anaconda+pytorch+opencv installation and environment configuration

1. Anaconda download and installation

Download address: Enter the anaconda official website, Anaconda | The World's Most Popular Data Science Platform

After the download is complete, click Install. The specific operations are as follows:

8c46b66b2aaf4bcd8f89cee444412817.png

12e0ab7281de482c96f31fdf522accd0.png

 9e27fb17c5f54ea2b1a56106153535bd.png

 watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM1MzU3Mjc0,size_16,color_FFFFFF,t_70#pic_center

 It is recommended to check the first option, which will automatically configure the anaconda environment in the system.

After the installation is complete, check whether the environment variables of your computer are configured successfully. Right-click this computer => Properties => Advanced System Settings => Path

 0e02286156204858aa3d68f12bb64340.png

 Because during the anaconda installation process, it is just user and not all users, so check whether the path under the user has these five environment variables.

D:\anaconda

D:\anaconda\Library\name-w64\bin

D:\anaconda\Library\usr\bin

D:\anaconda\Library\bin

D:\anaconda\Scripts

2. Install and configure the pytorch environment

1. Create a virtual environment

conda env list

4be6d325e2e942ba9a20c85f542dc18e.png

 Check out the several corresponding environments under conda. I already have two. One is the base environment that comes with it when installing anaconda, and the other is pytorch that I installed later.

conda create -n pytorch_gpu python=3.6

Create a new pytorch_gpu environment, in which the python version selected is version 3.6 (later it was found that version 3.6 did not correspond to the cuda version, so python3.7 version was installed instead).

09616a9e169742d49aa5a77fb6e80874.png

47b7b4a8087d4df0965a2f1bf12af70e.png

 Select Y to wait for the python environment to be installed automatically.

 After waiting for the installation to complete, enter in the console

conda activate pytorch_gpu

We can enter this environment and enter python in this environment. If the following picture appears:

c408efae8c3d4a96bdd3b38b9ac43781.png

 It means that our environment has been created successfully, and the next step is to install pytorch.

2.pytorch installation

Our installation method this time uses online installation. The installation URL is the pytorch official website.

PyTorch An open source machine learning framework that accelerates the path from research prototyping to production deployment. https://pytorch.org/ If the installation of some packages fails, you can also use offline installation. After downloading the installation package through the mirror, install it. For the specific process, please refer to this article https://blog.csdn.net/qq_32863549/article/details/107698516?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522167047570316782414986134%2522%252C %2522scm%2522%253A%252220140713.130102334 ..%2522%257D&request_id=167047570316782414986134&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_positive~default-1-107698516-null-null.142^v68^pc_rank_34_que ryrelevant25,201^v4^add_ask,213 ^v2^t3_control1&utm_term=pytorch%E5%AE%89%E8%A3%85&spm=1018.2226.3001.4187https://blog.csdn.net/qq_32863549/article/details/107698516?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522167047570316782414986134%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=167047570316782414986134&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_positive~default-1-107698516-null-null.142%5Ev68%5Epc_rank_34_queryrelevant25,201%5Ev4%5Eadd_ask,213%5Ev2%5Et3_control1&utm_term=pytorch%E5%AE%89%E8%A3%85&spm=1018.2226.3001.4187

Before installing pytorch, you should first check whether your computer supports CUDA. Generally speaking, any NVIDIA graphics card can be accelerated by GPU. can be entered in the console 

nvidia—smi

801cb303248844f0aad60604ff4fa1e0.png

 The version I support is before version 11.4, so choose the corresponding version

b438cfe1330a4304888c487fa5adfc1a.png

 d993e00b8e1a40328c689c1f1633f4f5.png

 I finally chose version 1.12 of pytorch and version 11.3 of cuda,

f281a16394c84a4d918542146ed25bf8.png

 If you install the instructions from the official website, the speed is very slow and takes a long time. At this time, you can use the mirror to download. Please refer to this article for details (you can also download it on the mirror website and then install it offline). The installation speed of Pytorch in Anaconda is too slow. Solution Method_Snail is Tingyu's Blog-CSDN Blog_anaconda pytorch installation is too slow 1. Problem After creating a new environment in Anaconda, I want to install Pytorch directly on the GUI, but the speed is extremely slow. 2. Solution 1. Click the arrow on the right side of the environment to open the terminal of the current environment. 2. Add mirror. Add the mirror URL in the pop-up terminal window. Enter the code as follows: conda config --add channels https://mirrors. tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/conda config --add channels https://mirrors.tuna.tsing https://blog.csdn.net/omg_orange/article/details/108652090?ops_request_misc=&request_id =&biz_id=102&utm_term=anaconda%E5%AE%89%E8%A3%85pytorch%E9%80%9F%E5%BA%A6%E6%85%A2&utm_medium=distribute.pc_search_result.none-task-blog-2~all ~sobaiduweb~default-0-108652090.nonecase&spm=1018.2226.3001.4187

Successful installation can verify torch

3798f901c8854dfca077fea6fb3b39cd.png

 3.Install cudnn

There are two ways to find the corresponding version of cudnn, the first is to find it on the official website of NVIDIA

cuDNN Archive | NVIDIA Developer Explore and download past releases from cuDNN GPU-accelerated primitive library for deep neural networks. https://developer.nvidia.com/rdp/cudnn-archive The second is to directly enter the search command in the console

conda search cudnn

conda search cudnn --info 
可以查看准确的版本及其下载源

Find your corresponding version

conda search cudnn=8.2.1 --info 可以查找8.2.1的对应下载源

conda install cudnn=8.2.1 -c +在查找中提供的下载地址

b7a93b5c2f0e437b838fdfb0f66031e1.png

 Downloading through the mirror is faster, verify it after the download is successful.

fa5ccc6623864cd3b99141ddaae611bd.png

 If this is the case after running, the configuration is successful.

4.opencv installation

The environment configuration of opencv this time adopts offline installation.

First, download the corresponding version of the whl file on the mirror website. The mirror website corresponds as follows:

https://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv (foreign mirror network)

https://pypi.tuna.tsinghua.edu.cn/simple/opencv-contrib-python/ (Tsinghua Mirror Network)

20201117143933125.png#pic_center

 cp37 means python3.7 version, then the first one is macos system, the second and third are linux systems, the fourth and fifth are win systems corresponding to 32-bit and 64-bit respectively. Mine is a 64-bit system. If I don’t know, right-click on My Computer and select Properties.

I installed python 3.7, and my computer is a 64-bit windows operating system. I choose the corresponding opencv version according to my needs.

Here's what I chose:

68ce48a5f4014c828f2cd6d0d38109dc.png

 Place the downloaded whl file in the site-packages folder under the Lib folder in the anaconda directory95e25383f9e341438592832732ebda45.png

 Then open the control window and cd to the site-packages folder in the pytorch_gpu environment.

(Note that if the cd command is run across disks, you need to add /d at the end)

8a95f119f9244132b0718c289cc51512.png

 After cd to site-packages, install opencv through pip install

pip install +whl文件名字

7ceb352cee6442eda979a6a373bd4104.png

 52a1cb110abb45969c45e5113fe1a7f1.png

 Verify opencv installation

da13e94479944db1a9d57b057d2121b3.png

The installation is successful.

3. Configure the pytorch environment in pychrm

Select the setting option under the file file

c98d5dbcf5bf4ae4b496fec29f16c1d4.png

 Select the python file in the corresponding environment.

4792dd44e1924c53beac1cd6df094000.png

 The environment is as shown in the figure, click ok, then the configuration is successful.

Verify as follows:

ca0a4cee6a634e1890d45fd197710db8.png

 Enter the following command in the python console in pycharm, and if it runs as shown in the figure, it means that the operation is successful.

Guess you like

Origin blog.csdn.net/qiaodahua/article/details/128480995
Recommended