Strongly inspired by https://gist.github.com/heymonkeyriot/9a2f429caff5c091d5429666fa080403.
On Ubuntu :
sudo apt install python3 python3-pip
or on Fedora < 31 :
sudo dnf install python3 python3-pip
That'll install both Python and PIP.
(Side note that you should install multiple versions of Python via Pyenv rather than Brew/apt/dnf to avoid any bad Python conflicts)
Install all your python env into local.
pip3 install --user virtualenv virtualenvwrapper
You'll need to tell ZSH where virtualenvs scripts are located
In ~/.zshrc add the bin folder to the path before the plugins part :
# Add the bin folder to $PATH before the plugins load
PATH=$HOME/.local/bin:$PATH
Also, add the virtualenvwrapper
to the plugin array :
plugins=(
git
...
virtualenvwrapper
)
Then you can load your shell with this new config :
source .zshrc
You might get into errors :
-
Virtualenvwrapper plugin doesn't find the path of
virtualenvwrapper.sh
:[oh-my-zsh] virtualenvwrapper plugin: Cannot find virtualenvwrapper.sh. Please install with `pip install virtualenvwrapper`
To fix it, you can put the correct path in the virtualenvwrapper plugin. Note: I don't find these very elegant, you'v probably forgot to update your PATH before. For example, change all the lines of
~/.oh-my-zsh/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
from/usr/local/
to$HOME/.local
(if you've installed locally the modules).You can do it with one commande line with
sed -i "s/\/usr\/local/\$HOME\/.local/g" ~/.oh-my-zsh/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
-
The
virtualenvwrapper.sh
script throws an error like :virtualenvwrapper_run_hook:12: permission denied:- virtualenvwrapper.sh: There was a problem running the initialization hooks.
It's probably your system use
python3
command and notpython
. Addingalias python=python3
doesn't seem to work.You need to add in
.zshrc
, before the plugins line :export VIRTUALENVWRAPPER_PYTHON=$(which python3)
-
ERROR: Environment '/home/john_doe/.virtualenvs/test-env' does not contain an activate script.
on a Raspberry PiFirst check your version of virtualenvwrapper with
pip freeze | grep virtualenv
, it should be4.x.x
and not5.0.0
. If necessary downgrade your version withpip uninstall virtualenvwrapper
andpip install --user virtualenvwrapper=="4.8.4"
(check the last version at PyPi).Then you can have the same issue is the as above, so just add
export VIRTUALENVWRAPPER_PYTHON=$(which python3)
to your.zshrc
(or.bashrc
) before loading the plugin.
When the source
doesn't throw any errors, you can test if virtualenvwrapper works.
workon
mkvirtualenv test
Here you should see
New python executable in /home/john_doe/.virtualenvs/test/bin/python2.7
Also creating executable in /home/john_doe/.virtualenvs/test/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /home/john_doe/.virtualenvs/test/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/john_doe/.virtualenvs/test/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/john_doe/.virtualenvs/test/bin/preactivate
virtualenvwrapper.user_scripts creating /home/john_doe/.virtualenvs/test/bin/postactivate
virtualenvwrapper.user_scripts creating /home/john_doe/.virtualenvs/test/bin/get_env_details
You should see a (test)
somewhere in you shell, but it might depend of the theme. (By default the ZSH virtualenv plugin hides the virtualenv name with export VIRTUAL_ENV_DISABLE_PROMPT=1
. That's why I didn't add it to plugins, it doesn't seem very useful but migh be linked with the theme I use.)
If you obtain the error ERROR: virtualenvwrapper could not find virtualenv in your path
, check if you've add the bin
folder to $PATH (see above).
Do whatever you want in your venv. Then to quit and delete.
deactivate
rmvirtualenv test
If the zsh plugin works correctly, you can link a venv to a git folder (auto workon
and deactivate
when you navigate in and out the folder. First create the folder test
(usually a git clone
). Then mkvirtualenv test
. It should work, hopefully.
Thank you!