Install the Deep Learning Framework Pytorch with Conda

1. Preface

Pytorch is currently a hot framework for in-depth learning.The learning curve is smoother than TensorFlow, so you can train and use the network without writing a lot of template code.Java support has started in the latest version of Pytorch.But installing Pytorch is not easy.Today, let's talk about how to install Pytorch using Conda.

2. Conda

To briefly mention Conda here, Conda is an open source, cross-platform package management system and environment management system for installing multiple Python versions of packages and their dependencies, and for easy switching between them.You can think of Conda as a Maven in the Python realm, and of course some of the features may be more powerful than Maven.Usually I install anaconda to integrate Conda and Python environments, and anacoda has additional useful scientific computing packages such as numpy and pandas.MiniConda can also be used if you are hygienic, it only contains Conda and Python.If you don't know Conda yet, it's recommended that you take ten minutes to get started quickly.

3. Install Pytorch Online

For Mac example, Conda has the following commands to install the latest version of Pytorch:

conda install pytorch torchvision -c pytorch

It's easy to install Pytorch as prompted by this command.If the installation fails, it is likely that the network latency is too high and the time-out will occur.So we can speed up the installation by configuring anacoda's domestic mirror source.The command executes the following commands:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes

Then reinstall Pytorch.

https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/ by Pytorch And we'll use it in the next chapter.

4. Install Pytorch offline

Sometimes even using a mirror source fails, so we can solve this problem by installing it offline.When Pytorch installation fails, the command line terminal should be prompted as follows:


CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://conda.anaconda.org/pytorch/osx-64/pytorch-1.4.0-py3.7_0.tar.bz2>
Elapsed: -

An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.

CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://conda.anaconda.org/pytorch/osx-64/torchvision-0.5.0-py37_cpu.tar.bz2>
Elapsed: -

An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.

Typically, pytorch and torchvision packages fail to download, and we can choose to manually download them and install them offline.We extract the package download url link from the hint above to download. You can replace https://conda.anaconda.org/pytorch/in the download url link with https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/to increase download speed.

For example, with the version in the figure above, execute the following commands to install the pytorch and torchvision packages after successful download:

   #  env_name is the Conda environment name
   conda install --offline  env_name /path/to/pytorch-1.4.0-py3.7_0.tar.bz2
   conda install --offline  env_name /path/to/torchvision-0.5.0-py37_cpu.tar.bz2

This completes the installation of Pytorch and makes it possible to practice alchemy happily.The linux and windows platforms are similar.

5. Summary

Today, I introduced how to solve some of the problems that Pytorch installation fails when using Conda to install Pytorch.If you don't understand anything in the installation, you can trust me privately.

Focus on Public Number: Felordcn for more information

Personal blog: https://felord.cn

Keywords: Programming Anaconda Python network Maven

Added by abax on Wed, 12 Feb 2020 06:21:53 +0200