栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何找到我的Python 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 pytestName: pytestVersion: 3.8.2Summary: pytest: simple powerful testing with PythonHome-page: https://docs.pytest.org/en/latest/Author: Holger Krekel, Bruno Oliveira, Ronny Pfannschmidt, Floris Bruynooghe, Brianna Laugher, Florian Bruhin and othersAuthor-email: NoneLicense: MIT licenseLocation: /home/peter/.local/lib/python3.4/site-packagesRequires: more-itertools, atomicwrites, setuptools, attrs, pathlib2, six, py, pluggy


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/441685.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号