If you’ve worked with python but never used virtualenv, then you will probably have encountered this problem. You are working on 2 projects. One requires version X of a library; the other requires version Y of the same library.
So you use virtualenv to create isolated python environments so you don’t have messy and conflicting dev environments in your system.
But here’s another tool that’s a bit easier to use. It’s a wrapper for virtualenv called virtualenvwrapper.
Here’s the basics.
pip install virtualenvwrapper
Now add these 2 lines to your ~/.bash_profile (if you’re on OSX)
export WORKON_HOME=~/virtualenvs source /usr/local/bin/virtualenvwrapper.sh
(Note, the 2nd line may be different depending on where virtualenvwrapper was installed)
Create a virtual env
Exit from the virtual env
Next time you want to work on that project again
If you forgot what virtual envs you have created, you can list them
Bonus Material: Attaching PyCharm to your VirtualEnv
If you use PyCharm as your python IDE, then you should know that you can attach your project to these virtualenv.
Open Preferences then search for “interpreter” or look under Project > Project Interpreter.
Then click on the gear icon in the top right and select “Add…”
Then select “Existing environment” and click “…” to find the virtualenv’s python executable you created using virtualenvwrapper above.
If you set your WORKON_HOME to ~/virtualenvs as instructed above, then you’ll find your virtualenv under ~/virtualenvs.
And if your virtual env is called env1, then you’ll select ~/virtualenvs/env1/bin/python (or ~/virtualenvs/env1/bin/python3 if you want to use python3)