How to configure the virtual environment of anaconda in pycharm

Friends who don't want to read the text can also watch the following video:
The correct way to open Anaconda and Pycharm in Python learning

Environment configuration

The configuration of the environment is divided into three steps: configure the virtual environment and the packages required by the installer and open the project in pycharm

Configure the virtual environment

Configuring the virtual environment needs to be done through anaconda . The download address of anaconda is: https://docs.conda.io/en/latest/miniconda.html

Windows users can download miniconda of python3.8

image-20210524105054366

After the download is complete, double-click to install it. Note that these must be selected.

image-20210524105240779

image-20210524105344251

After the program is installed, open the Windows command line (cmd), enter conda env list, and the following information appears, indicating that conda has completed the installation

image-20210524105549465

Enter the following command on the command line to create a virtual environment

conda create -n tf2.3 python==3.7.3
  • 1

The meaning of this instruction is to create a virtual environment with python version 3.7.3 and name tf2.3

image-20210524105851905

After the installation is complete, enter the following command to activate the virtual environment. The parentheses shown in the figure below indicate that the environment is successfully activated.

conda activate tf2.3 
  • 1

image-20210524110020460

Packages required by the installer

Then execute the following commands in sequence on the command line to install the packages required by the program (please choose the packages to be installed freely according to your program)

pip install tensorflow-cpu == 2.3.0 -i https://mirror.baidu.com/pypi/simple
pip install pyqt5 -i https://mirror.baidu.com/pypi/simple
pip install pillow -i https://mirror.baidu.com/pypi/simple 
pip install opencv-python -i https://mirror.baidu.com/pypi/simple 
pip install matplotlib -i https://mirror.baidu.com/pypi/simple 
  • 1
  • 2
  • 3
  • 4
  • 5

image-20210524110423033

Note: Each line of commands must be executed

open program in pycharm

For the convenience of viewing and debugging the code, we use pycharm here. The download address of pycharm is: https://www.jetbrains.com/pycharm/download/#section=windows

image-20210524110552220

Here you can choose the community version to download

Please be sure to select these options during the installation process to avoid unnecessary trouble later

image-20210524111504457

After the installation is complete, find our code and open it through pycharm

image-20210524111754027

After opening, we will find in the lower right corner of the softwareAdd interpreterAdd the virtual environment you just created

image-20210524111938905

image-20210524112020699

Finally, tf2.3 is displayed in the lower right corner, indicating that our current virtual environment is tf2.3

image-20210524112057673

When installing the program package later, open the terminal directly under pycharm and executepip install xxxcommand, the package will be automatically installed in the current virtual environment

image-20210524112334043

Tags: How to configure the virtual environment of anaconda in pycharm

Programming environment configuration

Related: How to configure the virtual environment of anaconda in pycharm