In order to set up your virtual environment, we highly recommend (and only formally support) the use of Anaconda to create and manage your Python environment.
Virtual environments are tools that to keep dependencies required by different projects separate by creating isolated python virtual environments for them. This may be especially relevant if different versions of packages are required for
- Download Anaconda, and install it on your computer. You can alternatively download Miniconda if space is a concern. After running, restart your terminal.
Note: If you have an existing Anaconda or Miniconda installation, then you don’t need to reinstall, and can just use that! To test if you have an existing conda installation, run
conda --version
in your terminal.
-
You can now set up your Conda environment in a few ways. A straight forward way is to run
conda create -n [your env name here]
(though Step 3 will have another installation method involving assistance in installing dependencies). After running this, you can runconda env list
to confirm your list of environments. To delete an environment, runconda env remove -n [your env name]
. From this point on, you can runconda activate [your env name]
to activate your environment. To deactivate it, runconda deactivate
. -
Install necessary dependencies (e.g. NumPy, PyTorch, etc.). Note that some niche packages may be in different channels, so if you cannot install them, you may need to add them. For any package that you need, run
conda install [package]
when in your environment. Some packages may have different syntaxes for installation (e.g. for PyTorch, you would runconda install pytorch torchvision -c pytorch
), so make sure to view documentation when necessary. View all your current packages withconda list
.
You can also directly create an environment with packages installed using yml
files. Create the environment instead with conda env create -n [name_of_env] -f [path_to_yaml]
. A yml
file has been provided for the following installation method.
Potential Issues: If a
SpecNotFound
is raised: cd to the path where .yml is located, set [path_to_yaml] as your yml file. If your conda version is conda 4.12.0 or lower, and meet error on create environment, try runningconda env create -n [name_of_env] --file=[path_to_yaml]
.
You've now set up your first virtual environment! If you are familiar with jupyter notebooks, you can move directly to the PyTorch guide. For a quick primer on notebooks, check out the the jupyter guide.
Having Trouble Opening the
.ipynb
File?: Try opening up the file in VSCode. If this doesn't work, you can alternatively open up the notebook via localhost. Ensure that jupyter-notebook is installed as a dependency,cd
into this directory, and typejupyter-notebook
into your terminal. This will open up a tab to access your jupyter files in your browser.