nutship
nutship

Reputation: 4924

Can't import packages in virtualenv

I've seen a bunch of similar questions but somehow can't get over it.

I am on Ubuntu. It uses python2.7 by default but I needed python3. I figured out the way best was to use virtualenv. So I did. I created a virtualenv using python 3 and installed some packages.

When I run (with env turned on):

import sys
print(sys.executable)

I get:

/usr/bin/python3

which does not seem correct. This is not the virtualenv python path. As a result I can't import any packages that I had installed inside of the virtualenv. Ideas?

Upvotes: 1

Views: 1221

Answers (1)

crs
crs

Reputation: 501

You might want to use a virtualenv version especially for python3: On Ubuntu 14.04 for example use pyvenv-3.4.

You code example runs fine with pyvenv-3.4:

(python-venv) user:~/tmp/test/python-venv$ python test.py 
/home/user/tmp/test/python-venv/bin/python

additionally, python --version and which python both return the expected results:

(python-venv) user:~/tmp/test/python-venv$ which python
/home/user/tmp/test/python-venv/bin/python
(python-venv) user:~/tmp/test/python-venv$ python --version
Python 3.4.0

Upvotes: 1

Related Questions