PyCharm integrates Anaconda

PyCharm integrates Anaconda

Anaconda is an open source Python distribution that integrates many commonly used scientific computing and data analysis tools. With Anaconda, we can easily install and manage Python packages, create and manage virtual environments. Anaconda contains many commonly used Python libraries for data analysis, machine learning and scientific computing, such as NumPy, Pandas, Matplotlib, SciPy, etc. These libraries are very commonly used in data analysis and scientific computing. In addition, Anaconda also provides Jupyter Notebook, an interactive programming environment that makes it easy to write and share data analysis code. This blog will focus on the basic use of Anaconda and how to integrate Anaconda in Pycharm.

Anaconda

Anaconda is a Python distribution and environment manager for scientific computing and data analysis. It contains many commonly used software packages and tools for scientific computing and provides a convenient way to manage Python environments. It is not recommended to use the downloaded and installed Python interpreter when analyzing Python data. Anaconda is often used. Regarding Anaconda, please read the reference documentation to install it. This article focuses on its working mechanism and integration steps.

Traditional questions

In traditional Python development, different projects may require different dependencies to run, and the same dependency may require different versions to run. The following are the dependency packages introduced by a traditional Python interpreter during development:

Untitled.png

When multiple projects use its pip to introduce and manage dependencies, it will cause dependency redundancy (multiple versions of the same dependency are mixed together, and it is impossible to effectively distinguish which dependencies a project needs). Is there a tool that can build different environments for different projects to manage? Anaconda was born for this!

Each virtual environment in Anaconda downloads and manages dependencies by itself, and is isolated from each other. This has the following benefits:

1. With the help of the virtual environment, we can clearly know what dependencies a certain project requires. When the project is running, only the dependencies in the specified virtual environment are taken, and the degree of dependency coupling between projects is reduced.

2. Anaconda comes pre-installed with a large number of dependencies, which avoids the pressure of manual installation and allows us to use it out of the box.

Virtual environment

Since we have already mentioned the working principle of Anaconda when analyzing the shortcomings of traditional problems – virtual partitioning and management of dependencies. Below we focus on the construction and management of virtual environments:

1**.Create a new environment**

In fact, Anaconda provides a default virtual environment when the download is completed, which covers all the packages that come with Anaconda. We use conda env list to view all created environments:

Untitled 1.png

Use the command conda list to view all dependencies and their versions currently downloaded and managed by Anaconda (actually the dependency packages of the virtual environment):

Untitled 2.png

This is a basic virtual environment that can help us quickly perform data analysis and development, but in the actual development process we may

A unique virtual environment needs to be built for each project:

  • Create a new environment:

    conda create --name mytest
    
    

Then we use the command conda env list to check again

Untitled 3.png

We can download our own dependency packages for the new environment (conda install -n virtual environment name dependency package):

Untitled 4.png

We see that it starts downloading python3.11 in the mytest environment.

When we need to delete an environment, enter conda env remove:

Untitled 5.png

Agent configuration

Like other package management tools, since the downloaded dependency packages are mainly from foreign warehouses, the download is slow. We recommend switching the download source of the dependency packages to domestic sources:

View configured sources

#View current conda configuration
conda config --show channels

#Delete the download source and replace it with the default source
conda config --remove-key channels


Configuration source

Select the appropriate source input command:

# University of Science and Technology of China mirror source
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/
# Beijing Foreign Studies University source
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/pkgs/main
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/pkgs/free
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/pkgs/r
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/pkgs/pro
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/pkgs/msys2
#清华源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
#Ali Cloud
conda config --add channels http://mirrors.aliyun.com/pypi/simple/
# Douban
conda config --add channels http://pypi.douban.com/simple/

View configuration information

#View configuration
conda config --show

#View added images
conda config --show channels

Restore default source

Delete the source in use and revert to the default source:

conda config--remove-key channels

PyCharm integration

Enter PyCharm and open setting → Project:xxx → Python Interpreter to set the specified interpreter environment for the specified project (the default project uses the system’s own Python interpreter and related dependencies):

Untitled 6.png

Click Add Interpreter to create a new environment, click Conda Environment, and specify the conda program (which can be used to load the environment it manages):

Untitled 7.png

At this time, it is equivalent to PyCharm integrating the Anaconda program, which can visually operate the dependencies and environment managed by the program.

Click Load Environments to load the environment managed by conda:

Untitled 8.png

We can see that after integrating the Anaconda program, PyCharm can not only load all environments, but also select common new simulation environments and load specified environments. Here we just use the environment that comes with Conda. If you have a new project and new dependencies, please create them first and then select them.


———————————END——————- ——–

Digression

In the current era of big data, how can one keep up with the times without mastering a programming language? Python, the hottest programming language at the moment, has a bright future! If you also want to keep up with the times and improve yourself, please take a look.

Interested friends will receive a complete set of Python learning materials, including interview questions, resume information, etc. See below for details.


CSDN gift package:The most complete “Python learning materials” on the entire network are given away for free! (Safe link, click with confidence)

1. Python learning routes in all directions

The technical points in all directions of Python have been compiled to form a summary of knowledge points in various fields. Its usefulness is that you can find corresponding learning resources according to the following knowledge points to ensure that you learn more comprehensively.

img
img

2. Python essential development tools

The tools have been organized for you, and you can get started directly after installation! img

3. Latest Python study notes

When I learn a certain basic and have my own understanding ability, I will read some books or handwritten notes compiled by my seniors. These notes record their understanding of some technical points in detail. These understandings are relatively unique and can be learned. to a different way of thinking.

img

4. Python video collection

Watch a comprehensive zero-based learning video. Watching videos is the fastest and most effective way to learn. It is easy to get started by following the teacher’s ideas in the video, from basic to in-depth.

img

5. Practical cases

What you learn on paper is ultimately shallow. You must learn to type along with the video and practice it in order to apply what you have learned into practice. At this time, you can learn from some practical cases.

img

6. Interview Guide

Resume template

CSDN gift package:The most complete “Python learning materials” on the entire network are given away for free! (Safe link, click with confidence)

If there is any infringement, please contact us for deletion.