[英]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.但是我必须先安装
numpy
和Cython
,这样才能成功安装 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.