About the problem that the third-party package installed by pip cannot be imported in PyCharm

Generally, we install third-party packages of Python by executing the following commands in the terminal to install:

pip install 要安装的包名

After the installation is successful, it is found that there is still a problem of not being able to find the package in PyCharm. Why?
In short, PyCharm cannot find the path of the package installed by pip, such as the path of the package I pipinstalled before matplotlib:

pip show matplotlib

Shown as follows:

Name: matplotlib
Version: 3.1.2
Summary: Python plotting package
Home-page: https://matplotlib.org
Author: John D. Hunter, Michael Droettboom
Author-email: [email protected]
License: PSF
Location: /Users/superfarr/anaconda3/lib/python3.6/site-packages
Requires: pyparsing, numpy, cycler, kiwisolver, python-dateutil
Required-by: jupyterthemes

As above, matplotlibthe path of the package is: /Users/superfarr/anaconda3/lib/python3.6/site-packages
if Anacondathis software is installed on your computer , you will bring pipthis tool, otherwise you need to install it manually pip, and these two installation pipmethods determine the pipdifference in the storage location of the third-party package of Python. :

  • If it Anacondacomes with it pip, it will pipinstall the pythonpackage to the /Users/用户名/anaconda3/lib/python3.6/site-packagesfollowing by default when using the installation package
  • If it is to manually installed pip, install the package in general is pythonunder installation directory lib\site-packages\包名under

PyCharm cannot find this path by itself, so it needs to be configured manually.

Of course, you can also directly File->setting->Python Interpreterclick the plus sign in PyCharm to search for the required package name to download, but this method is slower, and the market has problems with downloading errors.
Insert picture description here
Insert picture description here

Let's talk about how to configure pipthe path installed in PyCharm

Click the bottom right corner to configure Python Interpreter (Python interpreter)
you will probably find more Python Interpreter, because if it is installed before Anacondawill own an interpreter, Mac version of PyCharm also comes with Python Interpreter, and Anacondacomes with pipinstallation The package is under the Anacondapath, so you need to find this path.
Insert picture description here
selectInterpreter Settings

Insert picture description here

Click the gear in the upper right corner and selectadd

Insert picture description here

You will find that there are many environments on the left. Here, select the first configuration environment, Existing environment, and then configure the path. If it is installed, generally ~/anaconda3/bin/python, click OK.
Then look at the third-party package of the current project and find pipthe third-party package installed before All have
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_44471490/article/details/109080174