标签归档:pip

pip安装中“ X的构建车轮失败”是什么意思?

问题:pip安装中“ X的构建车轮失败”是什么意思?

在SO上,这是一个真正流行的问题,但是我看过的所有答案中,没有一个能清楚地说明此错误的真正含义以及发生的原因。

造成混乱的原因之一是,当您(例如)这样做时pip install pycparser,您首先会得到以下错误:

Failed building wheel for pycparser

然后出现以下消息,说明该软件包是:

Successfully installed pycparser-2.19


# pip3 install pycparser

Collecting pycparser
  Using cached https://files.pythonhosted.org/packages/68/9e/49196946aee219aead1290e00d1e7fdeab8567783e83e1b9ab5585e6206a/pycparser-2.19.tar.gz
Building wheels for collected packages: pycparser
  Running setup.py bdist_wheel for pycparser ... error
  Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-g_v28hpp/pycparser/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-__w_f6p0 --python-tag cp36:
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    ...
    File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2349, in resolve
      module = __import__(self.module_name, fromlist=['__name__'], level=0)
  ModuleNotFoundError: No module named 'wheel.bdist_wheel'

  ----------------------------------------
  Failed building wheel for pycparser
  Running setup.py clean for pycparser
Failed to build pycparser
Installing collected packages: pycparser
  Running setup.py install for pycparser ... done
Successfully installed pycparser-2.19

这里发生了什么?

(我想了解如何发生某些故障但仍然可以安装,以及是否可以信任此软件包正常运行?)

到目前为止,我已经找到了最好的部分原因是这个

This is a truly popular question here at SO, but none of the many answers I have looked at, clearly explain what this error really mean, and why it occurs.

One source of confusion, is that when (for example) you do pip install pycparser, you first get the error:

Failed building wheel for pycparser

which is then followed by the message that the package was:

Successfully installed pycparser-2.19.


# pip3 install pycparser

Collecting pycparser
  Using cached https://files.pythonhosted.org/packages/68/9e/49196946aee219aead1290e00d1e7fdeab8567783e83e1b9ab5585e6206a/pycparser-2.19.tar.gz
Building wheels for collected packages: pycparser
  Running setup.py bdist_wheel for pycparser ... error
  Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-g_v28hpp/pycparser/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-__w_f6p0 --python-tag cp36:
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    ...
    File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2349, in resolve
      module = __import__(self.module_name, fromlist=['__name__'], level=0)
  ModuleNotFoundError: No module named 'wheel.bdist_wheel'

  ----------------------------------------
  Failed building wheel for pycparser
  Running setup.py clean for pycparser
Failed to build pycparser
Installing collected packages: pycparser
  Running setup.py install for pycparser ... done
Successfully installed pycparser-2.19

What is going on here?

(I would like to understand how something can fail but still get installed and whether you can trust this package functioning correctly?)

So far the best partial explanation I have found is this.


回答 0

(这里是点子维护者!)

如果包装不是车轮,则pip尝试为其构建一个车轮(通过setup.py bdist_wheel)。如果由于任何原因导致安装失败,您将收到“ pycparser的建筑轮子故障”消息,并且pip退回到直接安装(通过setup.py install)。

装好轮子后,pip可以通过正确打开包装来安装轮子。pip尝试尽可能多地通过轮子安装软件包。这是由于使用滚轮的各种优势(例如更快的安装,可缓存的,不再执行代码等)。


您在这里的错误消息是由于wheel缺少软件包,其中包含构建轮子所需的逻辑setup.py bdist_wheel。(pip install wheel可以解决该问题。)


以上是当前默认的旧行为;我们会默认在将来的某个时间切换到PEP 517,为此我们将转到基于标准的流程。我们还为此提供了隔离的版本,因此,默认情况下,您会在这些环境中安装滚轮。:)

(pip maintainer here!)

If the package is not a wheel, pip tries to build a wheel for it (via setup.py bdist_wheel). If that fails for any reason, you get the “Failed building wheel for pycparser” message and pip falls back to installing directly (via setup.py install).

Once we have a wheel, pip can install the wheel by unpacking it correctly. pip tries to install packages via wheels as often as it can. This is because of various advantages of using wheels (like faster installs, cache-able, not executing code again etc).


Your error message here is due to the wheel package being missing, which contains the logic required to build the wheels in setup.py bdist_wheel. (pip install wheel can fix that.)


The above is the legacy behavior that is currently the default; we’ll switch to PEP 517 by default, sometime in the future, moving us to a standards-based process for this. We also have isolated builds for that so, you’d have wheel installed in those environments by default. :)


回答 1

昨天,我遇到了同样的错误: Failed building wheel for hddfancontrol跑步时pip3 install hddfancontrol。结果是Failed to build hddfancontrol。原因是error: invalid command 'bdist_wheel'Running setup.py bdist_wheel for hddfancontrol ... error。通过运行以下命令修复了该错误:

 pip3 install wheel

(从这里开始。)

另外,也可以从此处直接下载“ wheel” 。下载后,可以通过运行以下命令进行安装:

pip3 install "/the/file_path/to/wheel-0.32.3-py2.py3-none-any.whl"

Yesterday, I got the same error: Failed building wheel for hddfancontrol when I ran pip3 install hddfancontrol. The result was Failed to build hddfancontrol. The cause was error: invalid command 'bdist_wheel' and Running setup.py bdist_wheel for hddfancontrol ... error. The error was fixed by running the following:

 pip3 install wheel

(From here.)

Alternatively, the “wheel” can be downloaded directly from here. When downloaded, it can be installed by running the following:

pip3 install "/the/file_path/to/wheel-0.32.3-py2.py3-none-any.whl"

回答 2

从那以后,似乎没有人提到我自己。我自己解决上述问题是最常见的,以确保禁用缓存使用副本:pip install <package> --no-cache-dir

Since, nobody seem to mention this apart myself. My own solution to the above problem is most often to make sure to disable the cached copy by using: pip install <package> --no-cache-dir.


回答 3

从程序包部署的角度解决此问题可能会有所帮助。

那里有许多教程介绍了如何将程序包发布到PyPi。以下是我使用过的几对;

中型
真正的python

我的经验是,这些教程大多数都只使用源代码的.tar,而不使用转盘。因此,在安装使用这些教程创建的软件包时,我收到了“无法构建轮子”错误。

后来我在PyPi上找到了指向Python软件基金会的文档PSF Docs的链接。我发现它们的设置和构建过程略有不同,并且确实包括构建wheel文件。

使用正式记录的方法后,安装软件包时不再收到错误。

因此,错误可能只是开发人员如何打包和部署项目的问题。我们当中没有一个人天生就知道如何使用PyPi,如果它们是在错误的教程上发生的,那么您可以填补空白。

我敢肯定这不是错误的唯一原因,但我敢打赌这是主要原因。

It might be helpful to address this question from a package deployment perspective.

There are many tutorials out there that explain how to publish a package to PyPi. Below are a couple I have used;

medium
real python

My experience is that most of these tutorials only have you use the .tar of the source, not a wheel. Thus, when installing packages created using these tutorials, I’ve received the “Failed to build wheel” error.

I later found the link on PyPi to the Python Software Foundation’s docs PSF Docs. I discovered that their setup and build process is slightly different, and does indeed included building a wheel file.

After using the officially documented method, I no longer received the error when installing my packages.

So, the error might simply be a matter of how the developer packaged and deployed the project. None of us were born knowing how to use PyPi, and if they happened upon the wrong tutorial — well, you can fill in the blanks.

I’m sure that is not the only reason for the error, but I’m willing to bet that is a major reason for it.


回答 4

试试这个:

sudo apt-get install libpcap-dev libpq-dev

当我安装了这两个时,它对我有用。

有关更多信息,请参见此处的链接。

Try this:

sudo apt-get install libpcap-dev libpq-dev

It has worked for me when I have installed these two.

See the link here for more information


回答 5

在Ubuntu 18.04上,我遇到了此问题,因为的apt软件包wheel不包含wheel命令。我认为pip尝试导入wheelpython包,如果成功,则假定wheel命令也可用。Ubuntu打破了这一假设。

apt python3代码包的名称为python3-wheel。这是自动安装的,因为python3-pip建议您这样做。

apt python3 wheel命令包的名称为python-wheel-common。安装此工具也可以为我解决“建筑轮子故障”错误。

On Ubuntu 18.04, I ran into this issue because the apt package for wheel does not include the wheel command. I think pip tries to import the wheel python package, and if that succeeds assumes that the wheel command is also available. Ubuntu breaks that assumption.

The apt python3 code package is named python3-wheel. This is installed automatically because python3-pip recommends it.

The apt python3 wheel command package is named python-wheel-common. Installing this too fixes the “failed building wheel” errors for me.


回答 6

当我尝试安装pip install django-imagekit时,出现了相同的消息。因此,我运行了pip install wheel(我安装了python 2.7),然后重新运行了pip install django-imagekit,它开始工作了。谢谢

I got the same message when I tried to install pip install django-imagekit. So I ran pip install wheel (I had python 2.7) and then I reran pip install django-imagekit and it worked. Thanks


回答 7

我想补充一点,如果您的系统上只有Python3,则需要开始使用pip3而不是pip。

您可以使用以下命令安装pip3;

sudo apt install python3-pip -y

之后,您可以尝试安装所需的软件包。

sudo pip3 install <package>

I would like to add that if you only have Python3 on your system then you need to start using pip3 instead of pip.

You can install pip3 using the following command;

sudo apt install python3-pip -y

After this you can try to install the package you need with;

sudo pip3 install <package>

回答 8

错误:

系统:AWS EC2实例(T2小)

问题:通过安装opencv python时

pip3 install opencv-python

  Problem with the CMake installation, aborting build. CMake executable is cmake
  
  ----------------------------------------
  Failed building wheel for opencv-python
  Running setup.py clean for opencv-python

什么对我有用

pip3 install --upgrade pip setuptools wheel

在此之后,您仍然可能会收到休闲错误错误

    from .cv2 import *
ImportError: libGL.so.1: cannot open shared object file: No such file or directory

安装libgl为我解决了错误。

sudo apt update
sudo apt install libgl1-mesa-glx

希望这可以帮助

Error :

System : aws ec2 instance (t2 small)

issue : while installing opencv python via

pip3 install opencv-python

  Problem with the CMake installation, aborting build. CMake executable is cmake
  
  ----------------------------------------
  Failed building wheel for opencv-python
  Running setup.py clean for opencv-python

What worked for me

pip3 install --upgrade pip setuptools wheel

After this you still might received fallowing error error

    from .cv2 import *
ImportError: libGL.so.1: cannot open shared object file: No such file or directory

Installing libgl solved the error for me.

sudo apt update
sudo apt install libgl1-mesa-glx

Hope this helps


回答 9

安装Brotli时遇到相同的问题

错误

Failed building wheel for Brotli

我通过.whl此处下载文件 并使用以下命令进行安装来解决了该问题

C:\Users\{user_name}\Downloads>pip install Brotli-1.0.9-cp39-cp39-win_amd64.whl

I had the same problem while installing Brotli

ERROR

Failed building wheel for Brotli

I solved it by downloading the .whl file from here and installing it using the below command

C:\Users\{user_name}\Downloads>pip install Brotli-1.0.9-cp39-cp39-win_amd64.whl

回答 10

这可能对您有帮助!….

卸载pycparser:

pip uninstall pycparser

重新安装pycparser:

pip install pycparser

我在安装termcolor时遇到了同样的错误,并通过重新安装进行了修复。

This may Help you ! ….

Uninstalling pycparser:

pip uninstall pycparser

Reinstall pycparser:

pip install pycparser

I got same error while installing termcolor and I fixed it by reinstalling it .


点缓存文件夹在哪里

问题:点缓存文件夹在哪里

Python pip缓存文件夹在哪里?我在安装过程中出错,现在使用缓存文件重新安装软件包

该目录在哪里?我想备份它们以便将来安装。可能吗 ?

例如我有一个:

Using cached cssselect-0.9.1.tar.gz

我在google中搜索了此目录,但是我看到的所有内容都是从文件夹中了解如何安装,我想找到默认的缓存目录。

还有一个问题,这些缓存文件将保留在该目录中还是将很快删除?

Where is Python pip cache folder? I had error during install and now reinstall packages using cache files

Where is that directory? I want backup them for install in the future. Is it possible ?

For example I have this one :

Using cached cssselect-0.9.1.tar.gz

I searched google for this directory but anything I saw, is learn to how install from a folder, I want to find default cache directory.

And another question, these cache files will stay in that directory or will remove soon ?


回答 0

这取决于操作系统。

对于pip 20.1或更高版本,您可以通过以下方式找到它:

pip cache dir

例如,对于macOS:

$ pip cache dir
/Users/hugo/Library/Caches/pip

文件:

It depends on the operating system.

With pip 20.1 or later, you can find it with:

pip cache dir

For example with macOS:

$ pip cache dir
/Users/hugo/Library/Caches/pip

Docs:


回答 1

缓存目录的默认位置取决于操作系统:

的Unix

〜/ .cache / pip,它尊重XDG_CACHE_HOME目录。

苹果系统

〜/库/缓存/点

视窗

<CSIDL_LOCAL_APPDATA> \ pip \ Cache

车轮缓存

pip将从pip缓存目录内的子目录轮读取并使用在那里找到的所有软件包。[片段]

https://pip.pypa.io/zh_CN/latest/reference/pip_install/#caching

可以通过命令行选项更改缓存目录的位置--cache-dir

The default location for the cache directory depends on the Operating System:

Unix

~/.cache/pip and it respects the XDG_CACHE_HOME directory.

macOS

~/Library/Caches/pip

Windows

<CSIDL_LOCAL_APPDATA>\pip\Cache

Wheel Cache

pip will read from the subdirectory wheels within the pip cache directory and use any packages found there. [snip]

https://pip.pypa.io/en/latest/reference/pip_install/#caching

The location of the cache directory can be changed via the command line option --cache-dir.


回答 2

Pythonic和跨平台方式:

import pip
from distutils.version import LooseVersion

if LooseVersion(pip.__version__) < LooseVersion('10'):
    # older pip version
    from pip.utils.appdirs import user_cache_dir
else:
    # newer pip version
    from pip._internal.utils.appdirs import user_cache_dir

print(user_cache_dir('pip'))
print(user_cache_dir('wheel'))

在后台,它可以规范化路径,为奇异的和普通的操作系统和平台管理不同的位置,执行Windows注册表查找。

值得一提的是,如果安装了不同的Python版本2.x和3.x,它们确实共享相同的缓存位置。

Pythonic and cross-platform way:

import pip
from distutils.version import LooseVersion

if LooseVersion(pip.__version__) < LooseVersion('10'):
    # older pip version
    from pip.utils.appdirs import user_cache_dir
else:
    # newer pip version
    from pip._internal.utils.appdirs import user_cache_dir

print(user_cache_dir('pip'))
print(user_cache_dir('wheel'))

Under the hood, it normalizes paths, manages different locations for exotic and ordinary operating systems and platforms, performs Windows registry lookup.

It may worth mentioning, if you have different Python versions installed, 2.x’es and 3.x’es, they all do share the same cache location.


回答 3

您可以备份关联的滚轮,而不必尝试执行缓存文件夹的备份。

将版本0.9.1的csselect的滚轮下载到/tmp/wheelhouse

pip wheel --wheel-dir=/tmp/wheelhouse cssselect==0.9.1

安装下载的车轮:

pip install /tmp/wheelhouse/cssselect-0.9.1-py2-none-any.whl

You can backup the associated wheel rather than attempting to perform a backup of the cache folder.

Download the wheel for csselect of version 0.9.1 into /tmp/wheelhouse:

pip wheel --wheel-dir=/tmp/wheelhouse cssselect==0.9.1

Install the downloaded wheel:

pip install /tmp/wheelhouse/cssselect-0.9.1-py2-none-any.whl

如何在Python 3.6上安装PIP?

问题:如何在Python 3.6上安装PIP?

我正在尝试为python 3.6安装PIP,并查看了YouTube上的教程,但它们似乎都已过时,而且似乎都没有用。任何信息都会有所帮助,因此我可以继续进行我的项目。

I’m trying to Install PIP for python 3.6 and I’ve looked over YouTube for tutorials but all of them seem to be out of date and none of them have seemed to work. Any information would be helpful so I can carry on with my project.


回答 0

pip 与Python> 3.4捆绑在一起

在类Unix系统上使用:

python3.6 -m pip install [Package_to_install]

在Windows系统上,请使用:

py -m pip install [Package_to_install]

(在Windows上,您可能需要以管理员身份运行命令提示符才能写入python安装目录)

pip is bundled with Python > 3.4

On Unix-like systems use:

python3.6 -m pip install [Package_to_install]

On a Windows system use:

py -m pip install [Package_to_install]

(On Windows you may need to run the command prompt as administrator to be able to write into python installation directory)


回答 1

下载python 3.6

默认情况下,可能未安装pip。一种可能的解决方法是打开cmd并键入:

python -m ensurepip --default-pip

然后

python -m pip install matplotlib

实际上,我的脚本文件夹idk中什么都没有,但是为什么这些步骤对我有用。

Download python 3.6

It is possible that pip does not get installed by default. One potential fix is to open cmd and type:

python -m ensurepip --default-pip

and then

python -m pip install matplotlib

actually i had nothing in my scripts folder idk why but these steps worked for me.


回答 2

如果您的python 3.6安装未附带pip,则可以使用:

wget https://bootstrap.pypa.io/get-pip.py
sudo python3.6 get-pip.py

那么你可以python -m安装

If pip doesn’t come with your installation of python 3.6, this may work:

wget https://bootstrap.pypa.io/get-pip.py
sudo python3.6 get-pip.py

then you can python -m install


回答 3

pip包含在Python安装中。如果您无法调用pip.exe,请尝试从cmd调用python -m pip [args]

pip is included in Python installation. If you can’t call pip.exe try calling python -m pip [args] from cmd


回答 4

您是如何安装Python的,并且您正在使用虚拟环境?
正如您特别提到的Python 3.6,并且您尚未将其标记为已回答,我猜测您可能已使用sudo add-apt-repository ppa:jonathonf / python-3.6安装了它,因为这是安装Python的一种常见方法在没有本机3.6软件包的Unix OS上使用3.6。如果是这种情况,则正确安装pip的方法如下….

步骤1)使用Python 3.6建立虚拟环境…

python3.6 -m venv env --without-pip

步骤2)激活您的虚拟环境…

source env/bin/activate

步骤3)将pip安装到您的环境中…

curl https://bootstrap.pypa.io/get-pip.py | python3

How did you install Python, and are you using a virtual environment?
As you specifically mentioned Python 3.6, and you have not marked this as answered I will make a guess that you might have installed it using sudo add-apt-repository ppa:jonathonf/python-3.6, as this is a common way to install Python 3.6 on a Unix OS that doesn’t have a native 3.6 package. If this is the case the correct way to install pip is as follows ….

Step 1) Make a Virtual Environment with Python 3.6 …

python3.6 -m venv env --without-pip

Step 2) Activate your virtual environemnt …

source env/bin/activate

Step 3) Install pip into your environemnt …

curl https://bootstrap.pypa.io/get-pip.py | python3

回答 5

我在Centos 7中使用了这些命令

yum install python36
yum install python36-devel
yum install python36-pip
yum install python36-setuptools
easy_install-3.6 pip

检查点子版本:

pip3 -V
pip 18.0 from /usr/local/lib/python3.6/site-packages/pip-18.0-py3.6.egg/pip (python 3.6)

I Used these commands in Centos 7

yum install python36
yum install python36-devel
yum install python36-pip
yum install python36-setuptools
easy_install-3.6 pip

to check the pip version:

pip3 -V
pip 18.0 from /usr/local/lib/python3.6/site-packages/pip-18.0-py3.6.egg/pip (python 3.6)

回答 6

在某些情况下,您pip不会随着python安装一起下载。即使您的整个脚本文件夹也可以为空。

您也可以手动进行操作。

只需转到命令提示符,然后python -m ensurepip --default-pip按Enter。

确保路径变量的值已更新。

这会做把戏

There are situations when your pip doesn’t get downloaded along with python installation. Even your whole script folder can be empty.

You can do so manually as well.

Just head to Command Prompt and type python -m ensurepip --default-pip Press Enter.

Make sure that value of path variable is updated.

This will do the Trick


回答 7

由于python 3.4 pip包含在python的安装中。

Since python 3.4 pip is included in the installation of python.


回答 8

下载和安装Python 3.6时出现问题。取消选中安装中的pip可以避免此问题。因此,并非每次安装都提供pip。

There is an issue with downloading and installing Python 3.6. Unchecking pip in the installation prevents the issue. So pip is not given in every installation.


回答 9

我现在在Windows上用python 3.6.3安装bs4。

C:\yourfolderx\yourfoldery>python.exe -m pip install bs4

语法类似于下面的用户帖子:

我刚刚成功安装了excel软件包。安装python 3.6之后,您必须下载所需的软件包,然后进行安装。例如

python.exe -m pip download openpyxl==2.1.4

python.exe -m pip install openpyxl==2.1.4

I have in this moment install the bs4 with python 3.6.3 on Windows.

C:\yourfolderx\yourfoldery>python.exe -m pip install bs4

with the syntax like the user post below:

I just successfully installed a package for excel. After installing the python 3.6, you have to download the desired package, then install. For eg,

python.exe -m pip download openpyxl==2.1.4

python.exe -m pip install openpyxl==2.1.4

回答 10

我刚刚成功安装了excel软件包。安装后python 3.6,您必须下载所需的软件包,然后进行安装。例如

  1. python.exe -m pip download openpyxl==2.1.4

  2. python.exe -m pip install openpyxl==2.1.4

I just successfully installed a package for excel. After installing the python 3.6, you have to download the desired package, then install. For eg,

  1. python.exe -m pip download openpyxl==2.1.4

  2. python.exe -m pip install openpyxl==2.1.4


回答 11

是的,Python3.6安装了PIP,但由于已安装,因此无法访问。没有代码可以直接调用它!我已经呆了一个多星期了,我读了给出的每条建议,都没有成功!

最后,我测试了转到pip目录并升级已安装的版本:

root@bx:/usr/local/lib/python3.6/site-packages # python -m pip install --upgrade pip

该命令创建了一个PIP,该PIP现在可以在FreeBSD服务器上的任何位置正常工作!

显然,所安装的工具根本无法正常工作,就像Python3.6一样。运行它们的唯一方法是调用Python和所需的python文件,如您在发出的命令中所见。但是,一旦调用了更新,新的PIP就可以在全局范围内工作,而不必调用Python3.6 …

Yes, Python3.6 installs PIP but it is unreachable as it is installed. There is no code which will invoke it as it is! I have been at it for more than a week and I read every single advice given, without success!

Finally, I tested going to the pip directory and upgrading the installed version:

root@bx:/usr/local/lib/python3.6/site-packages # python -m pip install --upgrade pip

That command created a PIP which now works properly from any location on my FreeBSD server!

Clearly, the tools installed simply do not work, as installed with Python3.6. The only way to run them is to invoke Python and the desired python files as you can see in the command issued. Once the update is called, however, the new PIP works globally without having to invoke Python3.6…


回答 12

这在Amazon Linux上对我有用

sudo yum list | grep python3

须藤百胜安装python36.x86_64 python36-tools.x86_64

$ python3-版本Python 3.6.8

$ pip -V pip 9.0.3来自/usr/lib/python2.7/dist-packages(python 2.7)

] $ sudo python3.6 -m pip install –upgrade pip收集pip下载https://files.pythonhosted.org/packages/d8/f3/413bab4ff08e1fc4828dfc59996d721917df8e8583ea85385d51125dceff/pip-19.0.3-py2.py3-none-any.whl(1.4MB)100%|█████████████████████████████████| 1.4MB 969kB / s安装收集的软件包:pip找到现有安装:pip 9.0.3卸载pip-9.0.3:成功卸载pip-9.0.3成功安装pip-19.0.3

$ pip -V pip 19.0.3来自/usr/local/lib/python3.6/site-packages/pip(python 3.6)

This what worked for me on Amazon Linux

sudo yum list | grep python3

sudo yum install python36.x86_64 python36-tools.x86_64

$ python3 –version Python 3.6.8

$ pip -V pip 9.0.3 from /usr/lib/python2.7/dist-packages (python 2.7)

]$ sudo python3.6 -m pip install –upgrade pip Collecting pip Downloading https://files.pythonhosted.org/packages/d8/f3/413bab4ff08e1fc4828dfc59996d721917df8e8583ea85385d51125dceff/pip-19.0.3-py2.py3-none-any.whl (1.4MB) 100% |████████████████████████████████| 1.4MB 969kB/s Installing collected packages: pip Found existing installation: pip 9.0.3 Uninstalling pip-9.0.3: Successfully uninstalled pip-9.0.3 Successfully installed pip-19.0.3

$ pip -V pip 19.0.3 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)


回答 13

对于python3,应该是pip3

在ubuntu上

sudo apt install python3-pip

For python3 it should be pip3

on ubuntu

sudo apt install python3-pip

pip:没有名为_internal的模块

问题:pip:没有名为_internal的模块

我尝试以任何方式使用pip时遇到问题。我正在使用Ubuntu 16.04.4

我应该说我已经使用过它,并且从未遇到任何问题,但是从今天开始,当我使用任何命令时,我总是会遇到相同的错误(例如使用的示例pip --upgrade)。

Traceback (most recent call last):
  File "/usr/local/bin/pip", line 7, in <module>
    from pip._internal import main
ImportError: No module named _internal

我尝试了sudo apt-get remove python-pip之后,sudo apt-get install python-pip但没有任何改变。

I have a problem when I try to use pip in any way. I’m using Ubuntu 16.04.4

I should say that I’ve used it already, and I never had any problem, but starting today when I use any command I always get the same error (as an example using pip --upgrade).

Traceback (most recent call last):
  File "/usr/local/bin/pip", line 7, in <module>
    from pip._internal import main
ImportError: No module named _internal

I have tried doing sudo apt-get remove python-pip followed by sudo apt-get install python-pip but nothing changed.


回答 0

这为我做到了:

python -m pip install --upgrade pip

环境:通过brew安装OSX && Python

This did it for me:

python -m pip install --upgrade pip

Environment: OSX && Python installed via brew


回答 1

askUbuntu的回答有效。

对于pip2.7,您可以首先安装curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py,然后python2.7 get-pip.py --force-reinstall重新安装pip。

问题解决了。也适用于python3。

An answer from askUbuntu works.

For pip2.7, you can at first curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py, then python2.7 get-pip.py --force-reinstall to reinstall pip.

Problem solved. Also works for python3.


回答 2

此解决方案适用于我:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall

或使用sudo获得更高的权限(sudo python3 get-pip.py --force-reinstall)。

当然,您也可以使用python代替python3;)

资源

This solution works for me:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall

or use sudo for elevated permissions (sudo python3 get-pip.py --force-reinstall).

Of course, you can also use python instead of python3 ;)

Source


回答 3

请参阅此问题列表

sudo easy_install pip

在Mac OS下为我工作

对于python3,可以尝试sudo easy_install-3.x pip取决于python 3.x版本。要么python3 -m pip install --user --upgrade pip

Refer to this issue list

sudo easy_install pip

works for me under Mac OS

For python3, may try sudo easy_install-3.x pip depends on the python 3.x version. Or python3 -m pip install --user --upgrade pip


回答 4

在文件“ / usr / local / bin / pip”中更改 from pip._internal import mainfrom pip import main

In file “/usr/local/bin/pip” change from pip._internal import main to from pip import main


回答 5

此问题可能是由于普通用户没有访问软件包py文件的特权。
1. root用户可以运行“ pip list”
2.其他普通用户不能运行“ pip list”

[~]$ pip list
Traceback (most recent call last):
  File "/usr/bin/pip", line 7, in <module>
from pip._internal import main
ImportError: No module named pip._internal

检查pip py文件特权。

[root@]# ll /usr/lib/python2.7/site-packages/pip/  
合計 24  
-rw-------  1 root root   24  6  7 16:57 __init__.py  
-rw-------  1 root root  163  6  7 16:57 __init__.pyc  
-rw-------  1 root root  629  6  7 16:57 __main__.py  
-rw-------  1 root root  510  6  7 16:57 __main__.pyc  
drwx------  8 root root 4096  6  7 16:57 _internal  
drwx------ 18 root root 4096  6  7 16:57 _vendor  

解决方案:root用户登录并运行

chmod -R 755 /usr/lib/python2.7 

解决此问题。

This issue maybe due to common user do not have privilege to access packages py file.
1. root user can run ‘pip list’
2. other common user cannot run ‘pip list’

[~]$ pip list
Traceback (most recent call last):
  File "/usr/bin/pip", line 7, in <module>
from pip._internal import main
ImportError: No module named pip._internal

Check pip py file privilege.

[root@]# ll /usr/lib/python2.7/site-packages/pip/  
合計 24  
-rw-------  1 root root   24  6月  7 16:57 __init__.py  
-rw-------  1 root root  163  6月  7 16:57 __init__.pyc  
-rw-------  1 root root  629  6月  7 16:57 __main__.py  
-rw-------  1 root root  510  6月  7 16:57 __main__.pyc  
drwx------  8 root root 4096  6月  7 16:57 _internal  
drwx------ 18 root root 4096  6月  7 16:57 _vendor  

solution : root user login and run

chmod -R 755 /usr/lib/python2.7 

fix this issue.


回答 6

为了完整起见,我刚遇到了“ Ubuntu Latest”问题……v18.04 …,并通过以下方式解决了该问题:

python3 -m pip install --upgrade pip

(注意,必须指定,python3因为它引用了Python 3.6.9。python同一系统上的命令引用了Python 2.7.17。由于这显然是系统范围的安装,因此它遇到了[“ not sudo” …]权限。错误,但这没关系,因为无论如何都是错的。我遇到了pip3。)问题。

For completeness, I just encountered this problem with “Ubuntu latest” … v18.04 … and fixed it in this way:

python3 -m pip install --upgrade pip

(Notice that it was necessary to specify python3 since this references Python 3.6.9. The python command on the same system references Python 2.7.17. Since this is apparently a system-wide installation it encountered a [“not sudo” …] permission error, but it didn’t matter because it was the wrong thing to do anyway. I was encountering the problem with pip3.)


回答 7

PYTHONPATH设置为包含内置site-packages目录时,我已经看到了此问题。由于Python自动出现在那儿,因此没有必要,可以将其删除。

I’ve seen this issue when PYTHONPATH was set to include the built-in site-packages directory. Since Python looks there automatically it is unnecessary and can be removed.


回答 8

我只是遇到了同样的问题,以我为例,事实证明这是我的virtualenv中的python安装与站点范围的python(Ubuntu)之间的冲突。为我解决的是以这种方式运行pip,以强制使用正确的python安装(在我的vortualenv中):

python3 -m pip install PACKAGE

代替

pip3 install PACKAGE

当我尝试遵循一些建议重新安装pip的答案时,我意识到了这一点,尽管我已经激活了virtualenv,但我收到的错误输出却指向现有的站点范围内的python库路径。值得一试,然后再删除并重新安装东西。

I just encountered the same problem and in my case, it turns out this is a conflict between the python installation in my virtualenv and the site-wide python (Ubuntu). What solves it for me is to run pip in this way, to force usage of the correct python installation (in my vortualenv):

python3 -m pip install PACKAGE

instead of

pip3 install PACKAGE

I realised this when I tried to follow some of the answers here that suggest re-installing pip and the error output I got was pointing to an existing site-wide python library path although I had activated my virtualenv. Worth trying before deleting and re-installing stuff.


回答 9

您使用的是python2还是python3?以下命令可能有所不同!

  1. 用于python3 -m pip --version查看是否已安装pip。
  2. 如果是,请运行python3 -m pip install --upgrade pip
  3. 如果否,请运行sudo apt-get install python3-pip,然后再次执行。

Are you using python2 or python3? The following command could be different!

  1. use python3 -m pip --version to see if you have pip installed.
  2. if yes, run python3 -m pip install --upgrade pip.
  3. if no, run sudo apt-get install python3-pip, and do it again.

回答 10

它可能是由于版本冲突所致,请尝试运行此命令,它将以某种方式删除较旧的点。

sudo apt remove python pip

Its probably due to a version conflict, try to run this, it will remove the older pip somehow.

sudo apt remove python pip

回答 11

为了我

python -m pip uninstall pip

解决了这个问题。参考

For me

python -m pip uninstall pip

solved the issue. Reference


回答 12

我通过运行以下命令解决了此错误:

sudo apt remove python-pip
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py

它将删除先前安装的pip并重新安装。谢谢 :)

I have fixed this error by running the following commands:

sudo apt remove python-pip
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py

It will remove the previously installed pip and reinstall it. Thanks :)


回答 13

以下解决方案在我的机器上为python2.7解决了问题:“ $ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py”,然后是“ $ sudo python2.7 get-pip .py –force-reinstall“

The following solution solved the problem on my machine for python2.7 “$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py” and then “$ sudo python2.7 get-pip.py –force-reinstall”


回答 14

仅对于当前用户:

easy_install --user pip

要么

python -m pip install --upgrade --user pip

第二个可能会给出/usr/bin/python: No module named pip 即使which pip找到名为pip的模块。在这种情况下,请尝试easy_install

For the current user only:

easy_install --user pip

or

python -m pip install --upgrade --user pip

The second may give /usr/bin/python: No module named pip Even if which pip finds the module named pip. In this case try the easy_install


回答 15

当我尝试通过pip3安装软件包时,在Windows上遇到了相同的错误:

Traceback (most recent call last):
  File "d:\anaconda\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "d:\anaconda\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\Anaconda\Scripts\pip3.6.exe\__main__.py", line 5, in <module>
ModuleNotFoundError: No module named 'pip._internal'

我的python是通过Anaconda安装的。我通过conda重新安装pip解决了这个问题:

conda install pip

之后,pip恢复正常。

I met the same error on Windows when I tried to install a package via pip3:

Traceback (most recent call last):
  File "d:\anaconda\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "d:\anaconda\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\Anaconda\Scripts\pip3.6.exe\__main__.py", line 5, in <module>
ModuleNotFoundError: No module named 'pip._internal'

My python is installed via Anaconda. I solved this issue by reinstalling pip via conda:

conda install pip

After that, pip returns to normal.


回答 16

什么都没有对我有用,但只有一件事:我在命令前使用了sudo,它工作正常。

Nothing worked for me, but only one thing: I used sudo in front of the command and it is working fine.


回答 17

在将python安装从3.6升级到3.7后,我在虚拟环境中存在相同的问题,但仅在vent全局pip上可以正常工作,要解决此问题,请在重新创建后停用并删除我的虚拟环境,现在在venv上可以了:

deactivate
rm -rvf venv 

然后重新创建虚拟环境。我使用mac OS 10.11和python 3

I have the same problem on my virtual environment after upgrade python installation from 3.6 to 3.7 but only on vent globally pip work fine, to solve it I deactivate and delete my virtual environment after recreate again and now is fine, on venv:

deactivate
rm -rvf venv 

and after recreate the virtual environment. I use mac OS 10.11, and python 3


回答 18

(在Windows上)不确定为什么会这样,但是我的PYTHONPATH设置指向安装了python的c:\ python27。与virtualenv结合使用会产生上述错误。

通过一起删除PYTHONPATH env var来解决

(On windows) not sure why this was happening but I had my PYTHONPATH setup to point to c:\python27 where python was installed. in combination with virtualenv this produced the mentioned bug.

resolved by removing the PYTHONPATH env var all together


回答 19

我的解决方案:像大多数其他答案一样的第一步:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python2.7 get-pip.py --force-reinstall

第二,添加软链接

sudo ln -s /usr/local/bin/pip /usr/bin/pip

my solution: first step like most other answer:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python2.7 get-pip.py --force-reinstall

second, add soft link

sudo ln -s /usr/local/bin/pip /usr/bin/pip

回答 20

此命令对我有用。

卷曲https://bootstrap.pypa.io/get-pip.py -o get-pip.py python get-pip.py –force-reinstall –user

This command works for me.

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python get-pip.py –force-reinstall –user


回答 21

您可以先将其删除,然后重新安装,即可。对于centos:

yum remove python-pip
yum install python-pip

you can remove it first, and install again ,it will be ok. for centos:

yum remove python-pip
yum install python-pip

回答 22

我通过解决这个问题

sudo apt-get install python3-pip

这甚至适用于python2.7,令人惊讶…

I fixed this problem by

sudo apt-get install python3-pip

this worked even for python2.7, amazing…


回答 23

我的解决方案是添加import pip到链接到pip/pip3命令的脚本。

首先,/usr/local/bin/pip使用您喜欢的文本编辑器和sudo模式打开文件(例如)。例如,我sudo vim /usr/local/bin/pip用来打开脚本文件。

您将获得一些文件,如下所示:

import re
import sys

from pip._internal import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

然后,在问题解决import pip之前插入该语句from pip._internal import main

My solution is adding import pip to the script linked to the pip/pip3 commands.

Firstly, open the file (e.g. /usr/local/bin/pip) with your favorite text editor and the sudo mode. For example, I use sudo vim /usr/local/bin/pip to open the script file.

You will obtain some file as following:

import re
import sys

from pip._internal import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

Afterwards, insert the statement import pip just before the from pip._internal import main then the issue is resolved.


回答 24

这些通常来自使用pip来“更新”系统安装的pip,和/或在用户下具有多个pip安装。我的解决方案是清除用户下已安装的多个pip,重新安装pip repo,然后如上所述进行“ pip install –user pip”。

请参阅:https//github.com/pypa/pip/issues/5599,以获取正式的完整讨论以及针对该问题的修复程序。

These often comes from using pip to “update” system installed pip, and/or having multiple pip installs under user. My solution was to clean out the multiple installed pips under user, reinstall pip repo, then “pip install –user pip” as above.

See: https://github.com/pypa/pip/issues/5599 for an official complete discussion and fixes for the problem.


回答 25

我尝试了以下命令来解决此问题,它对我有用:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall

I tried the following command to solve the issue and it worked for me:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall

pip抛出TypeError:尝试安装新软件包时parse()得到了意外的关键字参数’transport_encoding’

问题:pip抛出TypeError:尝试安装新软件包时parse()得到了意外的关键字参数’transport_encoding’

我正在使用最新版本的Anaconda3。我刚刚安装了它,我正在尝试下载一些软件包。我正在使用Anaconda Prompt。尝试使用pip做任何事情(包括升级现有软件包)时,我得到以下回溯。

    Exception:
Traceback (most recent call last):
  File "C:\Users\csprock\Anaconda3\lib\site-packages\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "C:\Users\csprock\Anaconda3\lib\site-packages\pip\commands\install.py", line 335, in run
    wb.build(autobuilding=True)
  File "C:\Users\csprock\Anaconda3\lib\site-packages\pip\wheel.py", line 749, in build
    self.requirement_set.prepare_files(self.finder)
  File "C:\Users\csprock\Anaconda3\lib\site-packages\pip\req\req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "C:\Users\csprock\Anaconda3\lib\site-packages\pip\req\req_set.py", line 487, in _prepare_file
    req_to_install, finder)
  File "C:\Users\csprock\Anaconda3\lib\site-packages\pip\req\req_set.py", line 428, in _check_skip_installed
    req_to_install, upgrade_allowed)
  File "C:\Users\csprock\Anaconda3\lib\site-packages\pip\index.py", line 465, in find_requirement
    all_candidates = self.find_all_candidates(req.name)
  File "C:\Users\csprock\Anaconda3\lib\site-packages\pip\index.py", line 423, in find_all_candidates
    for page in self._get_pages(url_locations, project_name):
  File "C:\Users\csprock\Anaconda3\lib\site-packages\pip\index.py", line 568, in _get_pages
    page = self._get_page(location)
  File "C:\Users\csprock\Anaconda3\lib\site-packages\pip\index.py", line 683, in _get_page
    return HTMLPage.get_page(link, session=self.session)
  File "C:\Users\csprock\Anaconda3\lib\site-packages\pip\index.py", line 811, in get_page
    inst = cls(resp.content, resp.url, resp.headers)
  File "C:\Users\csprock\Anaconda3\lib\site-packages\pip\index.py", line 731, in __init__
    namespaceHTMLElements=False,
TypeError: parse() got an unexpected keyword argument 'transport_encoding'

有任何想法吗?(这个问题只有在我安装了tensorflow之后才开始出现)谢谢。

I am using the latest version of Anaconda3. I just installed it and I am trying to download some packages. I am using the Anaconda Prompt. While trying to use pip to do anything (including upgrading existing packages) I get the following traceback.

    Exception:
Traceback (most recent call last):
  File "C:\Users\csprock\Anaconda3\lib\site-packages\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "C:\Users\csprock\Anaconda3\lib\site-packages\pip\commands\install.py", line 335, in run
    wb.build(autobuilding=True)
  File "C:\Users\csprock\Anaconda3\lib\site-packages\pip\wheel.py", line 749, in build
    self.requirement_set.prepare_files(self.finder)
  File "C:\Users\csprock\Anaconda3\lib\site-packages\pip\req\req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "C:\Users\csprock\Anaconda3\lib\site-packages\pip\req\req_set.py", line 487, in _prepare_file
    req_to_install, finder)
  File "C:\Users\csprock\Anaconda3\lib\site-packages\pip\req\req_set.py", line 428, in _check_skip_installed
    req_to_install, upgrade_allowed)
  File "C:\Users\csprock\Anaconda3\lib\site-packages\pip\index.py", line 465, in find_requirement
    all_candidates = self.find_all_candidates(req.name)
  File "C:\Users\csprock\Anaconda3\lib\site-packages\pip\index.py", line 423, in find_all_candidates
    for page in self._get_pages(url_locations, project_name):
  File "C:\Users\csprock\Anaconda3\lib\site-packages\pip\index.py", line 568, in _get_pages
    page = self._get_page(location)
  File "C:\Users\csprock\Anaconda3\lib\site-packages\pip\index.py", line 683, in _get_page
    return HTMLPage.get_page(link, session=self.session)
  File "C:\Users\csprock\Anaconda3\lib\site-packages\pip\index.py", line 811, in get_page
    inst = cls(resp.content, resp.url, resp.headers)
  File "C:\Users\csprock\Anaconda3\lib\site-packages\pip\index.py", line 731, in __init__
    namespaceHTMLElements=False,
TypeError: parse() got an unexpected keyword argument 'transport_encoding'

Any ideas? (this problem only started after I installed tensorflow) Thanks.


回答 0

我有同样的问题,对我有用的是用conda更新点子:

conda install pip

它将我的点值从9.0.1-py36hadba87b_3更改为9.0.1-py36h226ae91_4,并解决了问题。

I had the same problem and what worked for me was updating pip with conda:

conda install pip

It changed my pip from 9.0.1-py36hadba87b_3 to 9.0.1-py36h226ae91_4 and solved issue.


回答 1

下载https://github.com/html5lib/html5lib-python/tree/master/html5lib并覆盖tensorflow环境“ envs \ tensorflow \ Lib \ site-packages \ html5lib”中html5lib文件夹中的所有文件,那么您应该能够在那之后运行任何“ pip install”命令

download https://github.com/html5lib/html5lib-python/tree/master/html5lib and overwrite all the files within html5lib folder in your tensorflow environment “envs\tensorflow\Lib\site-packages\html5lib” Then you should be able to run any “pip install” commands after that


回答 2

我在最新版本的Anaconda 3上安装keras时遇到了相同的问题(使用pip安装tensorflow 1.3之后),我可以通过使用conda安装keras来解决此问题。 conda install -c conda-forge keras

I ran into the same problem while installing keras (after I installed tensorflow 1.3 using pip) on the latest version of Anaconda 3. I was able to fix the problem by installing keras using conda conda install -c conda-forge keras


回答 3

安装SerpentAI时出现此确切错误。我所做的所有修复工作都activate serpent在conda提示符下运行,然后再次运行命令。不知道它是否适用于您的情况,但它们似乎足够接近。

编辑-如果上述方法无效,请注释掉以下行:

这对我来说非常有效。(这花费了我们社区中一个有用的成员进行了8个小时的调试)

I was getting this exact error installing SerpentAI. All I did to fix it was run activate serpent in conda prompt and then I ran the command again. Not sure if it’s applicable to your situation, but they seem close enough that it might.

EDIT – if the above didn’t work, comment out this line:

That worked perfectly for me. (this took a helpful member of our community 8 hours to debug)


回答 4

这对我有用:

python -m pip install –upgrade张量流

This worked for me:

python -m pip install –upgrade tensorflow


回答 5

pip3 install -U html5lib=="0.9999999"

为我工作

这是github上的html5lib错误

来自:https : //stackoverflow.com/a/39087283

pip3 install -U html5lib=="0.9999999"

worked for me

here’s the html5lib bug on github

from: https://stackoverflow.com/a/39087283


回答 6

这是给我的解决方法:

cd /usr/share/python-wheels/

目录的内容:

-rwxrwxrwx   1 www-data www-data 493905 Jul 22  2015 html5lib-0.999-py2.py3-none-any.whl
-rw-r--r--   1 root     root     112620 Apr  3  2019 html5lib-0.999999999-py2.py3-none-any.whl

跑:

mv html5lib-0.999-py2.py3-none-any.whl html5lib-0.999-py2.py3-none-any.whl.bak

pip3工作正常。正在加载旧的0.999版本。

Here was the fix for me:

cd /usr/share/python-wheels/

Contents of dir:

-rwxrwxrwx   1 www-data www-data 493905 Jul 22  2015 html5lib-0.999-py2.py3-none-any.whl
-rw-r--r--   1 root     root     112620 Apr  3  2019 html5lib-0.999999999-py2.py3-none-any.whl

Run:

mv html5lib-0.999-py2.py3-none-any.whl html5lib-0.999-py2.py3-none-any.whl.bak

pip3 works fine after. Was loading the old 0.999 version.


如何打包python应用程序使其可点子安装?

问题:如何打包python应用程序使其可点子安装?

我在业余时间正在编写django应用程序,以参加我们正在上班的小费竞赛。我认为我会明智地使用这段时间,并逐步了解virtualenv,pip,打包,django 1.3以及如何编写易于重新分发的应用程序。到目前为止,一切都很好。

我要负责包装部分。例如,GitHub上的许多django应用程序大多(大致)以相同的方式捆绑在一起。我将以django-uni-forms为例。

我所做的一个假设是,MANIFEST.insetup.py是pip完成工作所需的唯一必需的部分。那是对的吗?如果我的假设是错误的,还需要哪些其他组件?

是否通常生成了所需的包装文件,或者是手工制作的?可以描述依赖项然后再安装吗?我的应用程序依赖django-uni-forms,并且在requirements.txt我用来安装依赖项的应用程序中的文件中列出了它;但这是包装系统可以解决的问题吗?

我需要遵循哪些步骤来打包我的应用程序,以使pip能够安装它和任何依赖项?

I’m writing a django application in my spare time for a footy-tipping competition we’re running at work. I figured I’d use this time wisely, and get up to speed on virtualenv, pip, packaging, django 1.3, and how to write an easily redistributable application. So far, so good.

I’m up to the packaging part. A lot of the django apps on GitHub for instance are mostly bundled (roughly) the same way. I’ll use django-uni-forms as an example.

An assumption I’m making is that the MANIFEST.in and setup.py are the only required pieces that pip needs to do its job. Is that correct? What other components are necessary if my assumption is wrong?

Are the required packaging files generally generated, or are they crafted by hand? Can dependencies be described and then installed also? My application depends on django-uni-forms, and I have it listed in a requirements.txt file within my app which I used to install the dependency; but is that something that the packaging system can take care of?

What are the steps I need to follow to package my application in such a way that pip will be able to install it and any dependencies?


回答 0

是的,MANIFEST.in而且setup.py应该是足够的。

这篇博客文章确实具有有关此主题的一些很好的信息: 打包Django可重用应用程序

这是另一个很好的详细概述,对我有很大帮助: Python打包用户指南

尤其是包含静态文件(模板)的提示很重要,因为起初可能并不明显。

是的,您可以在setup.py其中指定所需的软件包,这些软件包在安装应用程序时会自动获取。

例如:

    install_requires = [
        'django-profiles',
        'django-uni-forms',
    ],

显然,现在我们在两个地方定义了依赖项,但这并不一定意味着这些信息是重复的:setup.py与requirements.txt

通过此设置,您的软件包应可通过安装pip


正如Pierre在评论中指出的那样,Django的官方文档中现在还有一个相关的部分: 打包您的应用

然后是这个“完全不完整”的指南,它确实很好地概述了打包并将程序包上载到PyPI:分享您的爱的劳动:PyPI的快速与肮脏

Yes, MANIFEST.in and setup.py should be sufficient.

This blog post really has some good information on this topic: Packaging a Django reusable app

And here’s another good, detailed overview that helped me a lot: Python Packaging User Guide

Especially the tips to get your static files (templates) included are important as this might not be obvious at first.

And yes, you can specify required packages in your setup.py which are automatically fetched when installing your app.

For example:

    install_requires = [
        'django-profiles',
        'django-uni-forms',
    ],

Obviously now we have two places where dependencies are defined, but that doesn’t necessarily mean that these information are duplicated: setup.py vs requirements.txt

With this setup your package should be installable via pip.


As Pierre noted in the comments, there’s now also a relevant section in Django’s official documentation: Packaging your app

And then there is this “completely incomplete” guide, which really gives a great overview over packaging and uploading a package to PyPI: Sharing Your Labor of Love: PyPI Quick And Dirty


为什么从git repo进行pip安装时#egg = foo

问题:为什么从git repo进行pip安装时#egg = foo

当我执行“ pip install -e …”以从git repo安装时,我必须指定#egg = somename或pip抱怨。例如:

pip install -e git://github.com/hiidef/oauth2app.git#egg=oauth2app

这个“蛋”字符串的意义是什么?

When I do a “pip install -e …” to install from a git repo, I have to specify #egg=somename or pip complains. For example:

pip install -e git://github.com/hiidef/oauth2app.git#egg=oauth2app

What’s the significance of this “egg” string?


回答 0

每点安装-h“ egg”字符串是在安装过程中检出的目录

per pip install -h the “egg” string is the directory that gets checked out as part of the install


回答 1

您必须包含#egg = Package,这样pip才能知道该URL的期望值。参见https://pip.pypa.io/en/stable/reference/pip_install/#vcs-support

更多鸡蛋

You have to include #egg=Package so pip knows what to expect at that URL. See https://pip.pypa.io/en/stable/reference/pip_install/#vcs-support

more on eggs


回答 2

https://pip.pypa.io/zh_CN/stable/reference/pip_install/#vcs-support说:

pip使用其URL后缀“ egg =-”的“项目名称”组件的依赖关系逻辑在pip下载和分析元数据之前识别项目。蛋名称的可选“版本”组件在功能上并不重要。它仅提供有关使用哪个版本的信息。对于setup.py不在项目根目录中的项目,将使用“子目录”组件。“子目录”组件的值应该是从项目根目录到setup.py所在位置的路径。

据此,我推断出egg值仅用于依赖性检查,因此,我认为按照惯例,some-pypi-package-name应使用包名称(即),而不要使用任何包含的文件夹(即some_pypi_package_name

https://pip.pypa.io/en/stable/reference/pip_install/#vcs-support says:

The “project name” component of the url suffix “egg=-” is used by pip in its dependency logic to identify the project prior to pip downloading and analyzing the metadata. The optional “version” component of the egg name is not functionally important. It merely provides a human-readable clue as to what version is in use. For projects where setup.py is not in the root of project, “subdirectory” component is used. Value of “subdirectory” component should be a path starting from root of the project to where setup.py is located.

From this I deduce that the egg value is only used for dependency checks and therefore I think, by convention, the package name (i.e. some-pypi-package-name) should be used, not any contained folder (i.e. some_pypi_package_name)


回答 3

一个Egg只是一些捆绑的python代码。在git网址中,egg是项目名称。 VCS支持

通常,我们从Pypi安装python软件包,因此您仅指定软件包名称和版本(如果未指定,则假定为最新版本)。然后,Pypi搜索您想要的鸡蛋,然后pip安装该鸡蛋。 pip install celery将安装最新发布的鸡蛋,pip install celery[redis]并安装包含相同celery软件包的其他鸡蛋,并从celery的setup.py中列出为Redis依赖项的软件包中安装最新的鸡蛋。

使用git和gitlab路径,您可以指定/{user|group}/{repository}.git@{tag}#egg={package-name}#egg=celery和之间有区别#egg=celery[redis],但是它们都将来自同一源代码。

除实际标签外,“标签”还可以是分支或提交哈希。master如果未指定,则假定为。

例如,git+https://github.com/celery/celery.git#egg=celery==4.3.0将检出master分支并进行安装。即使您指定了版本号,在安装中也不会考虑。版本号被忽略

通过git或其他VCS网址进行安装时,您将需要查找所需版本的标签或哈希。例如,git+https://github.com/celery/celery.git@v4.3.0#egg=celery它将签出标记为“ v4.3.0”的提交,然后从该源代码安装该软件包。假设维护人员没有过分地错误标记他们的存储库,则可以得到所需的版本。

An Egg is just some bundled python code. In a git url, the egg is the project name. VCS Support

Normally we install python packages from Pypi, so you specify ONLY the package name and version (or it assumes latest version if you don’t specify). Pypi then searches for which egg you want and pip installs that. pip install celery would install the latest published egg and pip install celery[redis] would install a different egg that contains the same celery package and also installs the the latest eggs from whatever packages were listed as dependencies for redis in celery’s setup.py.

With git and gitlab paths, you specify /{user|group}/{repository}.git@{tag}#egg={package-name}. there is a difference between #egg=celery and #egg=celery[redis], but they will both come from the same source code.

“tag” can also be a branch or commit hash in addition to an actual tag. It is assumed to be master if you do not specify.

for example, git+https://github.com/celery/celery.git#egg=celery==4.3.0 would check out the master branch and install that. Even though you specified a version number, it is not taken into account in the installation. THE VERSION NUMBER IS IGNORED

When installing via git or other VCS urls, you will want to find the tag or hash of the version you need. For example, git+https://github.com/celery/celery.git@v4.3.0#egg=celery which will checkout the commit tagged “v4.3.0” and then install the package from that source code. Assuming the maintainers did not egregiously mis-tag their repositories, you can get the version you want like that.


运行“ sudo pip”有什么风险?

问题:运行“ sudo pip”有什么风险?

有时,我会遇到一些评论或回应,它们强调说pipsudo“错误”或“不良”情况下运行,但在某些情况下(包括我设置了一堆工具的方式),情况可能要简单得多,甚至有必要这样运行。

什么是与运行相关的风险pipsudo


请注意,这个问题与这个问题不同,尽管有标题,但没有提供有关风险的信息。这也不是关于如何避免使用的问题sudo,而是关于为什么要使用的问题。

Occasionally I run into comments or responses that state emphatically that running pip under sudo is “wrong” or “bad”, but there are cases (including the way I have a bunch of tools set up) where it is either much simpler, or even necessary to run it that way.

What are the risks associated with running pip under sudo?


Note that this in not the same question as this one, which, despite the title, provides no information about risks. This also isn’t a question about how to avoid using sudo, but about specifically why one would want to.


回答 0

当您pip使用时sudo,您会setup.py使用sudo。换句话说,您可以从互联网上以根用户身份运行任意Python代码。如果有人在PyPI上放置了一个恶意项目,然后安装了该项目,则可以使攻击者具有对计算机的根访问权限。在对pipPyPI和PyPI 进行一些最新修复之前,攻击者还可能在您下载值得信赖的项目时,在中间攻击中让一名男子注入他们的代码。

When you run pip with sudo, you run setup.py with sudo. In other words, you run arbitrary Python code from the Internet as root. If someone puts up a malicious project on PyPI and you install it, you give an attacker root access to your machine. Prior to some recent fixes to pip and PyPI, an attacker could also run a man in the middle attack to inject their code when you download a trustworthy project.


回答 1

除了明显的安全风险(我认为安装已知的软件时,风险实际上较低)之外,还有其他原因。系统随附的Python是该系统的一部分,当您要管理系统时,可以使用专为系统维护而设计的工具,例如在安装/升级/卸载软件时的软件包管理器。当您开始使用第三方工具(在本例中为pip)修改系统软件时,就无法保证系统状态。另一个原因是,sudo可能会给您带来问题,否则您将没有机会或很少会有其他问题。例如,请参阅python中sys.executable和sys.version之间的不匹配

发行版已意识到此问题,并尝试减轻它。例如,Fedora – 使sudo pip安全; Debian – dist-packages而不是site-packages

Besides obvious security risks (which I think are in fact low when you install software you know) brought in other answers there is another reason. Python that comes with the system is part of this system and when you want to manage system you use tools designated for system maintenance like package manager in case of installing/upgrading/uninstalling software. When you start to modify system’s software with third party tools (pip in this instance) then you have no guarantee about the state of your system. Yet another reason is that sudo can bring you problems you wouldn’t have a chance or have a very small chance to have otherwise. See for example Mismatch between sys.executable and sys.version in Python

Distros are aware of this problem and try to mitigate it. For example Fedora – Making sudo pip safe and Debian – dist-packages instead of site-packages.


回答 2

以这种方式使用pip意味着您可以信任它到允许它对系统进行任何操作的程度。不仅是点子,而且还会从您可能不信任的来源下载并执行的任何代码,这可能是恶意的。

pip不需要所有这些特权,只需要对特定文件和目录的写权限。如果您不能使用系统的程序包管理器并且不想使用虚拟环境,则可以创建一个对python安装目录具有写权限的特定用户,并将其用于pip。这样,您可以更好地控制可以做什么和不可以做什么。您可以使用sudo -u它!

Using pip that way means you trust it to the level you allow it to make anything to your system. Not only pip, but also any code it will download and execute from sources you may not trust and that can be malicious.

And pip doesn’t need all that privileges, only the write access to specific files and directories. If you can’t use your system’s package manager and do not want to go the virtual environment way, you may create a specific user that has write privilege to the python installation directory and use it for pip. That way you better control what can pip do and not do. And you can use sudo -u for that!


回答 3

唯一“错误”的地方sudo是,它确实是以超级用户ala根身份运行的,这意味着您可能使用错误的命令破坏安装。由于PIP是特定程序的软件包维护,因此无论如何都需要这种访问权限才能进行更改…

The only thing “wrong” with sudo is that it, well, DOes as Super User ala root meaning you can potentially destroy an installation with the wrong command. As PIP is a package maintenance for a particular program you would need such access anyhow to make changes…


使用pip命令从requirements.txt升级python软件包

问题:使用pip命令从requirements.txt升级python软件包

如何使用pip命令从requirements.txt文件升级所有python软件包?

尝试以下命令

$ pip install --upgrade -r requirements.txt

由于python软件包的后缀是版本号(Django==1.5.1),因此它们似乎没有升级。有没有比手动编辑requirements.txt文件更好的方法?

编辑

正如Andy在其答案中提到的那样,软件包已固定到特定版本,因此无法通过pip命令升级软件包。

但是,我们可以pip-tools使用以下命令来实现。

$ pip-review --auto

这将自动从requirements.txt中升级所有软件包(确保pip-tools使用pip install命令安装)。

How do I upgrade all my python packages from requirements.txt file using pip command?

tried with below command

$ pip install --upgrade -r requirements.txt

Since, the python packages are suffixed with the version number (Django==1.5.1) they don’t seem to upgrade. Is there any better approach than manually editing requirements.txt file?

EDIT

As Andy mentioned in his answer packages are pinned to a specific version, hence it is not possible to upgrade packages through pip command.

But, we can achieve this with pip-tools using the following command.

$ pip-review --auto

this will automatically upgrade all packages from requirements.txt (make sure to install pip-tools using pip install command).


回答 0

否。您的需求文件已固定到特定版本。如果您的要求设置为该版本,则不应尝试升级到那些版本之外。如果需要升级,则需要在需求文件中切换到未固定的版本。

例:

lxml>=2.2.0

这会将lxml升级到2.2.0以上的任何版本

lxml>=2.2.0,<2.3.0

这会将lxml升级到2.2.0和2.3.0之间的最新版本。

No. Your requirements file has been pinned to specific versions. If your requirements are set to that version, you should not be trying to upgrade beyond those versions. If you need to upgrade, then you need to switch to unpinned versions in your requirements file.

Example:

lxml>=2.2.0

This would upgrade lxml to any version newer than 2.2.0

lxml>=2.2.0,<2.3.0

This would upgrade lxml to the most recent version between 2.2.0 and 2.3.0.


回答 1

你可以试试:

pip install --upgrade --force-reinstall -r requirements.txt

您也可以忽略已安装的软件包并安装新的软件包:

pip install --ignore-installed -r requirements.txt

you can try:

pip install --upgrade --force-reinstall -r requirements.txt

You can also ignore installed package and install the new one :

pip install --ignore-installed -r requirements.txt

回答 2

我已经在这里回答了这个问题。这是我的解决方案:

因为没有简便的方法来逐个软件包升级软件包和更新requirements.txt文件,所以我写了这个pip-upgrader,它requirements.txt为所选软件包(或所有软件包)更新了文件中的版本

安装

pip install pip-upgrader

用法

激活您的virtualenv(这很重要,因为它还将在当前virtualenv中安装新版本的升级软件包)。

cd 进入您的项目目录,然后运行:

pip-upgrade

高级用法

如果需求放置在非标准位置,请将其作为参数发送:

pip-upgrade path/to/requirements.txt

如果您已经知道要升级的软件包,只需将它们作为参数发送:

pip-upgrade -p django -p celery -p dateutil

如果您需要升级到发行前/发行后版本,请添加 --prerelease请在命令中参数。

全面披露:我写了这个包裹。

I already answered this question here. Here’s my solution:

Because there was no easy way for upgrading package by package, and updating the requirements.txt file, I wrote this pip-upgrader which also updates the versions in your requirements.txt file for the packages chosen (or all packages).

Installation

pip install pip-upgrader

Usage

Activate your virtualenv (important, because it will also install the new versions of upgraded packages in current virtualenv).

cd into your project directory, then run:

pip-upgrade

Advanced usage

If the requirements are placed in a non-standard location, send them as arguments:

pip-upgrade path/to/requirements.txt

If you already know what package you want to upgrade, simply send them as arguments:

pip-upgrade -p django -p celery -p dateutil

If you need to upgrade to pre-release / post-release version, add --prerelease argument to your command.

Full disclosure: I wrote this package.


回答 3

我建议冻结所有依赖项,以使构建具有可预测性

这样做时,您可以像这样一次更新所有依赖项

sed -i '' 's/==/>=/g' requirements.txt
pip install -U -r requirements.txt
pip freeze > requirements.txt

完成上述操作后,请使用新的程序包集测试您的项目,并最终将文件提交requirements.txt到存储库。

I suggest freezing all of your dependencies in order to have predictable builds.

When doing that, you can update all dependencies at once like this:

sed -i '' 's/==/>=/g' requirements.txt
pip install -U -r requirements.txt
pip freeze > requirements.txt

Having done the above, test your project with the new set of packages and eventually commit the requirements.txt file to the repository.


回答 4

我只需要做同样的事情…用这个小的一线工作:

packages=$(cat requirements.txt | sed 's/==.*//g'); echo $packages | xargs pip3 install -U; freeze=$(pip3 freeze); for p in $(echo $packages); do echo $freeze | grep -E "^${p}==" >> requirements.new; done

哪一个:

  • packages=$(cat requirements.txt | sed 's/==.*//g') 在requirements.txt中创建当前软件包名称的列表(删除版本)。
  • echo $packages | xargs pip3 install -U 然后将所有软件包作为参数传递给pip3进行升级。
  • freeze=$(pip3 freeze); 以requirements.txt所需的格式获取所有当前软件包版本。
  • for p in $(echo $packages) 然后遍历软件包名称
    • echo $freeze | grep -E "^${p}==" >> requirements.new 从pip Frozen输出中获取与软件包匹配的软件包版本行,并写入新的requirements.txt

这具有保留原始requirements.txt的顺序的额外好处。:)

希望这可以帮助!

I’ve just had to do the same… used this small one-liner to do the job:

packages=$(cat requirements.txt | sed 's/==.*//g'); echo $packages | xargs pip3 install -U; freeze=$(pip3 freeze); for p in $(echo $packages); do echo $freeze | grep -E "^${p}==" >> requirements.new; done

which:

  • packages=$(cat requirements.txt | sed 's/==.*//g') creates a list of the current packages names in requirements.txt (removing the version).
  • echo $packages | xargs pip3 install -U then passes all of the packages as arguments to pip3 to upgrade.
  • freeze=$(pip3 freeze); Gets all of the current package versions in the format required for requirements.txt
  • for p in $(echo $packages) then iterates through the package names
    • echo $freeze | grep -E "^${p}==" >> requirements.new gets the package version line from the pip freeze output which matches the package and writes to new requirements.txt

This has the added benefit of preserving the ordering of the original requirements.txt. :)

Hope this helps!


回答 5

由于无法使用bash做到这一点,因此我编写了一个python模块来创建一个没有版本的新需求文件并使用它:

data = open('requirements-prod.pip', 'r')
data2 = open('requirements-prod-no-version.pip', 'w')
for line in data.readlines():
    new_line = line[:line.index('==')]
    data2.write(new_line + '\n')
data2.flush()

然后从新文件安装库 pip install -U -r requirements-prod-no-version.pip

最后将版本冻结到原始文件 pip freeze > requirements-prod.pip

Since I couldn’t do that using bash, I wrote a python module to create a new requirements file with no versions and use it:

data = open('requirements-prod.pip', 'r')
data2 = open('requirements-prod-no-version.pip', 'w')
for line in data.readlines():
    new_line = line[:line.index('==')]
    data2.write(new_line + '\n')
data2.flush()

Then install the libs from the new file pip install -U -r requirements-prod-no-version.pip

Finally freeze the versions to the original file pip freeze > requirements-prod.pip


回答 6

另一个解决方案是使用升级要求

pip install upgrade-requirements

然后运行:

upgrade-requirements

它将升级所有不是最新版本的软件包,并在最后创建一个更新的requirements.txt。

Another solution is to use the upgrade-requirements package

pip install upgrade-requirements

And then run :

upgrade-requirements

It will upgrade all the packages that are not at their latest versions, and also create an updated requirements.txt at the end.


回答 7

  • 1)要从reqs.txt升级pip安装的文件, 添加> =代替==, 这将告诉pip安装的lib大于或等于您请求的版本,此处安装的是请求的库的最新版本

    1.a)**我对线程的回答**通过将py -m pip install -r reqs.txt添加到每日重启中…或者类似的性质,您可以更新已安装的库。安迪完美总结

    -我进入此线程的原因是查找有关如何更新虚拟环境基本点的信息(通常对我来说是10.0.03 ??)

希望解决一个问题,我能够得出两个解决方案之一

A. venv创建|| B.安装必需的库

多亏了安迪,我满足了需求B

通过在reqs.txt中添加pip > = 请求的版本

在实例化新的虚拟环境后|| 重新说明以前的Venv

  1. py -m venv devenv

设置新的开发环境

  1. devenv\scripts\activate.bat

激活开发环境

  1. python -m pip install -r requirenments.txt

安装基本库

Yield输出

收集pip > = 20.0.2(从-r requirenments.txt(第1行))使用缓存的> https://files.pythonhosted.org/packages/54/0c/d01aa759fdc501a58f431eb594a17495f15b88da142ce14b5845662c13f3/pip-20.0.2-py2.py3-无任何

找到现有的安装:pip 10.0.1

卸载pip-10.0.1:

 Successfully uninstalled pip-10.0.1
 Successfully installed pip-20.0.2

对不起,我们希望可以帮助某人:)

🤳奥斯汀👨‍🎤🚀🥊

  • 1) To upgrade pip installed files from reqs.txt add the >= in replacement of == this will tell pip to install lib greater than or equal to the version you are requesting, here by installing the most to-date version of requested library

    1.a) **My answer for thread ** By adding py -m pip install -r reqs.txt to a daily restart… or something of the nature you can update your installed libs. Summed up by Andy Perfectly

    -My reason For entering this thread was to find information on how to update virtual env base pip (usually 10.0.03 for me??)

in-hopes of satisfying an issue of which have I was able to derive one of two solutions

A. creation of venv || B. Installation of Required libs

Thanks to Andy I have satisfied need B

By adding pip >= requested version in reqs.txt

upon instantiation of new virtual-Environment || re-instantiation of previous Venv

  1. py -m venv devenv

to setup new dev env

  1. devenv\scripts\activate.bat

to activate dev env

  1. python -m pip install -r requirenments.txt

to install base libs

yeilds output

Collecting pip >= 20.0.2 (from -r requirenments.txt (line 1)) Using cached >https://files.pythonhosted.org/packages/54/0c/d01aa759fdc501a58f431eb594a17495f15b88da142ce14b5845662c13f3/pip-20.0.2-py2.py3-none-any.whl

Found existing installation: pip 10.0.1

Uninstalling pip-10.0.1:

 Successfully uninstalled pip-10.0.1
 Successfully installed pip-20.0.2

Sorry for the Brain Dump, Hopes this helps someone :)

🤳 Austin 👨‍🎤🚀🥊


回答 8

第二个答案是最有用的,但是我想做的是锁定某些程序包,同时使其他程序包处于最新版本(例如youtube-dl)。

一个示例requirements.txt如下所示(〜表示兼容):

Pillow==6.2.2
requests~=2.22.0
youtube_dl

然后在终端中,使用命令 pip install --upgrade -r requirements.txt

这样可以确保Pillow保持在6.2.2,将请求升级到最新的2.22.x(如果有),如果尚未安装,则将安装最新版本的youtube-dl。

The second answer is the most useful but what I wanted to do is lock some packages while having others at the latest version (e.g. youtube-dl).

An example requirements.txt would look like this (~ means compatible):

Pillow==6.2.2
requests~=2.22.0
youtube_dl

Then in the terminal, use the command pip install --upgrade -r requirements.txt

This ensures that Pillow will stay at 6.2.2, requests will be upgraded to the latest 2.22.x (if available), and the latest version of youtube-dl will be installed if not already.


回答 9

我猜最简单的解决方案是使用以下命令创建requirements.txt:

pip freeze | sed 's/==/>=/' > requirements.txt

I guess the simplest solution is creating the requirements.txt with:

pip freeze | sed 's/==/>=/' > requirements.txt

回答 10

如果您在django项目中安装了任何内容,并且在安装后想要更新需求文件,则此命令可以更新您required.txt文件pip冻结> requirements.txt

如果您的需求文件不存在于项目中,则可以使用此命令来创建新的需求文件。

If you install anything in your django project and after installation you want to update your requirement file this command can update you requirement.txt file pip freeze > requirements.txt

if your requirement file not exist in you project you can use this command for make new requirement.txt file pip freeze > requirements.txt


回答 11

我按如下所示编辑requirements.txt并运行$ sh ./requirements.txt

pip install -U amqp;
pip install -U appdirs;
pip install -U arrow;
pip install -U Babel;
pip install -U billiard;
pip install -U celery;
pip install -U Django;
pip install -U django-cors-headers;
pip install -U django-crispy-forms;
pip install -U django-filter;
pip install -U django-markdown-deux;
pip install -U django-pagedown;
pip install -U django-timezone-field;
pip install -U djangorestframework;
pip install -U fcm-django;
pip install -U flower;
pip install -U gunicorn;
pip install -U kombu;
pip install -U Markdown;
pip install -U markdown2;
pip install -U packaging;

I edit the requirements.txt as below and run $sh ./requirements.txt

pip install -U amqp;
pip install -U appdirs;
pip install -U arrow;
pip install -U Babel;
pip install -U billiard;
pip install -U celery;
pip install -U Django;
pip install -U django-cors-headers;
pip install -U django-crispy-forms;
pip install -U django-filter;
pip install -U django-markdown-deux;
pip install -U django-pagedown;
pip install -U django-timezone-field;
pip install -U djangorestframework;
pip install -U fcm-django;
pip install -U flower;
pip install -U gunicorn;
pip install -U kombu;
pip install -U Markdown;
pip install -U markdown2;
pip install -U packaging;

pip的`–no-cache-dir`有什么用?

问题:pip的`–no-cache-dir`有什么用?

我最近看到--no-cache-dir在Docker文件中使用了它。我以前从未见过该标志,并且帮助没有解释它:

 --no-cache-dir              Disable the cache.
  1. 问题:缓存了什么?
  2. 问题:高速缓存用于什么?
  3. 问题:为什么要禁用它?

I’ve recently seen the --no-cache-dir being used in a Docker file. I’ve never seen that flag before and the help is not explaining it:

 --no-cache-dir              Disable the cache.
  1. Question: What is cached?
  2. Question: What is the cache used for?
  3. Question: Why would I want to disable it?

回答 0

  1. 缓存为:藏匿起来以备将来使用
  2. 用于
  • 存储.whl通过pip安装的模块的安装文件(等)
  • 存储源文件(.tar.gz等),以免在未到期时重新下载
  1. 您可能要禁用缓存的可能原因
  • 您的硬盘驱动器上没有空间
  • 以前pip install意外的设置 运行
    • 例如:
      • 以前运行export PYCURL_SSL_LIBRARY=nsspip install pycurl
      • 希望新的运行export PYCURL_SSL_LIBRARY=opensslpip install pycurl --compile --no-cache-dir
  • 您想要使Docker映像尽可能小

链接到文档

https://pip.pypa.io/en/stable/reference/pip_install/#caching – @emredjan https://pip.pypa.io/en/stable/reference/pip_install/ – @mikea

  1. Cached is: store away in hiding or for future use
  2. Used for
  • store the installation files(.whl, etc) of the modules that you install through pip
  • store the source files (.tar.gz, etc) to avoid re-download when not expired
  1. Possible Reason you might want to disable cache:
  • you don’t have space on your hard drive
  • previously run pip install with unexpected settings
    • eg:
      • previously run export PYCURL_SSL_LIBRARY=nss and pip install pycurl
      • want new run export PYCURL_SSL_LIBRARY=openssl and pip install pycurl --compile --no-cache-dir
  • you want to keep a Docker image as small as possible

Links to documentation

https://pip.pypa.io/en/stable/reference/pip_install/#caching – @emredjan https://pip.pypa.io/en/stable/reference/pip_install/ – @mikea


回答 1

我认为在--no-cache-dir构建Docker映像时有充分的理由使用。缓存在Docker映像中通常是无用的,并且您可以通过禁用缓存来缩小映像大小。

I think there is a good reason to use --no-cache-dir when you are building Docker images. The cache is usually useless in a Docker image, and you can definitely shrink the image size by disabling the cache.


回答 2

禁用pip缓存的另一个原因-如果您以不存在的用户身份运行pip,则将创建其主目录,但该目录由root拥有。

在chroot中构建Amazon AMI时,这会发生在我们身上-pip以构建器机器上的用户身份运行,而不是在构建AMI的chroot监狱中。这是有问题的,因为特定用户现在无法ssh到刚刚构建的内容,因为他们无法读取他们的.ssh目录。

我想不出任何其他原因来以不存在的用户身份运行pip,因此这是一个非常极端的情况。

Another reason to disable the pip cache – if you run pip as a user that does not yet exist, their home directory will be created, but owned by root.

This happens to us when building Amazon AMIs in a chroot – pip is being run as a user that exists on the builder machine, but not in the chroot jail where the AMI is being constructed. This is problematic as that specific user can now not ssh to what was just built as their .ssh directory is not readable by them.

I can’t think of any other reason pip would be run as a user that doesn’t exist though, so it’s very much an edge case.


回答 3

如果您在DockerFile中具有python依赖项,请减小docker映像的大小,因为您的私有注册表/人工工厂或部署服务可能会有大小限制。

Reduce your docker image size if you’re having python dependencies in your DockerFile, as your private registries/artifactories or your deployment servcies may have size limitation.


回答 4

如果我不使用--no-cache-dir选项,则安装某些pip软件包时会出现权限错误。

Building wheels for collected packages: pyyaml, bottleneck, nvidia-ml-py3
  WARNING: Building wheel for pyyaml failed: [Errno 13] Permission denied: '/home/user/.cache/pip/wheels/b1'
  WARNING: Building wheel for bottleneck failed: [Errno 13] Permission denied: '/home/user/.cache/pip/wheels/92'
  WARNING: Building wheel for nvidia-ml-py3 failed: [Errno 13] Permission denied: '/home/user/.cache/pip/wheels/7f'

chown /.cache文件夹由于某种原因没有帮助,但--no-cache-dir可以正常工作。

I get permission error for installation of some pip packages if I don’t use --no-cache-dir option.

Building wheels for collected packages: pyyaml, bottleneck, nvidia-ml-py3
  WARNING: Building wheel for pyyaml failed: [Errno 13] Permission denied: '/home/user/.cache/pip/wheels/b1'
  WARNING: Building wheel for bottleneck failed: [Errno 13] Permission denied: '/home/user/.cache/pip/wheels/92'
  WARNING: Building wheel for nvidia-ml-py3 failed: [Errno 13] Permission denied: '/home/user/.cache/pip/wheels/7f'

chown /.cache folder didn’t help for some reason but with --no-cache-dir it works ok.