如何使用额外的依赖项安装GitHub的Python软件包,但没有“ git”?
我正在寻找一个单线线,可以通过 pip
从Github安装Python软件包,而无需安装 git
,并且能够指定额外的依赖项。
这就是我尝试的(当我在Windows上时,无需逃脱 []
):
pip install https://github.com/python/mypy/archive/master.zip[reports]
以下 di di di di di 工作,第一个从此答案:
# requires a git client to be installed
pip install -e git+https://github.com/python/mypy.git#egg=mypy[reports]
# omits extra dependencies
pip install https://github.com/python/mypy/archive/master.zip
但是它们具有评论中指出的各种限制。
对于初始命令,我得到了
Collecting https://github.com/python/mypy/archive/master.zip[reports]
ERROR: HTTP error 404 while getting https://github.com/python/mypy/archive/master.zip[reports]
ERROR: Could not install requirement https://github.com/python/mypy/archive/master.zip[reports] because of HTTP error 404 Client Error: Not Found for url: https://github.com/python/mypy/archive/master.zip%5Breports%5D for URL https://github.com/python/mypy/archive/master.zip[reports]
(我知道这不应使用 setuptools_scm
,例如, psf/black
,因此不应适用于包装。 “ https://github.com/pypa/setuptools_scm/blob/ca38555ba66fa4cb100f5039eea909932f815a4a4a4/src/setsrc/setsrc/setuptools_scm/__init __init__init__init__init__init_.py#l106-l106-l106-l106-l115 re =” UpTools_scm . py#l106-l115
/blob/ca38555ba666fa4cb100f5039eea909932f815a4a4a4/src/strc/setuptoopools_scm /__ init __
pip install "mypy[reports] @ https://github.com/python/mypy/archive/master.zip"
有什么更直观的吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道您是在要求一个单线,但让我首先描述针对GIT存储库(不仅仅是GitHub)的常见解决方法,该解决方案也避免了需要Git:
WGET
或curl
或任何可以使用的shell或脚本实用程序例如,在Mypy的GitHub中,您可以获得最新的 master ,一个特定的标签 v0.950 ,或选择其他任何一个发布标签。
。
例如,来自Black的GitHub,来自 22.3.0释放页面 ,获取 22.3.0源代码
python -m pip install ...
stytax 选择特定的特定环境和解释器M PIP安装... 语法使用常规
pip install
以这样的git回购, ... 2。如果添加a /
- 详细信息
选项,您会看到它首先从特定的提交中夹住代码的副本,然后将它们存储在某些临时目录中(我们不适合通常关心),然后从那里进行定期安装。示例Mypy:
因此,如果您没有git,则不能执行
git克隆
,而是必须手动下载代码。与DirectPIP Install
一样,如果您不在乎特定版本,则可以下载最新的Master
/main
commit:再次为mypy进行示例:
那么最后一步将只是在做
pip install
,它支持定位< local project path>
and 指定额外功能所有命令中的全部命令:因此,遵循下载和拆卸
mypy> mypy-master
上面的最后一步,只是简单地是:...显示与
pip install
-ED直接从git+https
的输出相同的输出。使用pip install
使用相同的注意事项,例如,如果您使用的是虚拟环境,请确保首先激活该问题,以便将mypy安装在同一位置。现在,为了使其成为一个单线命令,您可以将这些步骤转换为脚本,外壳别名,或者只是直接上升使用
&&
操作员运行多个命令:请注意,在命令末尾,我添加了对临时文件/文件夹的删除。如果其中一个步骤失败(例如,网络连接错误),则其余命令将被中止。您可以根据需要添加更好的/更多错误处理。
我同意 不是优雅或直观的命令。
I know you are asking for a one-liner, but let me describe first the common workaround to targeting Git repositories (not just Github) that also avoids requiring git:
wget
orcurl
or whichever shell or script-able utility is availableFor example, from mypy's Github, you can get the latest master, a specific tag v0.950, or choose any of the other release tags.
For example, from black's Github, from the 22.3.0 release page, get the 22.3.0 source codes
python -m pip install ...
syntax to select a specific environment and interpreterWith regular
pip install
targeting a Git repo like this,...it automatically already does steps 1 and 2. If you add a
-v
/--verbose
option, you'll see that it clones a copy of the codes first from a specific commit, and stores them in some temporary directory (which we don't normally care about), then does the regular installation from there.Sample for mypy:
So, if you don't have Git, you can't do a
git clone
, but instead have to download the codes manually. As with the directpip install
, if you don't care about a specific version, you can just download the latestmaster
/main
commit:Sample again for mypy:
Then the last step would simply be doing
pip install
, which supports targetting a<local project path>
and specifying extras all in one command:So following the downloaded and unpacked
mypy-master
above, the last step would simply be:...which shows the same output as the one that
pip install
-ed directly fromgit+https
. The same considerations with usingpip install
applies, for example, if you are using a virtual environment, make sure to activate that first so mypy is installed in the same location.Now, to make it all a one-liner command, you can turn those steps into a script, a shell alias, or just straight-up run multiple commands with
&&
operator:Note that I added removal of the temporary files/folders at the end of the command. If one of the steps fails (ex. network connection error), then the rest of the commands will be aborted. You can add better/more error-handling as needed.
I agree though that that isn't an elegant or an intuitive command.