您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何找到我的Python site-packages目录的位置?

如何找到我的Python site-packages目录的位置?

网站包目录有两种类型,全局目录和每个用户目录。

运行时会列出全局站点软件包(“ dist-packages ”)目录sys.path:

python -m site

要在Python代码getsitepackages站点模块运行更简洁的列表,请执行以下操作:

python -c 'import site; print(site.getsitepackages())'

注意:使用virtualenvs时,getsitepackages不可用,但是sys.path从上面将正确列出virtualenvsite-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 --userpip 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
python 2022/1/1 18:28:48 有191人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶