首页 > 解决方案 > 从源代码安装 pip 无需构建轮子

问题描述

我有一个包含大型 PyTorch 模型检查点的 Python 包。我尝试将那些包含在我setup.py的 as

package_data = {'mypackage': ['model_weights/*', 'model_weights/sequential_models*']},

现在的问题是,每当我尝试从源代码安装时,pip install mypackage/ --no-cache-dir我都会得到一个MemoryError. 我尝试调试--verbose并意识到这发生在

creating '/tmp/pip-wheel-bs29bp6a/tmpp0itbxn1/mypackage-1.0-py3-none-any.whl' and adding 'build/bdist.linux-x86_64/wheel' to it
adding 'mypackage/model_weights/distilled_model.pt'
adding 'mypackage-1.0.dist-info/RECORD'
Traceback (most recent call last):
...
File "/zhome/1d/8/153438/miniconda3/envs/testenv/lib/python3.9/zipfile.py", line 1127, in write
      data = self._compressor.compress(data)
MemoryError
Building wheel for mypackage (PEP 517) ... error
ERROR: Failed building wheel for mypackage

我真的只希望安装将文件复制model_weights/到安装目录中。将它们包括在轮子中似乎是不可能的。

有没有办法在运行时抑制这一步pip install?该包将仅作为源分发,永远不会在 PyPI 上分发,因为model_weights无论如何文件都太大了。

标签: pythonpippytorchsetuptools

解决方案


你可以跑

$ pip install mypackage/ --no-cache-dir --no-binary=mypackage

跳过轮子构建(假设mypackage实际上是您的发行版名称 - 这是您传递namesetup()功能的名称)。


推荐阅读