Question

I recently installed the Python 3.3 DMG from Python.org.

I have pip, virtualenv, and virtualenv-wrapper installed.

When I do:

$ mkvirtualenv -p /usr/local/bin/python3 someenv

The environment gets created as expected.

When I then do a pip install, like say:

(someenv) $ pip install beautifulsoup4

It installs correctly (no errors).

When I then fire up python:

(someenv) $ python
Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 01:25:11) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import bs4
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'bs4'

I've also tried a few other packages: pytz, pymemoize, mock, and all seem to suffer from the same "No module named ..." problem.

Looking in the virtual environment's site-packages directory, the packages are there, it's just that the interpreter cannot seem to find them. If I do a pip freeze all installed packages are listed.

Any suggestions?

If it helps, I'm using:

  • Python 3.3 (again, installed from the .dmg at Python.org)
  • pip v1.2.1
  • virtualenv-wrapper v1.8.2
  • distribute 0.6.28
  • OSX 10.7 (Lion)

Edit: as requested, the output of sys.path is:

['', '/Library/Frameworks/Python.framework/Versions/3.3/lib/python33.zip', 
'/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3', 
'/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/plat-darwin', 
'/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/lib-dynload', 
'/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages']

And as such what is missing is: `/Users/aparkin/.envs/someenv/lib/python3.3/site-packages' -- the virtual environment's site-packages directory.

Edit 2: as well, doing an ls -l on the site-packages directory gives:

$ ls -l .envs/someenv/lib/python3.3/site-packages/
total 168
drwxr-xr-x  7 aparkin  staff    238 18 Oct 11:49 PyMemoize-0.1.1-py3.3.egg-info
drwxr-xr-x  3 aparkin  staff    102 18 Oct 11:51 __pycache__
drwxr-xr-x  7 aparkin  staff    238 18 Oct 11:34 beautifulsoup4-4.1.3-py3.3.egg-info
drwxr-xr-x  9 aparkin  staff    306 18 Oct 11:32 bs4
drwxr-xr-x  8 aparkin  staff    272 18 Oct 11:31 distribute-0.6.28-py3.3.egg
-rw-r--r--  1 aparkin  staff    237 18 Oct 11:31 easy-install.pth
drwxr-xr-x  6 aparkin  staff    204 18 Oct 11:49 memoize
drwxr-xr-x  7 aparkin  staff    238 18 Oct 11:51 mock-1.0.0-py3.3.egg-info
-rw-r--r--  1 aparkin  staff  75204 18 Oct 11:51 mock.py
drwxr-xr-x  4 aparkin  staff    136 18 Oct 11:31 pip-1.2.1-py3.3.egg
drwxr-xr-x  9 aparkin  staff    306 18 Oct 11:44 pytz
drwxr-xr-x  8 aparkin  staff    272 18 Oct 11:44 pytz-2012f-py3.3.egg-info
-rw-r--r--  1 aparkin  staff     30 18 Oct 11:31 setuptools.pth
Was it helpful?

Solution

A new feature of Python 3.3 is a standard way to create and manage virtual environments, pyvenv. You should use it instead.

That said, you still should be able to make the old virtualenv work. One thing to check is the value of sys.path when using the virtualenv python that fails. You should see the virtualenv site-packages directory on it. If so and imports still don't work, check the virtualenv lib directories including site-packages for the correct file permissions.

Update: The contents of virtualenv site-packages looks reasonable at first glance. But the value of sys.path looks suspiciously like that of the standard python3.3, not one running from a virtualenv. So check to make sure you really are using that one. Try running the virtualenv python with an absolute path, like:

/path/to/someenv/bin/python3.3 -c 'import sys;print(sys.executable);print(sys.path)'

Also make sure you have no Python-related environment variables set, like PYTHONPATH or shell aliases or functions for python.

env | grep PYTHON
echo $PATH
which python
type python

OTHER TIPS

I think it is because you set an alias for python in your terminal.

If you use zsh, just use an editor (e.g vim) to open ~/.zshrc, and delete the alias for python, and then run source ~/.zshrc in your terminal or close the terminal windows and reopen it.

If you don't use zsh, the principle is the same, just delete the alias.

This will solve your problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top