Why virtual environment is needed?
It is very common in deep learning that each project has different dependency requirements, which makes environment management important. Conda can help us set multiple virtual environments and keep them independent from each other. Thus, all of your ML projects can run smoothly.
Set up virtual environment for pytorch using conda
-
Install CUDA and cuDNN
This step is only necessary for those who has a GPU. Before downloading CUDA and cuDNN from NVIDIA, check the version requirements on PyTorch website.
-
Install Anaconda or Miniconda depends on your taste.
Go to anaconda or miniconda’s website and download the .exe installer for your system. Rember to check the set conda as enviroment viable box.
-
Install jupyter
conda install -y jupyter
-
Create the enviroment named torch
conda create --name torch python=3.8 # created a conda enviroment named 'torch' # If you use cpu only, you need to change it to python 3.7 conda create --name torch python=3.7
After finished, reopen the terminal
-
Activate enviroment
conda activate torch conda install nb_conda # Add conda env to jupyter notebook python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
-
Install Pytorch
You can go check Pytorch’s website to see all the installation options.
-
CPU and GPU:
conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch -c conda-forge
-
CPU only:
conda install pytorch torchvision torchaudio cpuonly -c pytorch
-
-
Install other libraries
conda install -c conda-forge opencv dependencies: - jupyter - scikit-learn - scipy - pandas - pandas-datareader - matplotlib - pillow - tqdm - requests - h5py - pyyaml - flask - boto3 - pip: - bayesian-optimization - gym - kaggle
Or, if there is any requirements.txt, just use
pip install -r requirements.txt
Reference: