如何指示 pip 使用 --no-binary 标志安装需求

Mii*_*ind 6 python pip

我有一个想要打包的应用程序,它依赖于protobuf. protobuf 必须这样安装:

pip install protobuf --no-binary=protobuf protobuf
Run Code Online (Sandbox Code Playgroud)

我怎样才能将其包含在我的中setup.py install_requires

注意:我的要求要求此过程自动通过 setup.py。

我知道这个这个

因此,我尝试在 install_requires 或requirements.txt 中包含这些内容,但没有成功:

#requirements.txt
protobuf
--no-binary=protobuf
Run Code Online (Sandbox Code Playgroud)

当我打包应用程序时,如何为安装提供--no-binary=protobuf protobuf(我知道是标志)?pipprotobuf

更新: 我想要的是按照我在安装软件包时提到的方式安装 protobuf 软件包:

`pip install my_package.whl`
Run Code Online (Sandbox Code Playgroud)

Rob*_*ard 3

使用requirements.txt文件安装

我想你可以简单地在同一行添加标志。这对我有用:

# requirements.txt

protobuf --no-binary protobuf
pandas
Run Code Online (Sandbox Code Playgroud)

这样requirements.txt,protobuf 就可以在没有二进制文件的情况下安装,而 pandas 仍然可以安装.whl.

通过运行pip install -r requirements.txt,你将得到类似的结果:

$ pip install -r requirements.txt 
Collecting pandas
  ...
Collecting protobuf
  Using cached protobuf-3.17.3.tar.gz (228 kB)
Skipping wheel build for protobuf, due to binaries being disabled for it.
Installing collected packages: protobuf, pandas
    Running setup.py install for protobuf ... done
Successfully installed pandas-1.1.5 protobuf-3.17.3
Run Code Online (Sandbox Code Playgroud)

自动安装在打包库内

如果您想包含对protobuf没有二进制文件的依赖项,并且您正在使用文件打包您的库,setup.py则可以package@http://link/to/package.tar.gzinstall_requires.setup

# requirements.txt

protobuf --no-binary protobuf
pandas
Run Code Online (Sandbox Code Playgroud)

该解决方案的缺点是它还指定了依赖项的版本。

希望这可以帮助 !