Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a python virtual env error after installing Lion

I haven't touched python and virtualenv in a while, and I believe I setup my MBP with virtualenv and pip, but have totally forgotten how this stuff works.

After installing lion, I'm getting this error when I open up a new terminal window:

Traceback (most recent call last):   File "<string>", line 1, in <module> ImportError: No module named virtualenvwrapper.hook_loader virtualenvwrapper.sh: There was a problem running the initialization hooks. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is set properly. 

Any tips on how to fix this?

Trying:

easy_install eventlet

I got this:

Traceback (most recent call last):   File "/usr/local/bin/easy_install", line 5, in <module>     from pkg_resources import load_entry_point   File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 2607, in <module>     parse_requirements(__requires__), Environment()   File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 565, in resolve     raise DistributionNotFound(req)  # XXX put more info here pkg_resources.DistributionNotFound: setuptools==0.6c11 
like image 966
Blankman Avatar asked Aug 06 '11 18:08

Blankman


People also ask

How do I enable a virtual environment in Python?

To use the virtual environment you created to run Python scripts, simply invoke Python from the command line in the context where you activated it. For instance, to run a script, just run python myscript.py .

How do I run a Python 3.7 virtual environment?

Running virtualenv with interpreter C:\Python37\python.exe Using base prefix 'C:\Python37' New python executable in C:\Users\XXXX\Documents\GitHub\MyProject\venv\Scripts\python.exe Installing setuptools, pip, wheel... done.


1 Answers

I am a complete Python/Virtualenv novice. However, I had the exact same problem and found a solution that worked for me. I believe that this will vary greatly depending upon the way you originally setup Python & Virtualenv.

In my case, the Lion upgrade completely wiped out all contents of my /Library/Python/2.*/site-packages, but left the now broken executables (which link to the contents of this folder) in /usr/local/bin. I believe that this is the root cause of the cryptic "No module" import errors.

Reviewing my .bash_history, I had originally used easy_install to install pip, and then pip to install virtualenv and virtualenvwrapper. Once I repeated these steps, then I was able to re-enter my old virtual environments which still contained all the packages I had installed on 10.6. Note, however, that 10.6 shipped with Python 2.6 as default. If your packages require Python 2.6, you should change your default Python version to 2.6 first.

Step-by-step:

  1. I removed old Virtualenv configuration commands from my shell startup scripts (eg., .bash_profile). Start a new terminal session.
  2. (optional) Choose the version of Python you wish to use, eg.,
    defaults write com.apple.versioner.python Version 2.6
  3. sudo easy_install pip. It seems as though /Library/Python/2.*/site-packages now requires administrator privileges. I don't recall that being the case in 10.6 (or at least my bash history doesn't reflect that).
  4. sudo pip install virtualenv
  5. sudo pip install virtualenvwrapper
  6. Finally, I re-enabled those virtualenv configuration commands I disabled in step 1. A new terminal session had everything back the way it was (look at pip freeze -l to see local packages in this virtual environment). I think.
like image 125
mbauman Avatar answered Sep 24 '22 19:09

mbauman