How to view the file location of the installed library in python

A brief summary of the location and display of the installation library:

一、位置的不同
	1.自带库在环境的  lib\\os.py
	2.自己安装库在   lib\\site-packages\\numpy\\__init__.py
二、显示方式不同
	1.自带库只能使用导入包的方式,然后只能使用包名.__file__的方式
	2.自己安装库还可以使用pip show 包名的方式显示位置

Python comes with standard library location

The .py files in the lib folder of the installation environment are all in the lib folder of the environment

import sys
print(sys.path)

How to view installed third-party libraries

The results displayed by the following two methods are different. For the reason, please refer to: https://blog.csdn.net/nyist_yangguang/article/details/109848366
Personal understanding is: the pip method displays the library in the current environment, and the conda method displays Under the condition that the library in the current virtual environment is installed, the contents of the anacond/pkgs folder are also connected. This pkgs folder speeds up the establishment of the virtual environment again
. Note:Only libraries displayed by pip list can be imported directly, the libraries displayed in the conda list but not in the pip list cannot be imported and need to be installed.

pip list
conda list # 首先确定是安装了anaconda的前提下

The location display method of python's own library

Enter the commands one by one,

python
import 包名
包名.__file__

insert image description here

The way python installs the library itself

Of course, you can also use the above self-contained package query method. In addition, you can use the following command (note: do not enter the python environment). This method is not applicable to the location query of the self-contained package.

pip show 包名

First, use

Guess you like

Origin blog.csdn.net/weixin_43794311/article/details/127732593