pip 在哪里安装其软件包?

问题描述 投票:0回答:11

我激活了安装了 pip 的 virtualenv。我做到了

pip3 install Django==1.8

Django 已成功下载。现在,我想打开 Django 文件夹。该文件夹位于哪里?

通常它会在“下载”中,但我不确定如果我在 virtualenv 中使用 pip 安装它会在哪里。

python django pip virtualenv
11个回答
1209
投票

pip show <package name>
将提供 Windows 和 macOS 的位置,我猜是任何系统。 :)

例如:

> pip show cvxopt
Name: cvxopt
Version: 1.2.0
...
Location: /usr/local/lib/python2.7/site-packages

233
投票

pip list -v
可用于列出软件包的安装位置,在https://pip.pypa.io/en/stable/news/#b1-2018-03-31

中介绍

使用“-v”选项运行 list 命令时显示安装位置。 (#979)

>pip list -v
Package                  Version   Location                                                             Installer
------------------------ --------- -------------------------------------------------------------------- ---------
alabaster                0.7.12    c:\users\me\appdata\local\programs\python\python38\lib\site-packages pip
apipkg                   1.5       c:\users\me\appdata\local\programs\python\python38\lib\site-packages pip
argcomplete              1.10.3    c:\users\me\appdata\local\programs\python\python38\lib\site-packages pip
astroid                  2.3.3     c:\users\me\appdata\local\programs\python\python38\lib\site-packages pip
...

此功能在

pip
10.0.0b1 中引入。在 Ubuntu 18.04 (Bionic Beaver) 上,随
pip
pip3
安装的
sudo apt install python-pip
sudo apt install python3-pip
是 9.0.1,没有此功能。

检查 https://github.com/pypa/pip/issues/5599 是否有合适的升级方式

pip
pip3


182
投票

pipvirtualenv一起使用时通常会在路径

<virtualenv_name>/lib/<python_ver>/site-packages
中安装软件包。

例如,我使用 Python 2.7 创建了一个名为 venv_test 的测试 virtualenv,

django
文件夹位于
venv_test/lib/python2.7/site-packages/django
中。


66
投票

最简单的方法可能是

pip3 -V

这将显示您的 pip 安装位置以及您的软件包所在的位置。


31
投票

最安全的方法是通过您正在执行的特定

pip
来调用
python
。如果您直接运行
pip show pip
,它可能会调用与
pip
正在调用的不同的
python
。例子:

$ python -m pip show pip
$ python3 -m pip show pip
$ /usr/bin/python -m pip show pip
$ /usr/local/bin/python3 -m pip show pip

以下示例展示了它们的不同之处:

$ pip show pip

Location: /usr/local/lib/python3.9/site-packages

$ python -m pip show pip

Location: /Library/Python/2.7/site-packages

27
投票

在Python解释器或脚本中,你可以这样做

import site
site.getsitepackages() # List of global package locations

site.getusersitepackages() # String for user-specific package location

对于第三方软件包(不在核心 Python 发行版中)的安装位置。

在我的 macOS 上安装了 Homebrew 的 Python 上,前者输出

['/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages']
,

它规范化为

pip show
输出的相同路径,如之前的答案中所述:

$ readlink -f /usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
/usr/local/lib/python3.7/site-packages

参考:https://docs.python.org/3/library/site.html#site.getsitepackages


25
投票

默认情况下,在 Linux 上,Pip 将软件包安装到 /usr/local/lib/python2.7/dist-packages。

在安装过程中使用 virtualenv 或 --user 将更改此默认位置。如果您使用

pip show
,请确保您使用的是正确的用户,否则
pip
可能看不到您正在引用的包。


13
投票

可以导入包然后查阅其帮助

import statsmodels
help(sm)

帮助的最底部有一个部分

FILE
指示此软件包的安装位置。

此解决方案至少使用 matplotlib (3.1.2) 和 statsmodels (0.11.1) (python 3.8.2) 进行了测试。


9
投票
% python -c "import sysconfig; print(sysconfig.get_path('purelib'))"
/opt/homebrew/lib/python3.11/site-packages
% pip show yt-dlp
Name: yt-dlp
Version: 2023.3.4
Summary: A youtube-dl fork with additional features and patches
Home-page: https://github.com/yt-dlp/yt-dlp
Author:
Author-email:
License:
Location: /opt/homebrew/lib/python3.11/site-packages
Requires: brotli, certifi, mutagen, pycryptodomex, websockets
Required-by:

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

或更短

python -m pip show pip

pip 在哪里安装其软件包?


1
投票

如果您已通过 pip 安装了软件包并在 Windows 上运行代码,则该软件包应位于以下目录之一:

用户站点包:C:\Users\USERNAME\AppData\Roaming\Python\PythonXX\site-packages
全局站点包:C:\Program Files\PythonXX\Lib\site-packages
请注意,“USERNAME”和“XX”将取决于您的系统配置和您使用的 Python 版本。另外,如果您将 Python 安装在与默认位置不同的位置,则路径可能会有所不同。

如果您不确定软件包的安装位置,可以打开命令提示符并输入 pip show 'package-name'。这将显示软件包的安装位置。


0
投票

pip list -v 会给出

除了这个Python程序之外,像这样的程序也对我有用。只是作为替代解决方案

import subprocess


installed_packages = subprocess.check_output(['pip', 'list', '--format=freeze']).decode().split('\n')

print("Installed packages and their locations:")
print("=======================================")

for package in installed_packages:
    if package:
        package_name = package.split('==')[0]
        try:
            package_info = subprocess.check_output(['pip', 'show', package_name]).decode().split('\n')
            for line in package_info:
                if line.startswith('Name:') or line.startswith('Location:'):
                    print(line)
        except subprocess.CalledProcessError as e:
            print(f"Error: Could not find package {package_name}")

print("=======================================")

结果:

Installed packages and their locations:
=======================================
Name: boto3
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: botocore
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: build
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: CacheControl
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: certifi
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: charset-normalizer
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: cleo
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: colorama
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: crashtest
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: distlib
Location: c:\users\ramgh\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: dulwich
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: fastjsonschema
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: filelock
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: idna
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: importlib_metadata
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: importlib_resources
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: installer
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: jaraco.classes
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: jmespath
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: keyring
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: more-itertools
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: msgpack
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: numpy
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: packaging
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: pandas
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: pexpect
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: pip
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: pkginfo
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: platformdirs
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: poetry
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: poetry-core
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: poetry-plugin-export
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: ptyprocess
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: py4j
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: pyproject_hooks
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: pyspark
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: python-dateutil
Location: c:\users\ramgh\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: pytz
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: pywin32-ctypes
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: rapidfuzz
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: requests
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: requests-toolbelt
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: s3transfer
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: shellingham
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: simplejson
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: six
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: sqlglot
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: tomli
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: tomlkit
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: trove-classifiers
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: tzdata
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: urllib3
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: virtualenv
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: zipp
Location: c:\users\\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
=======================================

© www.soinside.com 2019 - 2024. All rights reserved.