Skip to content
Advertisement

Running bpython inside a virtualenv

I have created a virtualenv and installed SQLAlchemy in it:

$ virtualenv alchemy
$ source alchemy/bin/activate
$ pip install sqlalchemy

import works in python:

$ python
Python 2.7.5 (default, Mar  9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlalchemy
>>> print sqlalchemy.__version__
0.9.7

But it does not work in bpython:

>>> import sqlalchemy
Traceback (most recent call last):
  File "<input>", line 1, in <module>
ImportError: No module named sqlalchemy

Why can’t bpython find the package installed in the virtualenv, even though it is executed after source alchemy/bin/activate is called?

Advertisement

Answer

bpython must be installed in the virtualenv, otherwise the external, system-wide bpython is called:

$ source alchemy/bin/activate
(alchemy)[ 10:34PM ]  [ adamatan@rubidium:/tmp ]
$ pip install bpython
...
$ alchemy/bin/bpython
--------------
>>> import sqlalchemy
>>> print sqlalchemy.__version__
0.9.7
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement