How To Use Anaconda & Pycharm | Configure the environment

How To Use Anaconda&Pycharm | Anaconda super detailed installation tutorial

introduction

I recently reinstalled the system and needed to reconfigure the development environment. I remembered that I didn’t know anything about development tools before, and my development environment was a mess. Although it could be used, it couldn’t use the powerful functions of Anaconda+Pycharm, so I planned to write a tutorial on the installation and use of Anaconda and Pycharm to help Some computer novices like me.

Anaconda

Introduction to Anaconda

Anaconda (official website) is a distribution version that can easily obtain and manage packages, and at the same time, the environment can be managed uniformly. Anaconda includes more than 180 scientific packages and their dependencies including conda and Python. 1

Simply put, anaconda integrates most of the dependencies and toolkits developed in Python and provides a container that can manage these dependencies and toolkits.

Anaconda installation tutorial

  1. Enter the Anaconda official website , click Free Download in the upper right corner to download Anaconda (pay attention to your computer configuration, I am Win, 64-bit)
    Anaconda official website

  2. After the download is complete, we open the folder where the Anaconda installation package is located, click on the installation package, and start the installation program
    The folder where Anacona is located

  3. Enter the interface and select Next > I Agree > Just Me >****
    Anaconda installation interface
    A
    B

At this point, enter a Destination Folder path selection and install it according to your personal needs. It is generally not recommended to install to the C drive. Here I will change it to the D drive installation. The subsequent paths will not change. It is recommended that you remember
this path and add environment variables later. It is needed when

C
D
Then click Next
and such an interface will appear (python3.11), as shown in the figure.
If you need to use multiple versions of python or multiple different versions of anaconda, it is recommended that you choose the second option , which is Add Anaconda3 to my PATH environment variable , otherwise it will not be selected, I will not select it here.
Insert image description here
Click Next and Anaconda will start to be installed.
4. After the download is completed, keep clicking Next and Anaconda will be opened for the first time.
However, we cannot use Anaconda yet, and we need to add Anaconda's environment variables first.
E5. Copy the Anaconda download path we just created. It doesn’t matter if you don’t remember it. We can find the Anaconda icon on the desktop, right-click to open the file location, and it’s OK.

Insert image description here
my path

D:\Users\Crabfish\anaconda3
and we also need to use this path
D:\Users\Crabfish\anaconda3\Scripts

6. Add environment variables
to win system, search for advanced system settings in the search bar , open it, click Environment Variables.
Insert image description here
Insert image description here
![Insert image description here](https://img-blog.csdnimg.cn/4f6b6c010b62404291dca7ce6a85e8c1.png
In System Variables , find Path and click Edit .
Insert image description here
After entering, click New, copy the path just now,
Insert image description here
confirm, and close the window.
The Anconda installation is complete. The next step is to use anaconda to configure the environment. So let's first check whether we have downloaded anaconda.
Windows users, please open "Anaconda Prompt"
Insert image description here
. This is the basic environment of conda.
We enter >conda --version to view the conda version.
Enter >conda info to view conda information
Insert image description here
. If it is displayed normally, it means that anaconda is installed successfully.
##Anaconda usage
Now we officially use Anaconda to configure our environment.

Add domestic mirror source

Anaconda's default download sources for various packages are all abroad. The download speed is slow and often interrupted. Therefore, it is necessary to configure a domestically installed mirror. Then at this time, you need to set up a mirror source to improve the download speed. We choose Tsinghua University's here. Mirror source.

View current mirror source

We first enter Anaconda Prompt Insert image description here
and enter the following command to view the current mirror source.

conda config --show channels

View current mirror source
defaults means that no mirror source is currently added.
2) Create an environment
. There are four mainstream methods for creating a virtual environment. Here is a blog for you to choose.
How to create a virtual environment in Python , here is the conda create method.


Enter conda create --n name python=3.9 on the command line

Among them, conda create --n is the command to create a virtual environment. –n means that it is followed by the name of the environment. The name can be changed by yourself. The subsequent python=3.9 is equivalent to the installation package required for the environment, or it can be Jupyter notebook. It can also be other dependencies, =3.9 is equivalent to the version that requires python to be downloaded.
After entering the command, we can see that the system is undergoing installation planning.
Insert image description here
Here you will be provided with the Package Plan, which is the installation package that will be downloaded in the virtual environment, such as python, pip, etc. Then there will be another option here, enter y, that is Can.
Insert image description here
Insert image description here
At this time, he will start to create a virtual environment and install some of the installation packages you need.
After the installation is complete, we can notice his prompt,
Insert image description here
which is equivalent to telling us that if we want to enter the virtual environment, we need to enter the command:

conda activate name

If we want to exit this virtual environment, then we need to enter the command:

conda disabled

Now, let's try to enter this virtual environment.
Insert image description here
We can notice that the (base) in front of the path becomes the name of our virtual environment, which means that we have successfully entered the virtual environment we created from the basic environment.

Then at this time, we can add our mirror source here.
Enter the command:

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/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/

Insert image description here
As shown in the picture, it means it has been added successfully.
3. Install related packages.
If you need to add other dependencies and installation packages when you just created the virtual environment, including subsequent learning, then you can use **pip install** to complete it. The pip command can be used very well. Help us download the required packages.
For example:

pip list to view existing installation packages
pip install to download the installation package
pip uninstall to delete the installation package

Insert image description here
(Numpy is downloaded at the same time here because downloading opencv requires downloading numpy first)
Insert image description here
Here we can see that opencv–python has been installed.
At this point, do you feel that maybe downloading this way is too complicated?
When we download the project on GitHub, a file named requirement.txt will be provided in the code repository. This is actually the relevant installation package and version number required for environment configuration. We only need to execute it to install it with one click, pip install -r requirements.txtand This method is offline downloading, that is, offline downloading. However, the installation of the mirror source still requires an Internet connection.
pip uses requirement.txt to download

Check the current virtual environment

conda env list

Insert image description here
I won't go into details about the use of virtual environments here. I will just talk about the general use here. If any friends want to know the various uses of virtual environments in detail, then I will provide a blog here with detailed virtual environment usage commands.
Use of virtual environments

Pycharm

Introduction to Pycharm

Pcharm is an integrated environment for Python developers. It has IDE, Markdown and other functions. It can solve most py development needs in one piece. Combined with the functions of conda, it is simply not perfect.

Installation of Pycharm

For the installation of pycharm on the pycharm official website
Insert image description here
, I will provide you with a pycharm installation tutorial by Chuanchuan Noob, which is very good.
If you have installed anaconda according to the anaconda installation tutorial I provided above, there is no need to download python additionally. Just follow the tutorial to download pycharm and you are good to go.
pycharm installation

Add conda environment in Pycharm

We enter pycharm, click, create a new project
Insert image description here
, select the previously configured interpreter , click Add Interpreter > Add Local Interpreter,
Insert image description here
Insert image description here
select the conda environment
Insert image description here
, find the Scripts folder in the file path where we downloaded anaconda, there will be one in itconda.exe , click it.
Insert image description here
Here we choose to use the existing environment, and select the virtual environment we created
Insert image description here
Insert image description here
and click OK
Insert image description here

Click Create to enter the project.

Insert image description here
After entering, it will show that the relevant interpreter is being loaded. We only need to wait for it to finish loading.
Insert image description here

After the loading is completed, we try to run main. The green triangle in the upper right corner is the run button.
Insert image description here
Insert image description here
We can see that the runtime console outputs normally, indicating that we have completed the cooperation between pycharm and anaconda, and the environment configuration is now complete.

Pycharm plug-in recommendations

To install the plug-in, we only need to find filethe key in the upper left corner, click it setting, and then find it plugins. You can download the plug-in here. As long as you restart, the plug-in will run.

Pycharm, like vscode and vs, has many rich plug-ins. Here are several plug-in recommended blogs, which also introduce the use of related plug-ins. You can download them by yourself.
Plug-in recommendation

end

I hope my article can be helpful to you, and I hope everyone can have a happy day.


  1. Introduction to Anaconda↩︎

Supongo que te gusta

Origin blog.csdn.net/Crabfishhhhh/article/details/131707726
Recomendado
Clasificación