Connect to the Linux server through ssh under windows and install Anaconda, and remotely call the virtual environment under the server Anaconda through Pycharm

In the past, the environment of the laboratory server was installed directly through pip, and anaconda was not used.

When using the server in the laboratory these days, I found that the environment I built was modified by the same door. . .

My whole person was split. I learned from the pain and decided to secretly install an anaconda and create a virtual environment to avoid being modified by the same door again.

I won’t go into details about how to set up ssh. Just start installing anaconda. Refer to ssh to connect to the Linux server and install Anaconda.

Visit the official website of anaconda under windows

Right click 64-Bit (x86) Installer (529 MB) , click copy link address to get the download link

In the linux command line, download through wget

wget https://repo.anaconda.com/archive/Anaconda3-2020.11-Linux-x86_64.sh

If prompted that the permissions are not enough, add sudo

sudo wget https://repo.anaconda.com/archive/Anaconda3-2020.11-Linux-x86_64.sh

After the download is complete, you can find the installation package in the directory:

by

ll

print

With the Anaconda installation package, then install Anaconda

Since the uploaded file does not have executable permissions, you need to add executable permissions to the file first.

chmod u+x  Anaconda3-2020.11-Linux-x86_64.sh

If prompted that the permissions are not enough, also add sudo

sudo chmod u+x  Anaconda3-2020.11-Linux-x86_64.sh

With executable permissions, directly execute the "Anaconda3-2020.11-Linux-x86_64" file

./Anaconda3-2020.11-Linux-x86_64.sh

The following interface is displayed

Press Enter to continue

Read the software license,

Just press "q" directly,

Then enter "yes" to accept the license.

Specify the installation path of Anaconda.

Generally established under the user of home, mine is

/home/zhanglei/conda

Note that the implementation does not need to create the conda folder in advance and write the address. If you make a mistake, a strange symbol will appear when you press the backspace key. You need to hold down ctrl and then press backspace to delete

After typing the address, press enter to confirm

After installation

Select yes in whether to add Anaconda environment variables

 

Reconnect ssh and    input "conda -V" to successfully output the version of conda

 

After Anaconda is installed, create a virtual environment

by

conda create -n xxx python=3.6

Where xxx is your environment name

For example, mine is

conda create -n tensorflow-gpu python=3.6

If you need to delete the environment

use

conda remove -n tensorflow-gpu --all

tensorflow-gpu is my environment name

After setting up the environment, activate the environment

conda activate your_env_name(虚拟环境名称)
或者
source activate your_env_name(虚拟环境名称)

After activating the environment, we can install tensorflow-gpu

If you need to increase the domestic mirror source

Need to use

conda config --add channels

Instruction

Such as adding Tsinghua sources

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/

Similarly, you can increase the source of Jiaotong University

conda config --add channels  https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main/
conda config --add channels  https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/free/
conda config --add channels  https://mirrors.sjtug.sjtu.edu.cn/anaconda/cloud/conda-forge/

University of Science and Technology

conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/

Remember to add

conda config --set show_channel_urls yes

It means to display the url of the channel when installing the package from the channel, so that you can know the source of the package installation.

 

You can use Anaconda to install tensorflow-gpu directly under Anaconda without installing cuda cudnn separately

conda install tensorflow-gpu

If you need to limit the version of tensorflow (such as 1.15), you can change the code to

conda install tensorflow-gpu==1.15

Anaconda will automatically download cuda+cudnn

Start after typing y

This shows that the installation was successful

If there is no automatic installation, for example, I found that tensorflow-gpu 1.14 will not automatically install cuda and cudnn, so I need to install it manually.

You can first see which versions are in the mirror source

conda search cudnn
conda search cudatoolkit

Download according to the version number

conda install cudatoolkit=10.0.0
conda install cudnn=7.4

The version number needs to be selected according to the compatibility relationship

 

 

You can also pass

conda list

View installed libraries

You can see that tensorflow-gpu 1.15 and the supporting cuda10 have been installed

Let's check if it can be used normally

enter

python3
import tensorflow as tf
tf.test.is_gpu_available()

Can return true to indicate successful installation

 

If you need to exit your virtual environment, please enter

conda deactivate

If you need to view the specific location of the environment, please enter

conda env list

I have the basic base environment and the tensorflow-gpu environment just set

Pay attention to the address of this environment, you need to use pycharm to remotely call the virtual environment under the server Anaconda

 


 

Next, you can connect to the server with pycharm

Click on tools-->Deployment-->Configuration

Create a new SFTP connection

And set the mapping

Then enter File-->settings

In the python interpreter under project:xxx (your project name), click the gear, and then click show all

Click the plus sign

Select the set ssh configuration under ssh interpreter

Then choose Sync folders according to your preference, I usually save it under the mnt folder

Note that the Interpreter here should select python3 under the address displayed by the conda env list before

After selecting, click Finish

Then, we can try it in pycharm, can the remote call succeed

enter

import tensorflow as tf
print(tf.test.is_gpu_available())

We see the result

The graphics card is read and true is returned

Description can be successfully called

 


 

You will find that after installing anaconda, as long as you enter ssh, there will be (base) at the beginning of each line. . . This of course is not in line with my purpose of secretly pretending to be anaconda

You can hide (base) by setting the auto_activate_base parameter to false:

conda config --set auto_activate_base false

2. Pass if you want to enter

conda activate base

3. If you regret it or want to keep the base, then pass

conda config --set auto_activate_base true

To recover

Referring  After installing anaconda, the system displays the front of the system (base) word

 

Guess you like

Origin blog.csdn.net/weixin_39518984/article/details/111297923