What file do I edit, and how? I created a virtual environment.
This question is related to
python
linux
unix
virtualenv
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
mkvirtualenv myenv
workon myenv
add2virtualenv . #for current directory
add2virtualenv ~/my/path
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 the {venv-root}/lib/{python-version}/site-packages
directory. E.g.:
cd $(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
echo /some/library/path > some-library.pth
The effect is the same as adding /some/library/path
to sys.path
, and remain local to the virtualenv
setup.
It's already answered here -> Is my virtual environment (python) causing my PYTHONPATH to break?
Add "export PYTHONPATH=/usr/local/lib/python2.0" this to ~/.bashrc file and source it by typing "source ~/.bashrc" OR ". ~/.bashrc".
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.
Alternatively, you can also do below your code:-
import sys
sys.path.append("/home/me/mypy")
cd venv
source bin/activate
export PYTHONPATH='/home/django/srmvenv/lib/python3.4'
python
\>\> import sys
\>\> sys.path
I modified my activate script to source the file .virtualenvrc
, if it exists in the current directory, and to save/restore PYTHONPATH
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
:
export PYTHONPATH="${PYTHONPATH:+$PYTHONPATH:}/some/library/path"
Source: Stackoverflow.com