Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pip packages not found - Brewed Python

Running Python 2.7.3, installed with HomeBrew, on a mac.

Installed several packages using PIP, including virtualenv. (Using virtualenv as an example, but NONE of the packages work.)

When I try to run them in terminal, it fails as follows:

$ virtualenv venv --distribute
-bash: virtualenv: command not found

Alternatively:

$ python virtualenv.py venv
/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'virtualenv.py': [Errno 2] No such file or directory

A few other points that may help:

$ which python
/usr/local/bin/python
$ pip freeze
MySQL-python==1.2.4
...
virtualenv==1.8.4
$ echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
$ echo $PYTHONPATH
/usr/local/lib/python2.7/site-packages:

By default, the $PYTHONPATH was blank, I changed it in .bash_profile (didn't help). VirtualEnv does exist at that path. I also tried adding this path to the .profile $path, but that didn't help either, so I removed it.

On the HomeBrew Python page it seems to somewhat relate to this, but I am new to Python, and can't figure it out. Have spent some hours DuckDuckGo'ing with nothing gained.

Any help would be greatly appreciated.

EDIT: Updated to reflect actual usage.

like image 944
SamGoody Avatar asked Jan 31 '13 11:01

SamGoody


People also ask

How do I fix Python unable to locate a package?

Start by updating the package list using the following command: sudo apt update. Use the following command to install pip for Python 3: sudo apt install python3-pip. Once the installation is complete, verify the installation by checking the pip version: pip3 –version.

Why pip install module not found?

This is caused by the fact that the version of Python you're running your script with is not configured to search for modules where you've installed them. This happens when you use the wrong installation of pip to install packages.

How do I enable pip in Python?

Step 1: Download the get-pip.py (https://bootstrap.pypa.io/get-pip.py) file and store it in the same directory as python is installed. Step 2: Change the current path of the directory in the command line to the path of the directory where the above file exists. Step 4: Now wait through the installation process. Voila!


1 Answers

The problem was that I had not added Python to the system $PATH.

At the end of the brew install it says (viewable by typing brew info python):

Executable python scripts will be put in:  
   /usr/local/share/python
so you may want to put "/usr/local/share/python" in your PATH, too.

So, simply had to open .profile and paste it in, and all packages work.

Much thanks to MistyM on the Brew IRC channel for pointing that out!

like image 120
SamGoody Avatar answered Sep 19 '22 06:09

SamGoody