RedRaven
RedRaven

Reputation: 735

Python modules not found in virtualenv

I can't get modules to run in my virtual environment. Using pandas as an example:

With the virtual env on I run yolk -l and get back (shortened version):

(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)

So it is there. But when I try to activate the module I get an error:

(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

When I turn off the virtual environment and do the same thing it works:

(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'>

Any idea why this might be happening (did I miss an install step with virtualenv?)

EDIT: I installed pandas and other libraries while in the virtual environment, does this not install them in the environment?

EDIT 2: I tried reinstalling the packages while in the virtual environment and the system says they are already there:

(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$ 

Upvotes: 0

Views: 4920

Answers (1)

sanchitarora
sanchitarora

Reputation: 910

From what I understand, there are 2 issues here:

  1. Yolk is not installed in your virtualenv. Since it is picking up yolk from the global modules you are getting a list of all global packages. For information about this problem check this question: virtualenv yolk problem

  2. Pandas module also doesnt seem to be installed in your virtualenv (I am guessing you used the default virtualenv creation which does not use any site packages). A quick way to check this is pip freeze. You should go ahead and install pandas in your virtualenv (pip install pandas) and then see if the same behavior occurs.

Upvotes: 1

Related Questions