简体   繁体   English

使用 pip 从 git 将 package 安装到站点包中

[英]Install package using pip from git into site-packages

I installed a Python package using pip from git.我使用来自 ZBA9F11ECC3497D1953B933FDC2BD 的 pip 安装了 Python package。 In order to achieve this, I added the command -e git+<link>#<egg> to my requirements.txt.为了实现这一点,我将命令-e git+<link>#<egg>添加到我的 requirements.txt 中。 Pip installs this package, but not in the way I would like to have it. Pip 安装了这个 package,但不是以我想要的方式。

First problem: I use a virtual environment.第一个问题:我使用虚拟环境。 Usually, packages end up in <env>/Lib/site-packages .通常,包以<env>/Lib/site-packages结尾。 This one does not, it ends up in <env>/src .这个没有,它最终出现在<env>/src中。 This makes it more to difficult to import.这使得导入变得更加困难。

Second problem: The src folder also gets created within my actual project, the one I am working on.第二个问题: src文件夹也在我正在处理的实际项目中创建。

Both things are different to installing packages from other sources like PyPI.这两件事都不同于从 PyPI 等其他来源安装软件包。 Is there a way to install my own packages via git in the same way?有没有办法以同样的方式通过 git 安装我自己的包? I actual built a wheel and a tar.gz, but I don't know how to install them...我实际上构建了一个轮子和一个 tar.gz,但我不知道如何安装它们......

@AnthonySottile's comment pointed me into the right direction: The -e option makes the installed package editable, which is not what I wanted. @AnthonySottile 的评论为我指明了正确的方向: -e选项使已安装的软件包可编辑,这不是我想要的。 It actually works without it!没有它它实际上可以工作! So if you want to avoid having src folders appearing everywhere - download from git without the -e option: git+<link>#<egg>因此,如果您想避免src文件夹出现在任何地方 - 从没有 -e 选项的git+<link>#<egg>下载: git+<link>#<egg>

Unfortunately, I didn't find any documentation for this ... so feel free to post a more profound answer or add to this one.不幸的是,我没有找到任何关于此的文档......所以请随时发布更深刻的答案或添加到这个答案。

The following format of specifying a git+https location in requirements.txt worked for me:在 requirements.txt 中指定 git+https 位置的以下格式对我有用:

pycocotools@git+https://github.com/gautamchitnis/cocoapi.git@cocodataset-master#subdirectory=PythonAPI

But I had to install numpy and Cython first, so that the installation of that package was successful.但是我必须先安装numpyCython ,这样才能成功安装 package。 setuptools was already installed, this might need attention too. setuptools已经安装,这可能也需要注意。

PS C:\Users\user\Documents\project> pip install -r requirements.txt
Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com, https://download.pytorch.org/whl/cu113
Collecting pycocotools@ git+https://github.com/gautamchitnis/cocoapi.git@cocodataset-master#subdirectory=PythonAPI
  Cloning https://github.com/gautamchitnis/cocoapi.git (to revision cocodataset-master) to c:\users\user\appdata\local\temp\pip-install-ofosrylu\pycocotools_6c865fdd5be947bdaed6b1bb6e7ec022
  Running command git clone -q https://github.com/gautamchitnis/cocoapi.git 'C:\Users\user\AppData\Local\Temp\pip-install-ofosrylu\pycocotools_6c865fdd5be947bdaed6b1bb6e7ec022'
  Running command git checkout -b cocodataset-master --track origin/cocodataset-master
  Branch 'cocodataset-master' set up to track remote branch 'cocodataset-master' from 'origin'.
  Switched to a new branch 'cocodataset-master'
# ... output of other packages
Building wheels for collected packages: pycocotools
  Building wheel for pycocotools (setup.py) ... done
  Created wheel for pycocotools: filename=pycocotools-2.0-cp39-cp39-win_amd64.whl size=82226 sha256=4fcb72a83132367541d71faa8f0fb5a838e910c017f9aa033d13c19aebaada61
  Stored in directory: C:\Users\user\AppData\Local\Temp\pip-ephem-wheel-cache-_ygd_748\wheels\a6\5f\ec\1eaf8c69abab5724baee819736e6d30adad774deb60736413b
Successfully built pycocotools

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 来自远程 git 存储库的 Package 更新未反映在站点包中 - Package updates from remote git repository are not reflected in site-packages 如何在特定 python 安装的站点包中通过 pip 安装 python 包? - How to Install a python package via pip in site-packages of specific python installation? Python pip站点包 - Python pip site-packages 将python包安装到相对于site-packages的目录中 - Install python package into directory relative to site-packages 通过下载并展开到站点包中手动安装 package - Install a package manually by downloading it and unfolding into site-packages 使用全局站点包pip停止virtualenv吗? - Stop virtualenv using global site-packages pip? 如何使用站点包中升级的 pip? - How to use upgraded pip from site-packages? pip想要从其他虚拟环境中卸载站点包 - pip wants to uninstall site-packages from a different virtual environment 如何从setuptools将文件安装到站点软件包(而不是软件包子文件夹)? - How do you install a file to site-packages (not package sub-folder) from setuptools? 如何安装不在virtualenv的站点软件包中的软件包,以及如何将命令从本地目录安装到Requirements.txt中? - How to install package not in site-packages of virtualenv and put command in requirements.txt that will install this package from local dir?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM