What file do I edit, and how? I created a virtual environment.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
EDIT #2
The right answer is @arogachev's one.
If you want to change the
PYTHONPATH
used in a virtualenv, you can add the following line to your virtualenv'sbin/activate
file:This way, the new
PYTHONPATH
will be set each time you use this virtualenv.EDIT: (to answer @RamRachum's comment)
To have it restored to its original value on
deactivate
, you could addbefore the previously mentioned line, and add the following line to your
bin/postdeactivate
script.It's already answered here -> Is my virtual environment (python) causing my PYTHONPATH to break?
UNIX/LINUX
Add "export PYTHONPATH=/usr/local/lib/python2.0" this to ~/.bashrc file and source it by typing "source ~/.bashrc" OR ". ~/.bashrc".
WINDOWS XP
1) Go to the Control panel 2) Double click System 3) Go to the Advanced tab 4) Click on Environment Variables
In the System Variables window, check if you have a variable named PYTHONPATH. If you have one already, check that it points to the right directories. If you don't have one already, click the New button and create it.
PYTHON CODE
Alternatively, you can also do below your code:-
The comment by @s29 should be an answer:
One way to add a directory to the virtual environment is to install virtualenvwrapper (which is useful for many things) and then do
If you want to remove these path edit the file
myenvhomedir/lib/python2.7/site-packages/_virtualenv_path_extensions.pth
Documentation on virtualenvwrapper can be found at http://virtualenvwrapper.readthedocs.org/en/latest/
Specific documentation on this feature can be found at http://virtualenvwrapper.readthedocs.org/en/latest/command_ref.html?highlight=add2virtualenv
You can create a
.pth
file that contains the directory to search for, and place it in thesite-packages
directory. E.g.:The effect is the same as adding
/some/library/path
tosys.path
, and remain local to thevirtualenv
setup.I modified my activate script to source the file
.virtualenvrc
, if it exists in the current directory, and to save/restorePYTHONPATH
on activate/deactivate.You can find the patched
activate
script here.. It's a drop-in replacement for the activate script created by virtualenv 1.11.6.Then I added something like this to my
.virtualenvrc
:After initializing your vertualenv(1. cd venv and 2. source bin/activate).
just set or change your python path by entering command following-
export PYTHONPATH='/home/django/srmvenv/lib/python3.4'
for checking python path enter 1)
Thanks you...