Article Directory
foreword
Before programming and developing based on Ubantu, most students may choose Anaconda for installation package management. Therefore, today I will sort out the basic usage methods such as Anaconda environment configuration and mirror modification, hoping to help you.
1. Anaconda installation
The Anaconda3 installation package can be found on the official website to download the linux version, then decompress and install it.
Pay attention to the following installation instructions:
bash /home/gzx/APP/Anaconda3-xx.sh
The path is installed under its own corresponding address.
2. Anaconda environment configuration
After the installation is complete, you need to configure the environment. Enter the terminal:
sudo gedit ~/.bashrc #进行bashrc环境文件
After opening the bashrc file, add at the end:
export PATH="/home/gzx/APP/anconda3/bin:$PATH"
Note that the address is replaced with your own.
Then restart or enter in the terminal:
source ~/.bashrc #刷新
This global variable determines that you can find it later when using the conda command.
Use the following command to check the installation status.
conda --version
Appear
gzx@gzx-OMEN-by-HP-Laptop-17-ck0xxx:~$ conda --version
conda 22.9.0
Anaconda installation is complete.
3. Basic operation of Anaconda
3.1 Create a virtual environment
Create a new virtual environment, terminal input:
conda create -n carla_work python==3.8.0
carla_work is the environment name, and the version number of python in the virtual environment needs to be added.
3.2 View the virtual environment
There are two ways to view the virtual environment:
- Terminal input:
conda env list
- terminal input
conda info -e
result:
gzx@gzx-OMEN-by-HP-Laptop-17-ck0xxx:~$ conda env list
# conda environments:
#
base /home/gzx/APP/anaconda3
carla_work /home/gzx/APP/anaconda3/envs/carla_work
gzx@gzx-OMEN-by-HP-Laptop-17-ck0xxx:~$ conda info -e
# conda environments:
#
base /home/gzx/APP/anaconda3
carla_work /home/gzx/APP/anaconda3/envs/carla_work
3.3 Activate the environment
The activation environment can be used:
conda activate carla_Work
or
source activate carla_work
Individuals can only use source activation, everyone can try it.
result:
gzx@gzx-OMEN-by-HP-Laptop-17-ck0xxx:~$ source activate carla_work
(carla_work) gzx@gzx-OMEN-by-HP-Laptop-17-ck0xxx:~$
3.4 Exit the environment
Terminal input:
conda deactivate
result:
(carla_work) gzx@gzx-OMEN-by-HP-Laptop-17-ck0xxx:~$ conda deactivate
gzx@gzx-OMEN-by-HP-Laptop-17-ck0xxx:~$
3.5 Delete environment
Terminal input:
conda remove -n carla_work --all
I won’t give everyone a try to delete it. Generally speaking, only delete it if you don’t need the environment.
Four, Anaconda modify the image
Due to external network restrictions, Anaconda downloads the installation package very slowly. Here we can use domestic mirrors to increase the download speed of the installation package.
4.1 View the initial download source
Terminal input:
conda config --show
Find the title of channels, and you will find that channels is the default defaults, that is, repo.anaconda.com/xx. This URL needs to be accessed from the external network, otherwise it will be very slow, and the download will often fail after timeout.
4.2 Domestic mirroring and modification
Tsinghua Mirror:
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
Revise:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
You can set the download and installation package to display the source path:
conda config --set show_channel_urls yes
4.3 View configuration files and view sources
You can see it in your home directory, the condarc file, after opening:
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- defaults
show_channel_urls: true
View source:
Enter again in terminal:
conda config --show
result:
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- defaults
So far, the source file has been modified successfully.
4.4 Restoring source files
Terminal input:
conda config --remove-key channels
Or delete the specified source:
conda config --remove-key channels XXX
Summarize
This article will sort out the knowledge of Anaconda environment construction and mirror modification for you, hoping to help you, especially students who need Anaconda to manage the environment before programming and development.
Friends who like it, move your little hands to follow, I will regularly share some of my knowledge summaries and experiences, thank you!