简体   繁体   English

pip 冻结不显示所有已安装的包

[英]pip freeze does not show all installed packages

I am using a virtualenv .我正在使用virtualenv I have fabric installed, with pip .我安装了fabric ,带有pip But a pip freeze does not give any hint about that.但是pip freeze并没有给出任何提示。 The package is there, in my virtualenv , but pip is silent about it. package 在我的virtualenv中,但 pip 对此保持沉默。 Why could that be?为什么会这样? Any way to debug this?有什么办法调试这个?

I just tried this myself:我只是自己试过这个:

create a virtualenv in to the "env" directory:在“env”目录中创建一个 virtualenv:

$virtualenv2.7 --distribute env
New python executable in env/bin/python
Installing distribute....done.
Installing pip................done.

next, activate the virtual environment:接下来,激活虚拟环境:

$source env/bin/activate

the prompt changed.提示改变了。 now install fabric:现在安装结构:

(env)$pip install fabric
Downloading/unpacking fabric
  Downloading Fabric-1.6.1.tar.gz (216Kb): 216Kb downloaded
  Running setup.py egg_info for package fabric   
...

Successfully installed fabric paramiko pycrypto
Cleaning up...

And pip freeze shows the correct result: pip freeze显示正确的结果:

(env)$pip freeze
Fabric==1.6.1
distribute==0.6.27
paramiko==1.10.1
pycrypto==2.6
wsgiref==0.1.2

Maybe you forgot to activate the virtual environment?也许您忘记激活虚拟环境? On a *nix console type which pip to find out.在 *nix 控制台类型which pip要找出which pip

Although your problem was specifically due to a typo, to help other users:尽管您的问题是由于拼写错误造成的,但为了帮助其他用户:

pip freeze doesn't show the dependencies that pip depends on. pip freeze不显示 pip 依赖的依赖项。 If you want to obtain all packages you can use pip freeze --all or pip list .如果要获取所有包,可以使用pip freeze --allpip list

您可以尝试使用--all标志,如下所示:

pip freeze --all > requirements.txt

If you have redirected all the pre-installed packages in a file named pip-requirements.txt then it is pretty simple to fix the above issue.如果您已将所有预安装的软件包重定向到名为pip-requirements.txt的文件中,那么解决上述问题非常简单。

1) Delete your virtualenv folder or create new one (I am giving it a name as venv ) 1) 删除您的 virtualenv 文件夹创建一个新文件夹(我将其命名为venv

rm -rf venv && virtualenv venv

2) Install all the requirements / dependencies from the pip-requirements.txt 2) 从pip-requirements.txt安装所有需求/依赖

pip install -r pip-requirements.txt

3) Now you can check the installed packages for your Django application 3) 现在您可以检查 Django 应用程序的已安装包

pip freeze

4) If you had forgotten to update your requirements file( pip-requirements.txt ), then install fabric again ( Optional Step ) 4)如果你忘记更新你的需求文件( pip-requirements.txt ),那么再次安装fabric可选步骤

Note: After installing any dependency for your Django app, always update the requirements in any file as follows (make sure your virtualenv is activated)注意:为您的Django应用程序安装任何依赖项后,请始终按如下方式更新任何文件中的要求(确保您的virtualenv已激活)

pip freeze > pip requirements.txt

That's it.而已。

Adding my fix in addition of above fix also , I was also facing the same issue on windows,even after activating the virtualenv too pip freeze was not giving me all list of installed packages.除了上述修复程序之外,还添加了我的修复程序,我在 Windows 上也遇到了同样的问题,即使在激活 virtualenv 之后pip freeze也没有给我所有已安装软件包的列表。 So i upgraded my pip with python -m pip install --upgrade pip command and then used pip freeze .所以我用python -m pip install --upgrade pip命令升级了我的 pip,然后使用了pip freeze This time it worked and gave me all list of installed packages.这次它起作用了,并给了我所有已安装软件包的列表。

If none of the above answers are working for you.如果以上答案都不适合您。 As with me you might have problem in you venv and pip configuration.和我一样,你的 venv 和 pip 配置可能有问题。

Go inside your venv/bin and open pip and see the 2nd line as: '''exec' "path/to/yourvenv/bin/python3" "$0" "$@"进入你的 venv/bin 并打开 pip 并看到第二行: '''exec' "path/to/yourvenv/bin/python3" "$0" "$@"

See if this line is correctly pointing inside your venv or not For example in my case.看看这条线是否正确指向你的 venv 内部例如在我的情况下。 I initially named my virtual environment as venv1 and later just renamed it to venv2.我最初将我的虚拟环境命名为 venv1,后来只是将其重命名为 venv2。 In doing so my pip file 2nd line had: '''exec' "venv1/bin/python3" "$0" "$@" which to work properly should have: '''exec' "venv2/bin/python3" "$0" "$@" notice "venv2" not "venv1" since venv1 in now renamed to venv2.这样做时,我的 pip 文件第二行有: '''exec' "venv1/bin/python3" "$0" "$@"正常工作应该有: '''exec' "venv2/bin/python3" "$0 " "$@"注意"venv2"而不是"venv1",因为 venv1 现在更名为 venv2。

Due to this python was looking inside pip of venv2 and throwing error or not working as desired.由于这个 python 正在查看 venv2 的 pip 并抛出错误或无法按预期工作。

For those who added Python modules via PyCharm IDE, after generating a virtual environment from the command prompt, good luck.对于那些通过 PyCharm IDE 添加 Python 模块的人,在从命令提示符生成虚拟环境后,祝你好运。 You will need to rebuild the requirements.txt file manually with the ones missing by first running pip3 freeze and adding what is missing from PyCharm.您将需要通过首先运行 pip3 freeze 并添加 PyCharm 中缺少的内容来手动重建 requirements.txt 文件。

I highly suggest switching to Visual Studio Code.我强烈建议切换到 Visual Studio Code。

This might be stupid but I have got the same problem.这可能很愚蠢,但我遇到了同样的问题。 I solved it by refreshing vs code file directory (inside vscode there is a reload button).我通过刷新 vs 代码文件目录来解决它(在 vscode 里面有一个重新加载按钮)。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM