PyTorch via pip

Back to Index


Even though we will install PyTorch with GPU via pip, it can be done in a virtual environment like Miniconda (miniconda installation here).

As always, pay attention to the versions you need to install, specially if you will test someone else's code. If you will create a neural network from scratch, get the latest stable version.

First, create and activate your conda environment:

  • conda create -n PyTorchEnv python=3.7
  • conda activate PyTorchEnv 

Then, install CUDA via conda. Change the version to the one you need:

  • conda install -c anaconda cudatoolkit==11.0.221
Finally, install PyTorch GPU (as described here):
  • python -m pip install torch==1.11.0 torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113
Note: The "python -m" command means that the python installed for the active conda environment will execute the pip command. Without it, the Python of WSL (or of the operational system) will be used, and the package will be available for all conda environments, and you won't be able to install different versions of PyTorch .

Even following these steps, when executing the network, some libraries may be missing. This will lead to PyTorch  to find the GPU and print its name, but fail to link correctly. In my case, the missing libraries were cuDNN and cusolver, and they were installed with:
  • conda install -c anaconda cudnn==8.2.1
  • conda install -c nvidia libcusolver
Note: If you need a previous version of cusolver, then the only way is to install it on the system through:
  • sudo apt-get install libcusolver10 


No comments:

Post a Comment

Global Game Jam 2024

Wow, what a weekend. The Global Game Jam is intense. But I and 3 other members manage to build a game for the theme "Make me laugh&quo...