Article directory
foreword
When we use Python, sometimes we need multiple Python environments, some use Python2, and some use Python3. At this time, we need to install multiple versions of Python, but it is very inconvenient to manage. The role of Conda is revealed at this moment. It can create multiple Python environments and manage them in a unified manner without interfering with each other, which is very convenient.
1. What is Conda
Conda is an open source package and environment management system for installing multiple versions of packages and their dependencies, and switching between them easily. Its package management is similar to pip and can be used to manage third-party packages of Python.
Anaconda
and Miniconda
are both Conda-based management tool collections, which include Conda, a certain version of Python, and a batch of third-party libraries. Among them, Anaconda contains more than 180 scientific computing packages such as Conda and Python and their dependencies, so it is relatively large. And Miniconda is the smallest Conda installation environment, including only some necessary tool sets.
2. How to obtain
Both Anaconda and Miniconda support mainstream operating systems such as Windows
, , andmacOS
. Please select the corresponding version to download according to your needs.Linux
3. Use the Conda command to configure multiple environments
1. Create a new environment
After Anaconda (or Miniconda) is installed, open Anaconda Prompt in the start menu and execute the following command
conda create -n tensorflow python=3.8.12
tensorflow
is the name of the new environment created, which can be chosen arbitrarily-n
is short--name
forpython=3.8.12
is the Python version number installed in the new environment, if not added, it defaults to the Python version of Anaconda (or Miniconda)
2. Activate the new environment
Enter the command to activate the previously created environment named tensorflow
conda activate tensorflow
- When the command line window
(base) C:\Users
changes(tensorflow) C:\Users
, it means that it has been activated and entered the new environment
3. Configure the new environment
In the current environment , enter the command to install tensorflow
# 使用 conda 安装
conda install tensorflow
# 使用 pip 安装 (推荐)
pip install tensorflow
In the Python environment created with Conda, you can use pip to install the package
Just wait for the installation to complete
4. Exit the new environment
Exit the tensorflow environment
conda deactivate
- When the command line window
(tensorflow) C:\Users
changes(base) C:\Users
, it means that the new environment has been exited and returned tobase
the environment
5. Check all environments
Enter the following command in any environment
conda info -e
# 或者
conda env list
After executing this command, the following results are displayed
## conda environments:
#
base * C:\ProgramData\Anaconda3
tensorflow C:\ProgramData\Anaconda3\envs\tensorflow
*
The sign indicates the current environment position
6. Check all installed packages
conda list
The following display is the installed package
## packages in environment at C:\ProgramData\Anaconda3:
#
## Name Version Build Channel
_ipyw_jlab_nb_ext_conf 0.1.0 py38_0
alabaster 0.7.12 py_0
anaconda 2020.11 py38_0
anaconda-client 1.7.2 py38_0
...
## 注:剩余的包此处已略过
7. Delete an environment
conda remove -n tensorflow --all
tensorflow
is the name of the removed environment
8. Rename an environment
Conda does not actually have a renaming command. The renaming is done by cloning in two steps:
- Clone an old environment first, and rename it when cloning
- then delete the old environment
## 第一步:
conda create -n pytorch --clone tensorflow
## 第二步:
conda remove -n tensorflow --all
--clone
followed by the name of the old environment-n
followed by a new name
Fourth, use Anaconda Navigator to configure multiple environments
1 Introduction
Anaconda Navigator is Anaconda's desktop graphical user interface, which can realize the basic operation of Conda without using command line commands, and is also suitable for Windows, macOS and Linux.
2. Install
Anaconda Navigator has been installed in the default base
environment , and Miniconda needs to enter the following command to install
conda install anaconda-navigator
3. Basic operation
After opening Anaconda Navigator, follow the steps below to create an environment:
4. Introduction to the Environment Options Panel
5. Other operations
- When installing a Python package in an environment, use
conda
the command orpip
the command base
As the basic environment, Anaconda is automatically generated after the installation is complete- Other configured environment locations:
C:\ProgramData\Anaconda3\envs
(Take the default installation location as an example)