If you have many Python projects running on your computer and would like to install the latest Tensorflow 2 without affecting any existing package dependencies, you may want to create a virtual environment for your Tensorflow-related work.
Here is how to do that on Linux.
Note: This is only a trick that may be helpful to some people, and is not at all essential to the course. If this looks obscure to you, don't worry, you probably don't need it.
Initially, make sure the basic python3, jupyter-notebook, python3-virtualenv and python3-pip (or equivalent) packages are already installed in the usual way on your system (i.e. via apt on Debian/Ubuntu).
Create a new environment and activate it:
~$ virtualenv -p python3 ./tfenv # 'tfenv' is the (arbitrary) name of our new environment
~$ source ./tfenv/bin/activate
(tfenv) ~$ # '(tfenv)' indicates new environment is active
Install tensorflow and ipython (and optionally any other packages you require) in the following way:
(tfenv) ~$ pip install tensorflow ipython
If pip complains about low disk space (e.g. due to small /tmp partition), just create a local tmp/ dir and tell pip to use that for the installation:
(tfenv) ~$ cd tfenv/
(tfenv) ~/tfenv$ mkdir tmp/
(tfenv) ~/tfenv$ TMPDIR=tmp/ pip install --cache-dir=tmp/ --build tmp/ tensorflow ipython
To connect the new environment with Jupyter, run
(tfenv) ~$ pip install ipykernel
(tfenv) ~$ python3 -m ipykernel install --user --name=tfenv
Now, start a Jupyter server (or restart it, if it was already running). In the "New Notebook" dropdown menu, the `tfenv` should appear. It lets you create an interactive jupyter notebook within the newly created environment.
To leave the virtual environment, simply close the shell or run
Hope this helps someone!