dist-packages vs site-packages

dist-packages 和 site-packages的区别

Reference:

https://stackoverflow.com/questions/9387928/whats-the-difference-between-dist-packages-and-site-packages
https://stackoverflow.com/questions/122327/how-do-i-find-the-location-of-my-python-site-packages-directory

总结

  1. 系统自带的pip, 安装的包会放进去dist-packages(debian-specific-packages)中。而conda的pip安装的包会放进site-packages, 因为这个pip不是类似apt-get系统包管理安装的。
  2. 从源代码手动安装的包,会放进去site-packages(on-site packages)中。 例如自己编写了一个hello.py模块,想在其它程序中调用(import), 就要把hello.py放到python全局环境变量目录里,一般放在site-packages 目录下,这个目录在不同的OS里放的位置不一样,用 print(sys.path) 可以查看python环境变量列表。
  3. 获取dist-packages和site-packages位置
import sys; 
print [f for f in sys.path if f.endswith('packages')]

conda的虚拟环境中,这条命令只显示site-packages的位置。

posted @ 2018-04-03 11:38  Rocin  阅读(410)  评论(0编辑  收藏  举报