How do I uninstall all my python packages? - python

I have previously had a good working version of Python 3.6.0 on my macOS Sierra, that included modules like matplotlib.
However, I had the need of learning an image processing program, thus I wanted to learn openCV. I tried following this link to download and install openCV.
In the process I have downloaded the following programs:
Xcode
Homebrew
Python 2.7.10
Python 3.6.1
I found that I could import the cv2 module in my IDLE, however I could no longer import matplotlib in IDLE. Things are very messy with the 3 versions on Python on my macOS Sierra, and I would like to remove everything related to Python, so that I can start afresh, installing Python again, and hopefully install openCV on the same version of Python that has all the other modules that I was previously using.

If you are using the Homebrew versions of Python, you can just uninstall them and reinstall.
## Uninstall python & python3 packages. We use ignore-dependencies
## so the uninstaller will allow this; it's okay, we're going to reinstall
## right away anyway.
brew uninstall --ignore-dependencies python3
brew uninstall --ignore-dependencies python
## This will remove all of your locally installed Python packages.
rm -rf /usr/local/lib/python?.?
## And now reinstall the main Python packages.
brew install python python3

I recommend using conda (https://conda.io/miniconda.html) to manage your python environments and installed packages. It made my life soooo much better.
e.g.
$ conda create -n project_1_env python=3.5
$ source activate project_1_env
# project 1 uses python 3.5, and I install packages using `conda install <package>
$ conda create -n project_2_env python=2
$ source activate project_2_env
# project 2 uses python 2.X, and when I activate this environment
# the python 3.6 project-1 doesn't impact me at all
As well as python versions, conda lets you install specific version of packages for different virtual conda environments.

Related

How to use egg to install scikit-image?

I am stuck on this installation of scikit-image (aka skimage). I tried multiple ways:
Installation from a git hub folder (using the requirements.txt)
Installation from a whl file
Installation with pip install scikit-image
All three trials failed during the import: import skimage
ImportError: cannot import name 'geometry'
It seems that scikit-image has not been built correctly.
Your install of scikit-image appears to be broken.
Try re-installing the package following the instructions at:
https://scikit-image.org/docs/stable/install.html
I went through internet but did not find solutions besides the ones above.
Does anyone went through that before?
One possibility seems to be to pip install with -egg, but I found that for Mac rather than Windows.
EDIT:
Hi everyone, so I found a solution but this is kind of very hard and I still don't understand why it did not work before.
I just:
uninstall anaconda
uninstall python
install python (3.8)
install Anaconda (I have trouble with Spyder now^^)
If you want to code for computer vision/Image processing/machine learning tasks, then it can be done in pycharm with conda environment very easily. There is no need to install python separately to run Anaconda.
First, download and install pycharm. Next, If you use windows then download Anaconda 64 bit python 3.7 version from here,
https://www.anaconda.com/distribution/#windows
You can find some details about managing environment and helpful links here,
How to create some environments for tensorflow in anaconda?
https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html
Create a conda environment first using Anaconda Prompt command line,
conda create -n cvenv python=3.7
Now activate that environment using. By default base is activated.
conda activate cvenv
Next, install the packages you want,
conda install -c conda-forge scikit-learn
conda install -c conda-forge scikit-image
conda install -c conda-forge pillow
conda install -c conda-forge opencv
I use conda-forge packages as they are more recent. Finally, open pycharm and create a new project by selecting existing python interpreter in conda environment. If none exists then select,
Browse > Add Python Interpreter > Conda Environment > Interpreter > Browse > Anaconda3 installation folder > envs folder > cvenv folder > Python.exe
You can test by creating a python file and writing import skimage.

How to install OpenCV+Python on Mac?

I am trying to install OpenCV+Python on Mac. I am trying to do this in six steps by running commands at terminal (after step2):
Step1: Install Xcode
Step2: Install Homebrew
Step3: Install Python2 and Python3
1) brew install python python3
2) brew linkapps python
brew linkapps python3
4) which python
which python3
Step4: Install Python libraries by installing a virtual environment
Step5: Install OpenCV
Step6: Symlink OpenCV+Python to virtual environment
The problem is that which python must give output /usr/local/bin/python and not /usr/bin/python as it gives by default so that the virtual environment can be installed to install then the Python libraries.
I removed the link by running unlink /usr/bin/python and I created a symlink by running ln -s /usr/local/Cellar/python /usr/bin/python (python and python3 are installed by default at /usr/local/Cellar/).
However now which python gives me no output even though I have created the symlink. Why is this?
How can I change the output of which command to install finally OpenCV+Python on Mac?
Any better idea to install OpenCV+Python on Mac with most of the useful libraries or virtual environments etc? (Obviously I know how to do the installation without all these)
P.S. I followed this link: https://www.learnopencv.com/install-opencv3-on-macos/
The officially recommended python packaging tool is pipenv. One example of a workflow you could use to make a virtual environment with the exact libraries your project needs as well as ensuring security is this:
$ brew install pipenv
$ cd /path/to/project
$ pipenv --three
$ pipenv install opencv-python
And after you write your code in, say, project.py
$ pipenv run python3 project.py
More info on the pipenv site.
Finally, I did not solve the problem with which output even though I discuss it with really experienced people.
Finally, I downloaded PyCharm and I did the following:
1) Installed pip (Python package manager) by opening a project at PyCharm and going to PyCharm Community Edition (top bar) -> Preferences -> Project -> Project interpreter -> Press '+' -> Search and find pip (with the search bar) -> Press 'Install Package'
2) Type and enter pip install opencv-python (https://pypi.python.org/pypi/opencv-python) at the terminal
3) Follow the process at (1) to install/import opencv-python in PyCharm
4) Write import cv2 at the top of your source code
By not implementing the more extensive installation process described by the links that I posted above, I did not install the virtual environment which is highly recommended in order to avoid conflicts between various projects. But I think that I can make it without it for the moment!
Install OpenCV 'You must have Python3 installed'
pip3 install opencv-python

How to setup pip for coexisting Python 2.7/3.4?

I am using Anaconda Python 3.4 on a Windows 7 PC now. Recently I am trying to follow the instruction of the book High Performance Python to learn some profiling skills. To this end I need to use pip install to install several tools. Unfortunately, not all of them support Python 3, and I have to install Python 2.7 now.
Before installing Python 2.7, I would like to know how I should handle with such 2.7/3.4 coexisting system? How do I setup pip so that I could use pip install to install packages for different Python versions separately?
You can create a conda environment via:
conda create --name py27 python=2.7
and use this environment for your work with Python 2.7. Activate it with the command activate py27, going back to your root environment is just activate.
In the py27 environment you can install pip and all other packages you need.
pip is generally located at the Python27\Scripts and/or Python34\Scripts folder. If you wish to invoke pip directly in the command line, these folders should be in your PATH environment variable.
Now I would just rename pip.exe in Python34\Scripts into any other name, for example pip_for_3.exe. That way, when I install packages for Python27, I would just use:
pip install <package name>
and packages for Python34:
pip_for_3 install <package name>
Coexisting Python installations are not a problem, you just have to know which version is invoked every time. See this answer for the same idea.

How to fix broken python 2.7.11 after OSx updates? An in-depth look into Homebrew and beyond

What happened:
After an OSx update and installing a new version of python 2.7 my virtualevn environment completely broke and I struggled in fixing it. I wasn't sure what caused it and went through a whole set of things that I did and read initially that didn't work are listed below. What solved my problem is provided in the answer section.
What didn't work to fix virtualenv command not found:
Installed python through homebrew and then used pip to install virtualenv
Installed python through https://www.python.org and then used pip to install virtualenv
Related questions that helped me but did not provide the solution to my problem:
virtualenv-command-not-found
virtualenv-workon-command-not-found
Complete manual recovery I went through (What not to do!):
This didn't completely solved my problem. It is just to give you an idea of what steps I went through before I found the correct way to fix my python dev environment on my OSx.
Removed python 2.7 by using the post in here
Removed the homebrew installed version
Installed python through the pkg file in Mac OS X 32-bit i386/PPC installer or Mac OS X 64-bit/32-bit installer
Manually installed virtualenv following the instructions from here:
curl -O https://pypi.python.org/packages/source/v/virtualenv/virtualenv-13.1.2.tar.gz
tar xvfz virtualenv-13.1.2.tar.gz
cd virtualenv-13.1.2
sudo python setup.py install
Manaully install pip through 7:
curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | sudo python2.7
PIP was still broken after all this:
After all this after creating a virtual environment my pip still installed the packages in the main python folder instead of installing them under the virtual environment and non of the threads here neither here helped. My solution to that was to run pip under my virtual env with the following options:
1- Activate the virtual environment so that $VIRTUAL_ENV is set:
source venv/bin/activate
2- Forces pip to install in the right destination:
pip install --target=$VIRTUAL_ENV/lib/python2.7/site-packages
Summary
Something was badly broken and best way I fix my dev environment is provided in the answer to this question.
The reason
In my case was an OSx upgrade that affected my homebrew and after upgrading to python 2.7.11 is didn't install it properly.
How I got it to work:
I found steps 3 and 4 in a thread here and many thanks to https://github.com/baronomasia.
1 - Removed python 2.7 by using the post in here
2 - Removed the homebrew python installed version
brew uninstall python
3- Reinstall your Xcode command tools:
sudo xcode-select --install
4- Upgrade homebrew and reinstall python through homebrew:
brew update && brew reinstall python
After doing brew upgrade python my system python was broken and was throwing fits about virtualenvwrapper.sh, as well as my pip command was just suddenly missing.
I went to python.org and downloaded the python 2.7.13 installer, ran it, I now have python 2.7.13, pip, and can run pip install virtualenvwrapper and things seem to work.

Python - No pip when creating a virtual environment

So I heard about the proper way to install packages into python by creating a new virtual environment for every project. Being on a mac (10.8) I have installed python3 using Homebrew, then I installed pip and virtualenv on this copy.
Now here comes the problem:
I create a new virtualenv, and activate it using:
virtualenv testing
source testing/bin/activate
When I type
which python
/Users/mik/Desktop/testing/bin/python
But typing
which pip
/usr/local/bin/pip
(learned of this when trying to install a package in the virtual environment, and it installed in the system wide installation in /usr/local/)
Inside the folder testing there is no file referring to pip
Extra Question: How does pip know which python to install the files to, for example pip list (which I believe refers to python 2.7) outputs the names of packages installed on python 3.3
I'll start with the last question as it explains what is happening.
The commands pip and easy_install are python scripts which are made executable on the filesystem. The python they use is the python that the first line tells to run the script. e.g. in /usr/bin/easy_install it is #!/usr/bin/python This will be Apple's python. So easy_install will install the 2.7 version of pip and virtualenv and will ignore your python3.3 setup.
The way to instal into python 3 is to install the 3.3 version of pip and virtualenv, the easiest way would be to install the Homebrew package for them. I think it is easier and less confusing to use just one package manager (Homebrew here) and not two (i.e. Homebrew and python).
You can also install easy_install directly. The way to do this is install the distribute package using python3.3 explicitly.
Python 3.4 will make this much easier as pip will always be available

Categories

Resources