简体   繁体   English

当需要另一个 package 已经存在时,如何从 git 存储库构建安装 package?

[英]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.

相关问题 如何从带有 pip 的 git-lfs 内容的 git repo 安装 python 包? - How to install python package from git repo that has git-lfs content with pip? 如何从需要它的脚本中安装缺少的 python package? - How to install a missing python package from inside the script that needs it? 如何使用 pip install git +“git repo”重命名站点包? - How to rename the site-package using pip install git +“git repo”? 如何从具有dependency_links指向另一个Git存储库的Git存储库进行安装 - How to install from a Git repo which has dependency_links pointing to another Git repo 如何使用 pip -t 从 git 将 package 安装到特定目录中 - How to install a package from git into a specific directory using pip -t 如果它有多个子目录,如何从git安装pip包? - How to install a package with pip from git if it has multiple subdirectories? Debian 软件包从 Git 安装依赖项? - Debian package install Dependency from Git? 如何从 gitlab 包安装 pypi 包? - How to install pypi package from gitlab package? Install a python package using pip from private GitHub repo when building Docker image? - Install a python package using pip from private GitHub repo when building Docker image? 如何`pip install`一个包含Git依赖的包? - How to `pip install` a package that has Git dependencies?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM