[Linux] python的dist-packages和site-packages

site-packages

它的位置通常在: ~/.local/lib/python2.7/site-packages
通过源安装的python是使用这个地址来查找模块的. 这样做是让系统的python模块和用户自己安装的模块分割开来, 互不影响.

dist-packages

它的位置通常在: /usr/local/lib/python2.7/dist-packages
它是debian系统及其衍生系统的默认python的模块默认安装目录, 如果使用包管理器(如apt-get, easy_install, pip)安装python的模块, 都会安装到该地址下.

import模块

当python import模块的时候, 是通过sys.path里面的目录列表去查找的.
查看sys.path的方法, 打开控制台:

yasin@ubuntu:/$ python 
Python 2.7.14 (default, Sep 23 2017, 22:06:14) 
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.path
['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/home/yasin/.local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages']

参考:
https://www.cnblogs.com/kevin922/p/3161411.html
https://blog.csdn.net/ECHOutopia/article/details/48005283
https://blog.csdn.net/junli_chen/article/details/52817999

猜你喜欢

转载自blog.csdn.net/pangtouyu_qy/article/details/79878016