Kit Sunde
Kit Sunde

Reputation: 37075

My new virtualenv gets ImportError: No module named bz2 but system python can import

My virtualenv doesn't have the bz2 lib for whatever reason. I know I have bz2 becuase the system python can import it, how come my newly created virtualenv doesn't get it?

$ mkvirtualenv sentry
$ python -c "import bz2"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named bz2
$ deactivate
$ python -c "import bz2"

I also tried to recompile python into the virtualenv directory, but it didn't seem to work.

Upvotes: 0

Views: 4181

Answers (2)

Kit Sunde
Kit Sunde

Reputation: 37075

So the reason why my compilation failed is either that I was missing bzip2-devel or that I gave the wrong path to ./configure when I did (not sure which of the two):

./configure --prefix=/home/deploy/.virtualenv/sentry

after which running

make
make install

worked fine

Upvotes: 1

Zach Kelling
Zach Kelling

Reputation: 53829

If you can actually import bz2 try to explicitly create a new virtualenv with that particular Python:

virtualenv foo -p /path/to/system/python

You might want to do which python to check which Python you are using.

Upvotes: 1

Related Questions