5

In my /etc/profile, I set PYTHONPATH as something.

But when I source myvirtual-env

And then do this in python:

>>> import sys
>>> print sys.path

I don't see my paths anywhere.

2 Answers 2

5

That's the point of the virtualenv. It doesn't inherit from the rest of your setup. If you want a PYTHONPATH, you need to explicitly set one.

This djangousers post is probably helpful, you want to use virtualenvwrapper to solve this problem.

More info in this other SO post on a similar problem.

Sign up to request clarification or add additional context in comments.

2 Comments

How do I set PYTHONPATH in my virtual environment?
using virtualenvwrapper and the add2virtualenv command. doughellmann.com/docs/virtualenvwrapper/…
0

I don't observe the problem with Python 2.7, virtualenv 1.7.1.2 on Windows XP and I suspect Paul McMillan's answer is wrong.

# PYTHONPATH not set
# output from python -c "import sys; print sys.path" (edited for clarity)

'',
'C:\\Program Files\\python\\2.7\\lib\\site-packages\\pip-1.1-py2.7.egg',
'C:\\WINDOWS\\system32\\python27.zip',
'C:\\Program Files\\python\\2.7\\DLLs',
'C:\\Program Files\\python\\2.7\\lib',
'C:\\Program Files\\python\\2.7\\lib\\plat-win',
'C:\\Program Files\\python\\2.7\\lib\\lib-tk',
'C:\\Program Files\\python\\2.7',
'C:\\Program Files\\python\\2.7\\lib\\site-packages',
'C:\\Program Files\\python\\2.7\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg-info'

# PYTHONPATH not set, virtualenv activated
# output from python -c "import sys; print sys.path" (edited for clarity)

'',
'c:\\python\\virtualenv\\2.7\\lib\\site-packages\\distribute-0.6.24-py2.7.egg',
'c:\\python\\virtualenv\\2.7\\lib\\site-packages\\pip-1.1-py2.7.egg',
'C:\\WINDOWS\\system32\\python27.zip',
'c:\\python\\virtualenv\\2.7\\DLLs',
'c:\\python\\virtualenv\\2.7\\lib',
'c:\\python\\virtualenv\\2.7\\lib\\plat-win',
'c:\\python\\virtualenv\\2.7\\lib\\lib-tk',
'c:\\python\\virtualenv\\2.7\\Scripts',
'C:\\Program Files\\python\\2.7\\Lib',
'C:\\Program Files\\python\\2.7\\DLLs',
'C:\\Program Files\\python\\2.7\\Lib\\lib-tk',
'c:\\python\\virtualenv\\2.7',
'c:\\python\\virtualenv\\2.7\\lib\\site-packages'

# PYTHONPATH set to c:\pythonpath_sample_dir
# output from python -c "import sys; print sys.path" (edited for clarity)

''
'C:\\Program Files\\python\\2.7\\lib\\site-packages\\pip-1.1-py2.7.egg'
'c:\\pythonpath_sample_dir'   <--- value from PYTHONPATH
'C:\\WINDOWS\\system32\\python27.zip'
'C:\\Program Files\\python\\2.7\\DLLs'
'C:\\Program Files\\python\\2.7\\lib'
'C:\\Program Files\\python\\2.7\\lib\\plat-win'
'C:\\Program Files\\python\\2.7\\lib\\lib-tk'
'C:\\Program Files\\python\\2.7'
'C:\\Program Files\\python\\2.7\\lib\\site-packages'
'C:\\Program Files\\python\\2.7\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg-info'

# PYTHONPATH set to c:\pythonpath_sample_dir, virtualenv activated
# output from python -c "import sys; print sys.path" (edited for clarity)

''
'c:\\python\\virtualenv\\2.7\\lib\\site-packages\\distribute-0.6.24-py2.7.egg'
'c:\\python\\virtualenv\\2.7\\lib\\site-packages\\pip-1.1-py2.7.egg'
'c:\\pythonpath_sample_dir'   <--- value from PYTHONPATH
'C:\\WINDOWS\\system32\\python27.zip'
'c:\\python\\virtualenv\\2.7\\DLLs'
'c:\\python\\virtualenv\\2.7\\lib'
'c:\\python\\virtualenv\\2.7\\lib\\plat-win'
'c:\\python\\virtualenv\\2.7\\lib\\lib-tk'
'c:\\python\\virtualenv\\2.7\\Scripts'
'C:\\Program Files\\python\\2.7\\Lib'
'C:\\Program Files\\python\\2.7\\DLLs'
'C:\\Program Files\\python\\2.7\\Lib\\lib-tk'
'c:\\python\\virtualenv\\2.7'
'c:\\python\\virtualenv\\2.7\\lib\\site-packages'

Also python virtualenv: why can I still import old modules in clean/new virtualenv seems to confirm PYTHONPATH is being used to construct sys.path also when virtual environment is activated.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.