This is a blog post that I continue to update that discusses how I setup a Python Anaconda environment. As these
processes change, and I discover new things, I will update this post. These are my notes for how I setup a new Python environment for myself. I also refer students fom my course here for more advanced Python setup.
Environments
List your environments:
1 | conda env list |
Select an environment (Linux, OS X):
1 | source activate tensorflow |
Select an environment (Windows):
1 | activate tensorflow |
Deactivate Environment (Linux, OS X)
1 | source deactivate |
Deactivate Environment (Windows, Linux, OS X)
1 | deactivate |
Create/Delete Environment
Create an environment:
1 | conda create --name tensorflow python=3.6 |
Delete an environment:
1 | conda remove --name tensorflow --all |
Allow Jupyter Notebook to see Environment
1 | activate tensorflow |
Update/install
Update app packages:
1 | conda update --all |
Update one package:
1 | pip install tensorflow --upgrade |
Update Python to latest point version:
1 | conda update python |
Update Python to later version:
1 | conda install python=3.6 |
Version of a package:
1 | (tensorflow)Jeffreys-MacBook-Pro:present jeff$ python |
You might want to add a new environment to Jupyter notebook. By default, Jupyter will use
what ever environment you have active when you launch Jupyter. However, if you would like
to allow your new environment to be used in Jupyter execute the following:
For Mac:
1 | source activate tensorflow |
For Windows:
1 | activate tensorflow |
Jupyter Notebooks
It can be really handy to use Jupyter notebook to manage your different Python environments. To do this you must install Jupyter in your root Python environment (and each additional environment):
1 | conda install jupyter |
You must also install nb_conda in your root:
1 | conda install nb_conda |
You can also add support for R in Jupyter:
1 | conda install -c r r-essentials |
If you want your Anaconda environment to show up in Jupyter, you will need to add it. To add an environment named TensorFlow, use the following command:
1 | source activate tensorflow |
You might need to remove a conda environment from Jupyter. To list all environments, use the following command:
1 | jupyter kernelspec list |
To actually uninstall one, use the following command.
1 | jupyter kernelspec uninstall tensorflow |
Import/Export Environments
Once you create an environment (as described above), it can be useful to import and export these environments. You can use this to backup an environment, or transfer it to another machine.
To save an environment (make sure you have the environment you want to save activated), use this:
1 | conda env export > environment.yml |
To restore it onto another machine run this command. The name of this environment is specified in the first part of the .yml file. If you already have an environment named this, you will get an error. You can always rename the environment
inside of the .yml file. Or rename it with the -n option.
1 | conda env create -f environment.yml -n tensorflow |