如何找到目录的位置?site-packages
网友回答:
>>> import site; site.getsitepackages()
['/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages']
(或只是第一项site.getsitepackages()[0]
)
网友回答:
有两种类型的站点包目录:全局目录和每用户目录。
sys.path
python -m site
有关更简洁的列表,请从 Python 代码中的站点模块运行:getsitepackages
python -c 'import site; print(site.getsitepackages())'
谨慎:在虚拟环境中,getsitepackages 不适用于旧版本的 ,但是,从上面将正确列出 virtualenv 的站点包目录。在 Python 3 中,你可以改用 sysconfig 模块:virtualenv
sys.path
python3 -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])'
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>
$ 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 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
为提高可读性而设置格式(而不是用作单行),如下所示:
from distutils.sysconfig import get_python_lib
print(get_python_lib())
来源:一个非常旧版本的“如何安装 Django”文档(尽管这不仅对 Django 安装有用)
模板简介:该模板名称为【如何找到目录的位置?site-packages】,大小是暂无信息,文档格式为.编程语言,推荐使用Sublime/Dreamweaver/HBuilder打开,作品中的图片,文字等数据均可修改,图片请在作品中选中图片替换即可,文字修改直接点击文字修改即可,您也可以新增或修改作品中的内容,该模板来自用户分享,如有侵权行为请联系网站客服处理。欢迎来懒人模板【Python】栏目查找您需要的精美模板。