I use Jedi for Python autocompletion in Emacs, but it's not a dependency of my code so I don't want to put it in my requirements.txt
. (Other developers may not use a Jedi editor plugin, and it's certainly not needed when I deploy to Heroku.)
But Jedi must be available from my virtualenv in order to function, i.e. if I can't
import jedi
it doesn't work.
Is there a good way to install Jedi user-globally such that it is available in all of my virtualenvs?
I think what I want is to
~/.local/lib/python2.7/site-packages/
with pip
's --user
flag, then to--system-site-packages
flag, but for user packages instead of system packages.My current workaround is to pip install jedi
in each of my virtualenvs. Then when I add new dependencies I pip install foo
, pip freeze > requirements.txt
, then manually remove jedi
and a few other things from the file before committing. Obviously, this is time-consuming and error-prone.
Does anybody have a better solution?
You don't specifically need to activate an environment; activation just prepends the virtual environment's binary directory to your path, so that “python” invokes the virtual environment's Python interpreter and you can run installed scripts without having to use their full path.
If you build with virtualenv --system-site-packages ENV , your virtual environment will inherit packages from /usr/lib/python2. 7/site-packages (or wherever your global site-packages directory is).
include-system-site-packages is a boolean indicating whether or not the packages installed outside of the virtual environment, at the system level, should be visible inside the virtual environment. And version is the Python version used to create the environment.
When virtuenv
activate
s, it changes several env variables, such as PATH
,
PYTHONHOME
, PS1
, and so on, to point desired python binary, library, etc. You can change the script to change PYTHONPATH
to use your user site-packages, namely ~/.local/lib/python2.7/site-packages
, and possibly your system site-packages. With this setting, pip will search for library in virtual env, and then failover to user/system site-packages. Note that normally activate script does not change PYTHONPATH
at all.
That is, add the following lines in your virtual_env/bin/activate
.
# in activate script
# in deactivate function
if [ -n "$_OLD_VIRTUAL_PYTHONPATH" ] ; then
PYTHONPATH="$_OLD_VIRTUAL_PYTHONPATH"
export PYTHONPATH
unset _OLD_VIRTUAL_PYTHONPATH
fi
# in activate section
if [ -n "$PYTHONPATH" ] ; then
_OLD_VIRTUAL_PYTHONPATH="$PYTHONPATH"
PYTHONPATH=$HOME/.local/lib/python2.7/site-packages:/usr/lib/python2.7/site-packages
fi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With