Machine learning and deep learning tools Python, Pytorch, PyCharm, CUDA, Cudnn installation guide_Super comprehensive, simple, effective and fast, avoid pitfalls_Do not use Anaconda

      

         I recently restored the operating system and many of the installation programs were gone.
        Remembering that there are some problems when installing Pytorch, Cuda and Anaconda, I will share a simple, effective and fast method of installing the toolkit to avoid pitfalls.

         Because it is too long, it is divided into two articles.

         This article introduces the installation method without using Anaconda (after all, Anaconda takes up a lot of space and many people don't like it).

         The following describes the installation method using Anaconda.

Contents of this article

    1. Install Python

          1. Download address

          2. Version selection

          3. Download

          4. Installation (choose to automatically add Python environment variables)

          5. Configure environment variables

          6. Verify whether the installation is successful

   2. IDE (PyCharm or Visual Studio Code)

   3. Install CUDA

        1. Check the NVIDIA driver version

        2. CUDA download address

        3. Select CUDA version

        4. Install the CUDA package

        5. Configure CUDA environment variables

        6. Verify whether CUDA is installed successfully

  4. Install CuDNN

        1. Download

        2. Installation

        3. Configure environment variables

        4. Verify whether the installation is successful

   5. Install Pytorch (or TensorFlow)

         1. Download address

         2. Automatically download and install version selection and commands

         3. Manually download and install version selection

         4. Manual installation version

         5. Verify whether it can be used

         6. Installation location query

         7. Tensorflow download URL

        

  


 

Brief description:

      1. Python is a commonly used language for machine learning. The development environment IDE is generally PyCharm or VScode.

      2、PyTorch

        PyTorch is an open source Python machine learning library based on Torch for applications such as natural language processing.

In January 2017, PyTorch was launched based on Torch by Facebook Artificial Intelligence Research (FAIR). It is a Python-based sustainable computing package that provides two advanced features:

      Tensor computation with powerful GPU acceleration (like NumPy). Deep neural networks with automatic differentiation system.

        The predecessor of PyTorch is Torch. Its underlying layer is the same as the Torch framework, but a lot of content has been rewritten in Python. It is not only more flexible, supports dynamic graphics, but also provides a Python interface. Developed by the Torch7 team, it is a Python-first deep learning framework that not only enables powerful GPU acceleration, but also supports dynamic neural networks.

PyTorch can be regarded as numpy with GPU support, and it can also be regarded as a powerful deep neural network with automatic derivation function. In addition to Facebook, it has been adopted by institutions such as Twitter, CMU and Salesforce.


          3、CUDA

        CUDA is a parallel computing platform and programming model invented by NVIDIA. It greatly improves computing performance by leveraging the processing power of graphics processing units (GPUs).

        CUDA Toolkit (nvidia) is a CUDA tool installation package, including CUDA compiler (nvcc), IDE, debugger, etc., and CUDA library files.

         4 、CuDNN、

       Deep learning software library,

1. Download and install Python

1. Download address

The official website to download Python is: Python Source Releases | Python.org

After entering the official website, you can see the following figure:

2. Version selection

Select the "Looking for a specific release? (Are you selecting a specific version?)" column to download the desired Python version.

Select Python3.10.9 here and click the "Download" button.

After the page jumps, pull down. Keep finding the "Files" column.

3. Download

The version you need to download for Linux operating system:

Gzipped source tarball

The version you need to download for the CentOS operating system:

XZ compressed source tarball

hint:

In fact, Linux and CentOS come with python, so there is no need to download python.

Mac operating system needs to download the version:

macOS 64-bit universal2 installer

Windows operating system needs to download the version:

  

Windows embeddable package (32-bit)

Unzip the installation version of Windows 32-bit operating system. The download is a compressed file, and the installation is complete after decompression.

  

Windows embeddable package (64-bit)

Unzip the installation version of Windows 64-bit operating system. The download is a compressed file, and the installation is complete after decompression.

  

Windows installer (32-bit)

Windows 32-bit operating system direct installation version. The download is a direct installer.

  

Windows installer (64-bit)

Direct installation version of Windows 64-bit operating system. The download is a direct installer.

   

(recommended download)

At present, most computer operating systems Win7/Win10/Win11 are basically 64-bit.

  

Regarding version selection:

Place the mouse on the "This PC" (i.e. My Computer) location on the computer, right-click "Properties", and a pop-up interface will appear to view the operating system information. For example: "64-bit operating system, x64-based processor", then select " Windows installer (64-bit) " to download.

   

   

4. Installation:

(1) Double-click the downloaded python-3.10.9-amd64 installation program.

Instructions for amd64 in the version:

64-bit is divided into amd64 and em64t. 64-bit usually refers to AMD's 64-bit CPU. AMD64-bit CPU is 64-bit compatible with 32-bit operations, while INTEL's EM64T is 32-bit compatible with 64-bit operations.

Check for all users.

(2) Check to automatically add it to the environment variable, that is, check "Add Python 3.10 to PATH".

(3) Select "Install now" for default installation (usually installed on the C drive).

The installation process is relatively automated, just click next along the way.

(4) If you do not want to install on the C drive, you can choose "Customize installation" to customize the installation.

Select all Optional Features because they will be used later.

Advance Options中,

You have to choose these three items. It doesn’t matter whether you choose the others or not. It all depends on your personal preference.

Check "Add Python to environment variables" to automatically add it to the environment variables. You do not need to configure environment variables later.

Select the installation address in "Customize Location".

Click "next";

Click "install".

5. Configure environment variables

If you have checked to automatically add environment variables during installation, you do not need to configure environment variables.

If you forgot to check the automatic addition of environment variables during installation, you can also manually add environment variables.

Right-click "This PC (My Computer)" - select "Properties" - select "Advanced" - select "Environment Variables" - select "System Variables" (not user variables).

Find the path of the system variable (not the user variable) and click on the system variable (not the user variable) to edit the path.

The environment variables of some computers are not displayed in columns as shown in the picture above, but are displayed in a row. It's hard to see what environment variables are there.

How to modify it to display in list state?

Taking the 64-bit Win11 operating system as an example, just add a system variable at the beginning of the Path column of the system environment variable: C:\Windows\System64

After confirmation, click Edit Environment Variables again, and it will be displayed in a column:

Find the installation location of Python just now, for example, the installation location is D:\Program Files(x64)\Python.

Then click Path and click Edit.

Click New in the editing environment variable interface.

Then add the following two pieces of information to the Path of the system environment variable. Each variable is separated by a semicolon (;) in English format.

D:\Program Files(x64)\Python;

D:\Program Files(x64)\Python\Scripts;

Click OK.

Click Confirm again (remember to click Confirm again, otherwise the addition will not be successful).

Click OK.

6. Verify whether the installation is successful

Press and hold the Windows (Microsoft logo) button + R button on the keyboard and enter cmd in the run command interface to open the run window.

Enter "python" in the run window interface.

If the Python version number is displayed as 3.10.9, the installation is successful.

Or: Enter the installation address of python and find the exe file named "python".

Double-click and the following python version number information appears.

The installation is successful.

View the Python installation list:

Enter the command in the running command window: python -m site

Found a problem:

The base path of the user installation package and the site path of the user installation package for Python are displayed as not existing.

USER_BASE: 'D:\\Program Files\\Python' (doesn't exist)

USER_SITE:' D:\\Program Files\\Python\\Scripts\\Python310\\site-packages' (doesn't exist)

Enter in the run command window:

set PYTHONUSERBASE=D:\\Program Files\\Python

Can be solved.

Alternatively, open the location of the installed Python files:

D:\Program Files(x64)\Python\Lib

Find a file named not site.py and open it with IDE.

It can be seen that there is no path for the user installation package base path and the user installation package site path.

USER_SITE = None

USER_BASE = None

Modify it to:

USER_SITE = 'D:\Program Files(x64)\Python\Lib\site-packages'

USER_BASE = 'D:\Program Files(x64)\Python\Scripts'

Check the Python installation list again:

Enter the command in the running command window: python -m site

Display the base path of the Python user installation package and the site path of the user installation package, indicating that they already exist.

Two, IDE installation

1. Pycharm download address

PyCharm: JetBrains' Python IDE for Professional Developers

Pycharm installation is relatively automated, so I won't discuss it too much.

2. You can also download and install Visual Studio Code from Microsoft official website, which is relatively automated.

3. Install CUDA

1. Check the NVIDIA driver version

Enter "NVIDIA Control Panel" in the Start program, and then click "NVIDIA Control Panel".

Click "System Information".

Click on "Components".

Check supported CUDA versions. It is shown here as CUDA11.7.99, so it can be downloaded as long as it is equal to or lower than the CUDA11.7 version.

Check driver version:

Enter "NVIDIA Control Panel" in the Start program, and then click "NVIDIA Control Panel".

After clicking on the help interface, click "System Information"

Note: CUDA Samples installation files are no longer provided after CUDA11.6.

Official website description: https://docs.nvidia.com/cuda/cuda-samples/index.html

As of CUDA 11.6, all CUDA samples are now only available on the GitHub repository. They are no longer available via CUDA toolkit.

CUDA Samples download address on the GITHUB webpage:

GitHub - NVIDIA/cuda-samples: Samples for CUDA Developers which demonstrates features in CUDA Toolkit

2. CUDA download address.

CUDA official website download address: CUDA Toolkit Archive | NVIDIA Developer

Cuda version selection reference:

https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html

NVIDIA GPU computing power query:

Compare GeForce Gaming RTX 30 Series Laptops | NVIDIA

3. Select CUDA version

Select the CUDA11.6.0 version here (as long as it is the same as or lower than the version supported by the computer).

Select the Windows version;

Select x86_64 bit;

Select 11 (cuda version);

Select exe(local): download to local;

Because of network speed issues, try not to use exe (network) to install online.

After selecting, click Download.

4. Install the CUDA package

Double-click the downloaded CUDA and run it as administrator.

You can change the location where the temporary decompression installation tool package is stored.

Kind tips:

This is the location where the temporary decompression CUDA installation tool package is stored, not the actual program installation location.

Click "Continue"

Click Agree and continue.

Selecting "Custom" here has two benefits:

First, you can specify the installation location yourself.

The second is to choose the installation content yourself.

Only CUDA is checked here.

All CUDA installation components are optional.

Because other content is usually already built-in when the computer leaves the factory.

For example, let's open it and see:

GeForce Experience, PhysX, Display Driver, etc. can definitely be viewed in the installation program of the control panel, and they are the most matching ones, so there is no need to replace them.

Come on, this is the real CUDA program installation location.

Please note these installation locations because you will need to configure environment variables later.

The installation directory is by default. It is best not to modify it. Modification may cause errors in subsequent development.

One installation location is Program Files and the other is ProgramData (for samples).

Kind tips:

       Even if you want to change the installation location path, remember that it cannot be the same as the location where you just stored the temporary decompression CUDA installation tool package. Otherwise, after the installation is completed, the installation folder of the entire program will not be found. Because the temporary storage and decompression CUDA folder will be automatically deleted after installation;

The screen will refresh a few times during installation, it's okay.

Click Next.

After installation, if no errors are reported, it is generally installed.

    5. Configure CUDA environment variables

Generally, the environment variables of CUDA_PATH and CUDA_PATH_V11_6 will be automatically configured.

System variable name

variable

CUDA_PATH

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6

CUDA_PATH_V11_6

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6

as follows:

Add system variable operation:

Click the New button on the system variables interface and enter:

variable name

variable

CUDA_SDK_PATH

C:\ProgramData\NVIDIA Corporation\CUDA Samples\v11.6

CUDA_LIB_PATH

%CUDA_PATH%\lib\x64

CUDA_BIN_PATH

%CUDA_PATH%\bin

CUDA_SDK_BIN_PATH

%CUDA_SDK_PATH%\bin\win64

CUDA_SDK_LIB_PATH

%CUDA_SDK_PATH%\common\lib\x64

Note: When entering the variable value of the system variable CUDA_SDK_PATH variable name, enter the installation location of CUDA Samples when installing CUDA previously.

There is no need to look at the installation location for the next four system variables, just copy and paste them directly.

Now add the Path variable of the system environment.

Click on Path of the system variable and then click on Edit.

After opening, click New.

Add the following four PATH variables:

%CUDA_BIN_PATH%

%CUDA_LIB_PATH%

%CUDA_SDK_BIN_PATH%

%CUDA_SDK_LIB_PATH%

confirm.

Yes.

Then click Confirm and Confirm on the two interfaces in sequence.

6. Verify whether CUDA is installed successfully

Use Windows key + R key to open the run command interface, enter cmd to open the run window.

Enter nvcc --version or nvcc -V

It’s done.

4. Install CuDNN

1. Download

Official website download address: https://developer.nvidia.com/rdp/cudnn-download

Note: To download Cunn, you must first register an account. Click Register Free to register one.

Registering an account will be completed soon. After logging in with the registration number, find your corresponding CUDA version.

勾选I Agree To the Terms of the cuDNN Software License Agreement

Click to open: Archived cuDNN Releases

Jump to the following page:

cuDNN Archive | NVIDIA Developer

Because what you just downloaded is CUDA11.6, just choose one for CUDA11.X.

2. Installation

Rather than installing it, it is better to put the contents of the downloaded cudnn file into the CUDA development environment.

Open the folder.

There are three folders and a license (license file) inside.

Select and copy the three folders bin, include, and lib together, put them into a folder, and name the folder "Cudnn".

Then put the cudnn folder containing the bin, include, and lib folders into the CUDA installer folder: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6

It is the v11.6 folder where the CUDA development environment folder of Documentation and Development was just placed, not the 11.6 folder of CUDA Samples.

3. Configure environment variables

After clicking the Path of the system variable, click Edit.

After opening, click New to add two Path variables.

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\extras\CUPTI\lib64

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\cudnn\bin

4. Verify whether the installation is successful

One way is to use the installed CUDA folder bandwidthTest.exe and deviceQuery.exe files.

These two built-in files are in the CUDA development environment folder:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\extras\demo_suite

As usual, use Windows key + R key to open the run command interface, enter cmd to open the run window.

Then use the cd command to locate the target path, and then enter the following two commands under the target path.

.\bandwidthTest.exe

.\deviceQuery.exe

That is, enter the following command in the running command window:

cd C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\extras\demo_suite

.\bandwidthTest.exe

.\deviceQuery.exe

After opening the run command window, enter:

cd C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\extras\demo_suite

Then enter:

.\bandwidthTest.exe

Show Result = PASS

Then enter:

.\deviceQuery.exe

Show Result = PASS

It means the installation is successful.

5. Install Pytorch (or TensorFlow)

1. Download URL

Official website address: PyTorch

Installation package download address: https://download.pytorch.org/whl/torch_stable.html

2. Automatically download and install version selection and commands

(1) pip command

The latest ones shown are CUDA11.7 and CUDA11.8 versions.

If the computer does not have a GPU, install the CPU version.

If you need other earlier CUDA versions, please click on the red box below.

Choose CUDA11.6 version here

 The pip installation command is:

pip install torch==1.12.1+cu116 torchvision==0.13.1+cu116 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu116

3. Manually download and install version selection

(It is recommended to download it locally first and then install it to avoid repeated installation due to disconnection in the middle)

(1) Official website download address:

https://download.pytorch.org/whl/torch_stable.html

(2) Download address of domestic Tsinghua open source software mirror station:

Simple Index

  (3) Download version adaptation suggestions

https://github.com/pytorch/vision#installation

There are three files to download in total:

torch version number: 1.12.1

torchvision version number: 0.13.1

torchaudio version number: 0.12.1

Download the red box torch installation package (the following figure indicates the meaning of the file code name):

Download the red box torchvision installation package (the following figure indicates the meaning of the file code name):

Download the red box torchaudio installation package (the following figure indicates the meaning of the file code name):

  After downloading, place the downloaded installation file into the Scripts folder in the python installation program directory. ,

For example, if Python is installed in this directory: D:\Program Files(x64)\Python\Scripts

Then, go to the D:\Program Files(x64)\Python\Scripts folder, right-click "Open in Terminal" to open Powershell.

4. Installation

In the Powershell window enter:

pip3 install torch-1.12.1+cu116-cp310-cp310-win_amd64.whl

Successfully installed torch-1.12.1+cu116 will appear after a minute or two.

The installation is successful.

5. Check whether it can be used

Enter cmd in the running program, enter the running command window, enter: python

Then enter: import torch

Then enter: torch.cuda.is_available()

If the result is True, Pytorch is available.

The other two files, Torchvision and Torchaduio, are installed in the same way:

In the Powershell window enter:

pip3 install ttorchaudio-0.12.1+cu116-cp310-cp310-win_amd64.whl

pip3 install torchvision-0.13.1+cu116-cp310-cp310-win_amd64.whl

6. Installation location query

Generally, it is in a folder called site_packages in the Python installation folder. For example: D:\Program Files(x64)\Python\Lib\site-packages

7. Tensorflow download URL

Pytroch is similar to Tensorflow.

If you have already installed Pytorch, you do not need to install Tensorfow.

However, if there is someone who particularly prefers Tensorflow but doesn’t like Pytorch.

It can be downloaded from Tsinghua Free Software Mirror Station:

https://pypi.tuna.tsinghua.edu.cn/simple/tensorboard/

references:

Installing on Windows — Anaconda documentation

Installation — pytorch_geometric documentation

https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html

https://www.nvidia.com/en-us/geforce/laptops/compare/30-series

Guess you like

Origin blog.csdn.net/StringEast/article/details/129688827