[PyCharm] Solve the problem that pip cannot be used after creating a new virtual environment


1.Problem description and solution

  • When creating or opening a project in PyCharm, we need to select a python interpreter. If we choose to create a new virtual environment, as shown in the figure below:

Insert image description here

  • After entering the project, we open the terminal and see that we have automatically entered the virtual environment:

Insert image description here

  • However, if we try to use the pip command, an error will be reported , as shown in the figure:

Insert image description here

  • At this time, we only need to delete the folder in the picture :

Insert image description here

  • Then try using the pip command again:

Insert image description here

  • You can see that pip can be used normally!
  • Since I inherited the global site, I have a lot of packages here

2. Use of virtual environment

2.1 Features

  • Installing packages in a virtual environment does not affect global packages at all
  • Virtual environments are free to use global packages as long as they choose to inherit the global site
  • As shown in the picture, I installed scipy in the virtual environment, but this package is not available globally:

Insert image description here
Insert image description here

2.2 Entry and exit

Enter

<project-path>/venv/Scripts/activate

quit

<project-path>/venv/Scripts/deactivate

Guess you like

Origin blog.csdn.net/qq_50791664/article/details/130784626
Recommended