[英]How to install a package from git repo build when it needs another package to be already present?
I am trying to deploy my app to Streamlit
and it requires detectron2
.我正在尝试将我的应用程序部署到
Streamlit
,它需要detectron2
。 I had to install detectron2
using我必须使用安装
detectron2
python -m pip install 'git+https://github.com/facebookresearch/detectron2.git'
It requires torch
to be already present as it'll throw an error there and then.它要求
torch
已经存在,因为它会在那里引发错误。
so when I did, pip freeze requirements.txt
, the snippet looks like:所以当我这样做时,
pip freeze requirements.txt
,片段看起来像:
torch==1.12.1
torchaudio==0.12.1
torchvision==0.13.1
detectron2 @ git+https://github.com/facebookresearch/detectron2.git@717ab9f0aeca216a2f800e43d705766251ba3a55
so when I pip install -r requirements.txt
, it gives me error as:所以当我
pip install -r requirements.txt
,它给我的错误是:
Collecting detectron2@ git+https://github.com/facebookresearch/detectron2.git@717ab9f0aeca216a2f800e43d705766251ba3a55
Cloning https://github.com/facebookresearch/detectron2.git (to revision 717ab9f0aeca216a2f800e43d705766251ba3a55) to /tmp/pip-install-60odo0ml/detectron2_3c0ef1b35e7b42cd95cfd938e09dd4d5
Running command git clone --filter=blob:none --quiet https://github.com/facebookresearch/detectron2.git /tmp/pip-install-60odo0ml/detectron2_3c0ef1b35e7b42cd95cfd938e09dd4d5
Running command git rev-parse -q --verify 'sha^717ab9f0aeca216a2f800e43d705766251ba3a55'
Running command git fetch -q https://github.com/facebookresearch/detectron2.git 717ab9f0aeca216a2f800e43d705766251ba3a55
Resolved https://github.com/facebookresearch/detectron2.git to commit 717ab9f0aeca216a2f800e43d705766251ba3a55
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [6 lines of output]
Traceback (most recent call last):
File "<string>", line 36, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/tmp/pip-install-60odo0ml/detectron2_3c0ef1b35e7b42cd95cfd938e09dd4d5/setup.py", line 10, in <module>
import torch
ModuleNotFoundError: No module named 'torch'
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
Not a great work but I found a kind of way around it.不是一个伟大的工作,但我找到了一种解决它的方法。 So I just removed
detectron2
from requirements.txt
and installed at runtime using subprocess
inside app.py
.所以我只是从
requirements.txt
中删除detectron2
,并在运行时使用app.py
中的subprocess
进程安装。 Not recommended but it just did the work for me.不推荐,但它只是为我工作。 Please suggest a better way to do it.
请提出一个更好的方法来做到这一点。 Thanks:)
谢谢:)
try:
from detectron2.config import get_cfg
except ModuleNotFoundError:
import subprocess
import sys
subprocess.check_call([sys.executable, "-m", "pip", "install", 'git+https://github.com/facebookresearch/detectron2.git'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.