我创建了一个virtualenv并在其中安装了SQLAlchemy

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

import在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

但它不适用于:
>>> import sqlalchemy
Traceback (most recent call last):
  File "<input>", line 1, in <module>
ImportError: No module named sqlalchemy

为什么bpython找不到安装在virtualenv中的包,即使它是在调用source alchemy/bin/activate之后执行的?

最佳答案

bpython必须安装在virtualenv中,否则将调用外部的、系统范围的bpython:

$ source alchemy/bin/activate
(alchemy)[ 10:34PM ]  [ adamatan@rubidium:/tmp ]
$ pip install bpython
...
$ alchemy/bin/bpython
--------------
>>> import sqlalchemy
>>> print sqlalchemy.__version__
0.9.7

关于python - 在virtualenv中运行bpython,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25434576/

10-12 16:32
查看更多