如何找到我的Python site-packages目录的位置? [英] How do I find the location of my Python site-packages directory?

查看:1355
本文介绍了如何找到我的Python site-packages目录的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何找到我的站点软件包目录的位置?

How do I find the location of my site-packages directory?

推荐答案

站点包目录有两种类型, global 每个用户.

There are two types of site-packages directories, global and per user.

  1. 全局网站程序包("

  1. Global site-packages ("dist-packages") directories are listed in sys.path when you run:

python -m site

要获取更简洁的列表,请从站点模块中运行getsitepackages 在Python代码中:

For a more concise list run getsitepackages from the site module in Python code:

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

注意:使用virtualenvs getsitepackages不可用,但是,上面的sys.path将正确列出virtualenv的site-packages目录.在Python 3中,您可以使用 sysconfig模块代替:

Note: With virtualenvs getsitepackages is not available, sys.path from above will list the virtualenv's site-packages directory correctly, though. In Python 3, you may use the sysconfig module instead:

python3 -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])'

  • 每个用户站点软件包目录( PEP 370 )是Python安装本地软件包的位置:

  • The per user site-packages directory (PEP 370) is where Python installs your local packages:

    python -m site --user-site
    

    如果该目录指向不存在的目录,请检查Python的退出状态,并参见python -m site --help以获得解释.

    If this points to a non-existing directory check the exit status of Python and see python -m site --help for explanations.

    提示:运行pip list --userpip freeze --user会为您提供每个用户安装的所有 网站软件包的列表.

    Hint: Running pip list --user or pip freeze --user gives you a list of all installed per user site-packages.


    实用提示

    • <package>.__path__可让您标识特定程序包的位置:(详细信息)


      Practical Tips

      • <package>.__path__ lets you identify the location(s) of a specific package: (details)

        $ python -c "import setuptools as _; print(_.__path__)"
        ['/usr/lib/python2.7/dist-packages/setuptools']
        

      • <module>.__file__可让您标识特定模块的位置:(差异)

      • <module>.__file__ lets you identify the location of a specific module: (difference)

        $ python3 -c "import os as _; print(_.__file__)"
        /usr/lib/python3.6/os.py
        

      • 运行pip show <package>以显示Debian风格的软件包信息:

      • Run pip show <package> to show Debian-style package information:

        $ 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 site-packages目录的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆