在virtualenv中找不到Python模块

时间:2013-12-01 16:59:32

标签: python python-2.7 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的安装步骤?)

编辑:我在虚拟环境中安装了pandas和其他库,这不是在环境中安装吗?

编辑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$ 

1 个答案:

答案 0 :(得分:1)

据我所知,这里有两个问题:

  1. 您的virtualenv中未安装Yolk。由于它从全局模块中获取蛋黄,因此您将获得所有全局包的列表。有关此问题的信息,请检查此问题: virtualenv yolk problem

  2. Pandas模块似乎也没有安装在你的virtualenv中(我猜你使用了默认的virtualenv创建,不使用任何网站包)。检查此问题的快捷方法是pip freeze。您应该继续在virtualenv(pip install pandas)中安装pandas,然后查看是否发生了相同的行为。