[英]Python modules not found in virtualenv
我无法在虚拟环境中运行模块。 以熊猫为例:
打开虚拟环境后,我运行yolk -l
并返回(简化版本):
(basicpython)xxxx@LinuxBox:~/pythonprojects/basicpython$ yolk -l
Python - 2.7.3 - active development (/usr/lib/python2.7/lib-dynload)
numpy - 1.6.1 - active
pandas - 0.7.0 - active development (/usr/lib/pymodules/python2.7)
在那里。 但是,当我尝试激活模块时,出现错误:
(basicpython)xxxxx@LinuxBox:~/pythonprojects/basicpython$ python
Python 2.7.3 (default, Sep 26 2013, 20:08:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pandas
当我关闭虚拟环境并执行相同的操作时,它会起作用:
(basicpython)xxxxx@LinuxBox:~/pythonprojects/basicpython$ deactivate
xxxx@LinuxBox:~/pythonprojects/basicpython$ python
Python 2.7.3 (default, Sep 26 2013, 20:08:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
>>> pd
<module 'pandas' from '/usr/lib/pymodules/python2.7/pandas/__init__.pyc'>
知道为什么会发生这种情况(我错过了virtualenv的安装步骤吗?)
编辑:我在虚拟环境中安装了熊猫和其他库,这不是在环境中安装它们吗?
编辑2:我尝试在虚拟环境中重新安装软件包,并且系统说它们已经存在:
(basicpython)xxxx@LinuxBox:~/pythonprojects/basicpython$ sudo apt-get install
python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-nose is already the newest version.
python-numpy is already the newest version.
ipython is already the newest version.
ipython-notebook is already the newest version.
python-matplotlib is already the newest version.
python-pandas is already the newest version.
python-scipy is already the newest version.
python-sympy is already the newest version.
The following packages were automatically installed and are no longer required:
linux-headers-3.2.0-55-generic-pae gir1.2-ubuntuoneui-3.0 linux-headers-3.2.0-55 libubuntuoneui-3.0-1
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 6 not upgraded.
(basicpython)xxxxx@LinuxBox:~/pythonprojects/basicpython$
据我了解,这里有两个问题:
您的virtualenv中未安装Yolk。 由于它是从全局模块中提取蛋黄的,因此您将获得所有全局软件包的列表。 有关此问题的信息,请检查以下问题: virtualenv卵黄问题
Pandas模块似乎也未安装在您的virtualenv中(我猜您使用了默认的virtualenv创建,它不使用任何站点包)。 一种快速的检查方法是pip freeze
。 您应该继续在您的virtualenv中pip install pandas
( pip install pandas
),然后查看是否发生相同的行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.