ubuntu18.04 builds a deep learning environment from scratch


A lot of people just started to learn the depth responded with great enthusiasm, but often spend a lot of time on the built environment and their own computer installed a lot of versions of the package, do not know the final use of the environment which run through Now, it has to be rebuilt for a new project.
In order to recover quickly after their own people and just start ubuntu18.04 after reinstall the system, you can look at the following lessons learned (I have two years of experience to ensure stable):

1. Install ubuntu18.04

Needless to say, just pay attention to:

  • You can enter the BIOS at the step of installing the system to disable Secure Boot Disabled
  • Verify that the system installation is normal: when ubuntu18.04 is installed and prompts you to restart, no abnormal information pops up on the screen at this time

2. Change the source of the system

The advantage of this is that you will feel that updating some packages will be very fast

Find Software & Updates, and update the source to the source of Alibaba Cloud, as shown
Replace Software source
in the figure below: Check Canonical Partners in Other Software, as shown in the figure below:
Check Canonical Partners
Then don’t forget to update:

sudo apt update
sudo apt upgrade

3. Install NVIDIA graphics driver

This step is a necessary item (although you will be prompted whether to Install NVIDIA Accelerated Graphics Driver when installing cuda
, but it is usually installed like this), it is also a stage where many people are easy to crash. The following is a tried and tested method in my collection:
Ubuntu 18.04 Install NVIDIA driver

  • It is recommended to ubuntu-drivers devicesselect the recommended driver version in the next step
  • Then this tutorial just needs nvidia-smito output something similar to the following after seeing it:

nvidia-smi output interface

4. Install cuda and cudnn

This article is my favorite high-quality blog about installing cuda and cudnn: Ubuntu18.04 installs CUDA10, CUDNN , and there are a few more points to note:

  • Try to install cuda10.0, some of the higher versions of the 9 series of deep learning frameworks do not support
  • In STEP3, only export in the terminal is valid for the current session and can gedit ~/.bashrcbe modified, don’t forgetsource ~/.bashrc
  • It is recommended to install locally, so that you do not need to be online and consume data to download in the future (the patch .run file is downloaded and installed in the same way)
  • I personally use more cuda10.0+cudnn7.4.2, you can use it nvcc -Vto check the cuda version
  • In fact, you can install cuda10.1+cudnn7.6.5 now. After all, for cuda10.0, pytorch supports up to 1.4. That is to say, if you want to use a higher version, it is best to install cuda10.1 (there will be (Some differences from cuda10.0)

5. Install Anaconda3

Needless to say, Anaconda3 can easily create a virtual environment and isolate the operating environment required by different projects.

It is usually .shinstalled by downloading files. The following blog of the collection explains: The correspondence between anaconda python version and the download address of anaconda . To summarize:

  • At present, most of them are in python3.6 or 3.7 environment (python3.8 environment is not recommended), so just download Anaconda3-5.2.0-Linux-x86_64.shand separately Anaconda3-5.3.0-Linux-x86_64.sh, see the table for more versions
  • Then bash ./Anaconda××××××××××××××××××.shit's ok
  • During the installation process, you will be prompted whether you want to write Anaconda into the environment variable. If you write it in the terminal, you will enter the python environment of Anaconda. If you don’t write, you will enter the python environment of the system when you enter python3 in the terminal.
  • Personally, I don’t like to write environment variables, I will run the following command: Then enter conda activatethe base virtual environment
gedit ~/.bashrc
. /home/lz/anaconda3/etc/profile.d/conda.sh
source ~/.bashrc
  • Although many people would suggest to change the source of conda, I found that the conda package management will make it possible to upgrade the python version during use, so I have been using pip to install the package (if you want to change or change back to the original source, here is one A high-quality blog: anaconda 1, add Tsinghua mirror 2, change back to the original source )

6, pip change source

The speed after changing the source is simply different:
create a .pip folder in the home directory, and then create a pip.conf file in this directory:

mkdir ~/.pip
gedit ~/.pip/pip.conf

Write the following content in the pip.conf file (replaced with the mirror source of Tsinghua University):

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple 

Save and exit will take effect.

7. Install PyTorch gpu version

No one installs the CPU version
here , right -_- Here I don't recommend installing according to one sentence in the official website, such as:

conda install pytorch torchvision cudatoolkit=10.0 -c pytorch

Or if you remove the latter and -c pytorchswitch to Tsinghua's conda source, the speed may be faster, which is not my favorite method.
My method is to install via pip:
Insert picture description here
For cuda10.0, you can go: https://download.pytorch.org/whl/cu100/torch_stable.html
More other versions of the match can be seen here: https://download.pytorch. org/whl/torch_stable.html
download the corresponding versions of torch.whl and torchvision.whl (see the figure below for version matching): It is now recommended to use the version of torch 1.3+. For
Insert picture description here
example , the version you torch-1.3.0%2Bcu100-cp36-cp36m-linux_x86_64.whldownloaded is (represents version 1.3.0, python3.6) Environment, linux 64-bit system) and torchvision-0.4.1%2Bcu100-cp36-cp36m-linux_x86_64.whl, then as long as it is used in an environment activated by conda:

pip install torch-1.3.0%2Bcu100-cp36-cp36m-linux_x86_64.whl
pip install torchvision-0.4.1%2Bcu100-cp36-cp36m-linux_x86_64.whl

You can quickly install the PyTorch gpu version (the whl file can be stored on the mobile hard disk, and you don’t need to download it for the next installation)

8. Install pycharm

The best IDE for python is of course pycharm. The latest version also supports mouse-over to display documents, which is particularly convenient for viewing code:
recommend a favorite high-quality blog: Ubuntu 18.04 install PyCharm

Of course, for the activation step, I used student activation, so it is the genuine professional version (you can read jupyter notebook)

At this point, you can install the basic environment for deep learning~~~~Experience summary, it is worth collecting!

Guess you like

Origin blog.csdn.net/laizi_laizi/article/details/108251733