Install Anaconda under Red Hat and create a Python virtual environment

Series of articles:
pycharm connects to a remote server and debugs the code

Sometimes you need to work in multiple Python environments. It is quite convenient to use Anaconda to manage the Python environment.

Install Anaconda

download

Anaconda's official website: https://www.anaconda.com/download/Download
: https://www.anaconda.com/products/individual#Downloads

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

installation

Enter the path where you downloaded the installation package Anaconda3-2020.11-Linux-x86_64.sh in the previous step

Insert picture description here
installation:

bash Anaconda3-2020.11-Linux-x86_64.sh

During the installation process, basically keep pressing enter or yes to default.

Configure environment variables

After the installation is complete, we also need to add environment variables to facilitate our startup.

Regardless of the kernel (version) system, you can modify the configuration information of /etc/profile or /etc/bashrc to achieve the purpose of setting environment variables

Because I am not an administrator, I cannot set global environment variables, so I cannot add environment variables through sudo vi /etc/profile.
You can add environment variables as follows

vim ~/.bash_profile

Insert picture description here
Then add the following code at the end of the file:

export PATH=$PATH:$HOME/anaconda3/bin

The PATH here is your anaconda3 installation path, mine is under ~/anaconda3/bin, so it is the path above.

test

Terminal input:
Insert picture description here
If python is in the picture above, the installation is successful.

Anaconda creates multiple Python environments

  1. conda env list or conda info -e check which virtual environments currently exist:
    Insert picture description here

  2. Create a Python virtual environment:
    use conda create -n your_env_name python=XX (2.7, 3.6, etc.) anaconda command to create a virtual environment whose python version is XX and the name is your_env_name. The your_env_name file can be found under the envs file in the Anaconda installation directory.

  3. Use activated (or switch between different python versions) virtual environment. Open the command line and enter python --version to check the current python version. Use the following command to activate your virtual environment (i.e. change the version of python).

source activate your_env_name(虚拟环境名称)

or:

conda activate your_env_name(虚拟环境名称)

Then use python --version to check whether the current python version is what you want.

  1. Install additional packages in the virtual environment.

    Use the command conda install -n your_env_name [package] to install the package into your_env_name
    or directly pip install

  2. Close the virtual environment (that is, exit from the current environment and return to use the default python version in the PATH environment).

    Just use the following command.

    Linux: source deactivate

    Windows: deactivate

  3. Delete the virtual environment.

    Use the command conda remove -n your_env_name (virtual environment name) --all to delete.

  4. Delete a package in the environment.

    Use the command conda remove --name yourenvnamepackage_name

Reference: https://blog.csdn.net/dongwanli666/article/details/78920059

Guess you like

Origin blog.csdn.net/weixin_44456692/article/details/113002314