如何找到我的Python site-packages目录的位置?
如何找到我的site-packages目录的位置?
-
网站包目录有两种类型,全局目录和每个用户目录。
运行时会列出全局站点软件包(
“ dist-packages ”
)目录sys.path:
python -m site
要在Python代码中
getsitepackages
从站点模块运行更简洁的列表,请执行以下操作:python -c 'import site; print(site.getsitepackages())'
注意:使用
virtualenvs
时,getsitepackages
不可用,但是sys.path
从上面将正确列出virtualenv
的site-packages
目录。在Python 3中,你可以改为使用sysconfig
模块:python3 -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])'
在每个用户站点包目录(PEP 370)是其中的Python安装本地套餐:
python -m site --user-site
如果这指向一个不存在的目录,请检查Python的退出状态并查看
python -m site --help
说明。提示:运行
pip list --user
或pip freeze --user
为你提供每个用户站点软件包的所有已安装列表。实用技巧
<package>.__path__
可让你识别特定包裹的位置:(详细信息)$ python -c "import setuptools as _; print(_.__path__)" ['/usr/lib/python2.7/dist-packages/setuptools']
<module>.__file__
可让你识别特定模块的位置:(差异)$ python3 -c "import os as _; print(_.__file__)" /usr/lib/python3.6/os.py
运行
pip show <package>
以显示Debian风格的软件包信息:$ pip show pytest Name: pytest Version: 3.8.2 Summary: pytest: simple powerful testing with Python Home-page: https://docs.pytest.org/en/latest/ Author: Holger Krekel, Bruno Oliveira, Ronny Pfannschmidt, Floris Bruynooghe, Brianna Laugher, Florian Bruhin and others Author-email: None License: MIT license Location: /home/peter/.local/lib/python3.4/site-packages Requires: more-itertools, atomicwrites, setuptools, attrs, pathlib2, six, py, pluggy