Python Tools
Python
Homepage: https://www.python.org/
Python is usually automatically installed in Linux distributions.
To run Python, type python3. If you want to use python3 when you type python, just add alias python='python3' to your ~/.bash_aliases file.
NumPy
Homepage: https://numpy.org/
Requires Python and pip. If you don’t have pip, install using:
sudo apt install python3-pip
Note
If pip requires entering pip3 instead of pip, add alias pip='pip3' to your ~/.bash_aliases file.
Install NumPy with:
pip install numpy
If it tells you to add a directory to PATH, add it to path by adding to ~/.bashrc: PATH=$PATH:/usr/local/bin, replacing /usr/local/bin with the directory the terminal tells you to.
Tip
Alternatively, instead of opening bashrc, you can run echo "PATH=\$PATH:/usr/local/bin" >> ~/.bashrc after replacing /usr/local/bin.
PyTorch
Requirements:
NVIDIA CUDA 9.2 or above
NVIDIA cuDNN v7 or above (?)
It is recommended that you use Python 3.6, 3.7 or 3.8
The PyTorch website recommends installing PyTorch with Anaconda, but pip is good.
From https://pytorch.org/get-started/locally/, select Stable, Linux, Pip, Python, and CUDA 11.1 (or most recent). Run the command given.
If the given comand returns an error, try
pipinstead ofpip3.
Verify PyTorch installed correctly by running python in the terminal and entering:
import torch; x = torch.rand(5, 3); print(x)
The output should be similar to:
tensor([[0.3380, 0.3845, 0.3217],
[0.8337, 0.9050, 0.2650],
[0.2979, 0.7141, 0.9069],
[0.1449, 0.1132, 0.1375],
[0.4675, 0.3947, 0.1426]])
Check if your GPU driver and CUDA is enabled and accessible by PyTorch:
import torch; print(torch.cuda.is_available())
Should return
True
Tip
You can run this code in one line without starting python by running python -c "import torch; print(torch.cuda.is_available())"