virtualenv
is a command-line utiltity that will allow you to encapsulate a python environment. Ubuntu calls the package that installs this utility "python-virtualenv". You can install it with $ sudo apt-get install python-virtualenv
.
In this sequence, I'm going to assume that python 3.5 is the installed verison.
$ cd ~
$ mkdir venv
$ cd venv
$ virtualenv -p $(which python3) 3.5 --system-site-packages
$ cd ~
You'll need to 'activate' the virtualenv in order to make use of it. It will re-write your prompt to put the name of the virtualenv at the beginning.
$ source ~/venv/3.5/bin/activate
(3.5)$
I recommend that you update pip immediately because there are sometimes some issues in old versions of pip that get in our way:
(3.5)$ pip install pip --upgrade
Collecting pip
.........
Successfully installed pip-19.3.1
(3.5)$ python --version
Python 3.5.3
(3.5)$ pip --version
pip 19.3.1 from /home/halfak/env/3.5/lib/python3.5/site-packages (python 3.5)
When you want to go back to the default python state, you'll need to deactivate the environment.
(3.5)$ deactivate
$ python --version
Python 2.7.6
$ pip --version
pip 1.5.4 from /usr/lib/python2.7/dist-packages (python 2.7)
Any time you want to use the virtual environment again, just run that "source activate" command from above:
$ source ~/venv/3.5/bin/activate
(3.5)$