Anaconda3 installation and solving conflicts with native Python
Article directory
1. Introduction to Anaconda
Anaconda is a software package for learning and developing the Python programming language, an integrated development environment (IDE) written in Python. It provides multiple command line tools, such as shell, condal, etc., as well as the supporting dependency manager pip. By using these tools and library files, you can quickly set up your own Python environment and conduct various types of coding experiments. Compared to other Unix/Linux command-line interfaces, Anaconda is more customizable and flexible because it provides a graphical user interface (GUI) similar to Windows desktop applications.
The anaconda3 package is part of the Anaconda suite, which contains many useful tools and libraries, such as pip_packager, condal-install, jupyterhub, etc. These tools can help you easily build, test and deploy python code. By using Anaconda3, you can learn and develop python more efficiently, and master various mainstream frameworks and technologies in a short period of time.
The relationship between Anaconda and python
Anaconda3 has a very close relationship with python. As an integrated development environment (IDE), Anaconda3 can connect many different frameworks and libraries to easily develop and debug Python applications.
Anaconda includes Conda, Python and a lot of installed toolkits, such as: numpy , pandas , etc.
Miniconda includes Conda, Python , saving disk space is preferred
Conda is an open source package and environment manager that can be used to install different versions of software packages and their dependencies on the same machine, and to switch between different environments
Advantages of Anaconda
By using Anaconda, you can learn and develop python more efficiently, and master various mainstream frameworks and technologies in a short period of time.
First, anaconda is more customizable and flexible because it provides a graphical user interface (GUI) similar to Windows desktop applications. This means that you can personalize elements such as toolbars, menus, and buttons, and perform keyboard shortcuts more conveniently. At the same time, Anaconda also provides a wealth of plug-ins and extensions, which can help you better build and test complex Python code.
Second, anaconda has better language support . Compared with other command line interfaces, Anaconda provides a more complete automation library and sample code files, which makes it easier for you to understand and master the programming language and development environment you are using. At the same time, Anaconda also provides many pre-installed functions and modules, which can help you better develop and deploy projects.
Finally, Anaconda's community is relatively active , with many enthusiastic volunteers providing technical support and answering questions.
conda treats almost all tools and third-party packages as packages, even including python and conda itself ! Therefore, conda breaks the constraints of package management and environment management, and can easily install various versions of python and various packages and switch easily.
Reference: Still don't understand what Anaconda is? It is enough to read this article
Second, the installation of Anaconda3
To install Anaconda3 in a Windows environment, you can follow the steps below:
-
Download the Anaconda3 package.
Official website download address: https://www.anaconda.com/products/distribution
Tsinghua mirror source download: https://repo.anaconda.com/archive/ (note that you choose your corresponding version)
-
Right-click the downloaded installation package and run it as an administrator to enter the installation interface.
Click Next > I agree (choose just me) > Next > -
Choose an installation location and click Install. (It is recommended to use English for the installation path, try not to contain spaces and other characters)
ps: In "Advanced Installation Options" , it is not recommended to check "Add Anaconda to my PATH environment variable." ("Add Anaconda to my environment variable.") . Because if checked, it may affect the use of other programs. -
Wait for the installation to complete.
After the installation is successful, you will see the "Thanks for installing Anaconda" dialog box:
ps: Note that after installation, the system default Python will change to the Python version installed with Anaconda. After Anaconda is installed, a default Python environment will be created in the system, and all packages installed in the default environmentconda list
can .
Official installation tutorial: https://docs.anaconda.com/anaconda/install/windows/
conda --version
After the command line is entered, the following content appears, indicating that the installation is successful
'conda' is not recognized as an internal or external command, operable program or batch file. Solving reference:
https://blog.csdn.net/m0_68744965/article/details/125700817
Set domestic mirror source
If you need to install a lot of packages, you will find that the download speed of conda is often very slow, because the Anaconda.org server is abroad, here we can use the Tsinghua mirror source to speed up the download speed, the configuration is as follows:
# 添加Anaconda的清华镜像
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
# 设置搜索时显示通道地址
conda config --set show_channel_urls yes
3. Basic usage
Basic usage of the command:
usage: conda-script.py [-h] [-V] command ...
Using help:
conda --help 或者 conda
Commonly used commands:
conda clean # 删除未使用的包和缓存
conda config # 修改.condarc中的配置值
conda create # 从指定包的列表中创建一个新的conda环境
#eg:conda create --name <env_name> <package_names>
conda info # 显示有关当前conda安装的信息
conda install # 将程序包列表安装到指定的conda环境中
conda list # 列出所有已安装的科学包及其依赖项
conda package # 低级别conda软件包实用程序。(实验)
conda remove # 从指定的conda中删除程序包列表环境
conda run # 在conda环境中运行可执行文件
conda search # 搜索包并显示相关的包信息。
conda uninstall # conda remove的别名
conda update # 将conda软件包更新到最新的兼容版本
#eg: 更新conda至最新版本 conda update conda
conda upgrade # conda update 的别名
Examples of environmental management:
- Create environment NN1 containing numpy and pandas packages
conda create -n NN1 numpy pandas
ps: If the Python version is not specified when installing Python after creating the environment, the same Python version as the Anaconda version will be installed
- Switch environment to NN1
conda activate NN1
- exit environment
conda deactivate
- Show created environment
conda info --envs 或者 conda info -e 或者 conda env list
- Copy environment NN1 to NN2
conda create --name NN1 --clone NN2
ps: After cloning, the two environments exist and have the same configuration
- delete environment NN1
conda remove --name NN1 --all
Package management example:
- update all packages
conda update --all
- Install the numpy package in the current environment
conda install numpy
- Uninstall the numpy package in the current environment
conda remove numpy
ps: conda uses the same python pip, pip does not have environment management function, the same, pip is also applicable to conda
For details, please refer to: Anaconda introduction, installation and usage tutorial
4. Solve the problem of conflict
Pre-confirmation:
- Both Python and Anaconda are installed on the computer and environment variables are configured
- Both need to be used (otherwise uninstall one of them)
Solution one:
Unset one of the environment variables.
For example, if you want to use native python by default, delete the root directory of Anaconda in the environment variable.
Solution 2 (recommended):
Change the name of the python.exe file in the installation directory to distinguish between the two, (copy one first)
python
In this way, the default input is to use native Python when using it , and if python-a
it is used, use Anaconda.
Note: After this change, the pip command should also be distinguished. To use anaconda, you need to add before the pip commandpython-a -m
Python-ana –m pip –-version #查看当前Python对应的pip版本;
Python-ana –m pip list #查看当前Python对应的pip安装的第三方库;
Python-ana –m pip install #库名即可安装对应的扩展库;
Python-ana –m pip uninstall #库名即可卸载对应的扩展库
question:
Every time I open it with the command line, python-a
the same warning appears, and I need to activate the environment first every time.
In addition, the default conda environment is called base, so conda activate base
just run:
Reference: Perfect solution to the conflict between Python and anaconda, you deserve it