linux install anaconda3 create virtual environment tensorflow install pycharm remote connection

Keywords: Python Linux Pycharm TensorFlow

1. anaconda3 package download

1.1 windows Download

First download through windows, and then transfer to linux server through winscp and other software

Official website address:

Tsinghua mirror address:

Anaconda corresponds to python version:

1.2 linux download


2. anaconda3 installation

Reference blog:

  1. Enter the following code in the directory where the file is located (if the version is different and the file name is different, you can replace it by yourself)

  2. After the following prompt appears, press ENTER to continue

    Please, press ENTER to continue
  3. Then ENTER the user agreement, press and hold ENTER until the following prompt appears, and ENTER yes

    Please answer 'yes' or 'no':'
  4. Then the following prompt appears. Enter the installation path to install automatically, for example: / opt/Anaconda3 (Anaconda3 folder cannot exist in / opt directory before installation)

    Anaconda3 will now be installed into this location:
      - Press ENTER to confirm the location
      - Press CTRL-C to abort the installation
      - Or specify a different location below

    Note: it is recommended to install in the home directory

  5. After the installation, the following prompt appears, asking whether to initialize Anaconda3 in the. bashrc file in the home directory (in order to use the conda command and directly enter the base environment), enter yes

    Do you wish the installer to initialize Anaconda3
    by running conda init? [yes|no]
    [no] >>> yes
  6. Re execute the newly modified initialization file. bashrc (in the home directory)

    source ~/.bashrc
  7. Enter conda and the following contents will be displayed, and the installation will be successful

    [test@localhost ~]$ conda
    usage: conda [-h] [-V] command ...
    conda is a tool for managing and deploying applications, environments and packages.
    positional arguments:
  8. The configuration conda command can be used globally (optional)

    1. vi or vim command to edit ~ /. bashrc file

      vim ~/.bashrc
    2. Press i on the keyboard to enter the editing mode, and add the following contents at the end of the file

      export PATH='anaconda Installation directory for/bin:$PATH'
    3. esc exit editing mode: enter command mode, enter wq to save and exit

    4. Let the modification take effect and execute the command: source ~/.bashrc

3. anaconda3 virtual environment management

Reference blog:

  1. Create a python=3.7 virtual environment named py37

    conda create -n py3.7 python=3.7
  2. Delete the environment named py37

    conda remove -n py3.7 --all
  3. Activate environment py37

    conda activate py37
  4. Close the current environment

    conda deactivate
  5. Displays all installed environments

    conda env list perhaps  conda info --envs
  6. Rename environment

    conda create -n newenv --clone oldenv  # Clone old environment
    conda remove -n oldenv --all  # Delete old environment
  7. Automatic activation environment

    conda config --set auto_activate_base false  # Turn off automatic activation
    conda config --set auto_activate_base true  # Turn on automatic activation

4. tensorflow installation

  • Tencerflow1.15 and tencerflow2 coexist
  • Tensorflow 1.15 is installed in the virtual environment of Python 3.6
  • Tensorflow 2 is installed in the virtual environment of Python 3.7

reference resources:

Note: installing some packages with conda may be slow or fail. Adding a domestic image source can help solve the problem. Refer to part V image source management for details

3.1 tensorflow 1.15 installation (the same as tensorflow 2 installation)

  1. Create a python=3.6 virtual environment named py36

    conda create -n py3.6 python=3.6
  2. Activate environment py36

    conda activate py36
  3. Search for available tensorflow GPU versions

    anaconda search -t conda tensorflow-gpu 

    The feedback is shown in the figure below (part of it). Find the required tensorflow version:

  4. Get the installation command of the corresponding version

     anaconda show hanyucui/tensorflow-gpu

    The feedback is as follows:

    Using Anaconda API:
    Name:    tensorflow-gpu
    Summary: Metapackage for selecting a TensorFlow variant.
    Access:  public
    Package Types:  conda
       + 1.15.0+db2
    To install this package with conda run:
         conda install --channel tensorflow-gpu
  5. Enter the command to install:

    conda install --channel tensorflow-gpu

    It is best to confirm whether it is version 1.15:

    conda install --channel tensorflow-gpu=1.15

5. anaconda3 image source management

Reference blog:


(winscp show hidden files: shortcut Ctrl+Arl+H)

  • Method 1: you can directly modify the. condarc file in the home directory, and then run conda clean -i to clear the index cache to ensure that the index provided by the mirror station is used

    (. condarc configuration file is an optional runtime configuration file, which does not exist by default, but will be created in the user's home directory when the user runs the conda config command for the first time.)

    If you use Tsinghua image source (recommended), replace the file content with the following:

    # >>> conda mirrors >>>
      - defaults
    show_channel_urls: true
    # <<< conda mirrors <<<
  • Method 2: command line management

    1. View added mirror sources

      conda config --show  # Displays the config information for all conda s
      conda config --show channels  # Displays information about channels
    2. Add cuust image source

      conda config --add channels
    3. Set the channel address displayed during the search

      conda config --set show_channel_urls ye
    4. Delete the image source of China University of science and technology

      conda config --remove channels
    5. Restore original mirror source

      conda config --remove-key channels

6. anaconda3 unloading

Reference blog:

  1. Delete the Anaconda 3 installation directory. Since the Anaconda installation files are contained in one directory, you can delete them directly

    rm -rf Installation directory
  2. Delete the following contents in the. bashrc file, namely the initialization contents of conda:

    # >>> conda initialize >>>
    # !! Contents within this block are managed by 'conda init' !!
    __conda_setup="$('/home/test/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
    if [ $? -eq 0 ]; then
        eval "$__conda_setup"
        if [ -f "/home/test/anaconda3/etc/profile.d/" ]; then
            . "/home/test/anaconda3/etc/profile.d/"
            export PATH="/home/test/anaconda3/bin:$PATH"
    unset __conda_setup
    # <<< conda initialize <<<
  3. Re execute. bashrc

    source ~/.bashrc

7. pycharm connects to the python environment in the remote linux server

  • pycharm2020.3.5 + ubuntup1p6.04.07 + anaconda3 + python3.6
  1. Configure remote server connection

    1. 1



    1.4 after configuration, click test conference to connect to the test server. After successful configuration, click apply and save to close the window

    1.5 add the synchronous mapping relationship between the local project and the remote server project, complete the configuration, save and close the window

  2. Turn on automatic synchronization

    You can also right-click the file directory to synchronize separately:

  3. Configuring the remote python environment

    3.1 file - > Settings - > python interpreter - > add add new python environment

    3.2 as shown in the figure below:

    3.3 fill in the python environment location in the remote server, so far all configuration is completed

    About python location on the server:

    • Windows: anaconda3 installation directory / envs / virtual environment name / python.exe

    • linux: anaconda3 installation directory / envs / virtual environment name / bin/python

      You can locate the python location as follows:

    About python location on the server:

    • Windows: anaconda3 installation directory / envs / virtual environment name / python.exe

    • linux: anaconda3 installation directory / envs / virtual environment name / bin/python

      You can locate the python location as follows:

Posted by rossmurphy on Fri, 29 Oct 2021 01:42:59 -0700