Use venv and never
pip install as root.
I often use Python wrappers around C++, for example for testing or visualisation. To handle versioning, it is essential to setup a virtual environment for modules. Historically there have been many different approaches to this, but now there is one good way. While python2 will no doubt remain installed on my systems indefinitely, I won’t be using it for new development, so the best way to separate my libraries from system libraries - and other development versions of my libraries - uses venv:
python3 -m venv ~/pythonenvironment
On Ubuntu, you’ll need to
apt-get install python3-venv first. venv is included by default on Redhat and most Windows distributions as far as I can tell.
- To enable a virtual environment:
- Which defines
- Modules installed now will go here. For example
pip install matplotlibon my system runs
~/pythonenvironment/bin/pipand installs to
- And finally, your own modules can be copied to the site-packages.