Python project combat: create + activate virtual environment

Step 1: Create a new virtual environment + activate the virtual environment

When using conda to install or update software packages, an error message is reported:failed with initial frozen solve. Retrying with flexible solve

Solution

  • Step 1: Exit after failure and clean up the environment
    (1) conda update conda: Update Conda
    (2) conda clean --all: Clean up the environment and remove potentially conflicting packages
  • Step 2: Create and activate a virtual environment
    (1) Open the cmd command line terminal or Anaconda Prompt.
    (2) Create a new virtual environment (optional): conda create -name py39 python=3.9. Among them: -name py39means to create a new virtual environment named py39, Python=3.9means to specify the Python version as 3.9.
    (3) Activate the created new virtual environment: conda activate py39
    (4) Check the python version:python --version

insert image description here

(1.1) BUG: The Python version displayed after activation is different from the one specified when creating a new one.

  • Reason : It may be due to some problems with Python version management in Anaconda. (Most likely due to poor network)
  • Workaround (Install python separately after activating the virtual environment), the operation is as follows: conda activate py39+ conda install python=3.9+ python --version.

(1.2) Successful activation: In the environment configuration of Anaconda software, a py39 virtual environment will appear.

insert image description here

Step 2: Configure the virtual environment in Pycharm + activate the environment in Terminal and use it.

Note: PyCharm's Terminal (terminal) and cmd (command prompt) are two different command line tools, the former is used to execute commands and operations in PyCharm.

(1) The environment has not been configured:
insert image description here
(2) The environment has been configured: enter Run / Debug Configurations, select Python interpreter
insert image description here

Step 3: Exit the virtual environment + delete the virtual environment

  • Exit the virtual environment:conda deactivate
  • Delete the virtual environment: conda env remove --name py39. Among them: py39 is the name of the virtual environment to be deleted. Note: Before deleting a virtual environment, make sure that you no longer need it and that there is no important data in it. Use caution to avoid accidentally deleting important environments or data.

insert image description here

Guess you like

Origin blog.csdn.net/shinuone/article/details/131421541