简体   繁体   English

如何从 GitHub gist 安装包?

[英]How do I install a package from GitHub gist?

I don't understand this...我不明白这...

I want to install this https://gist.github.com/sixtenbe/1178136 .我想安装这个https://gist.github.com/sixtenbe/1178136

It is a peak detection script for python.它是python的峰值检测脚本。

Everywhere I look I am told to use pip with the .git extension.我到处都被告知要使用带有 .git 扩展名的 pip。

All I see is how to download the .zip, but from there I am lost.我所看到的只是如何下载 .zip,但从那里我迷路了。

How can I install this?我该如何安装?

Thanks.谢谢。

You can get the individual files in the Gist (or download the Gist as an ZIP and extract) and put them in your source code folder.您可以获取 Gist 中的各个文件(或将 Gist 下载为 ZIP 并解压缩)并将它们放在您的源代码文件夹中。

Then you will be able to import them as modules in your own scripts:然后你就可以在你自己的脚本中将它们作为模块导入:

import analytic_wfm as AW
AW.ACV_A6( ... )

import peakdetect as PK
PK.peakdetect_parabola( ... )

Let's give it another look.让我们再看看。
By "installing a package" we might mean that the package should be available via import .通过“安装包” ,我们可能意味着该包应该可以通过import获得。
For that the package directory should reside either in the current directory or in one of the other directories in the import search path.为此,包目录应位于当前目录或导入搜索路径中的其他目录之一中。
One such directory is the "user-specific site-packages directory, USER_SITE" :一个这样的目录是“用户特定的站点包目录,USER_SITE”

python -c "import site; print(site.getusersitepackages())"

Git URL网址

First we might need a Git URL.首先,我们可能需要一个 Git URL。 Going to https://gist.github.com/sixtenbe/1178136 we can click on the Embed pop-up and switch it to Clone via HTTPS :转到https://gist.github.com/sixtenbe/1178136 ,我们可以单击Embed弹出窗口并Clone via HTTPS

在此处输入图像描述

in order to obtain the GIT URL: https://gist.github.com/1178136.git .为了获得 GIT URL: https://gist.github.com/1178136.git

git and bash git 和 bash

Having the Git URL and the Unix shell (bash) we can install the package manually into the USER_SITE.有了 Git URL 和 Unix shell (bash),我们可以手动将包安装到 USER_SITE。

Let's go into the USER_SITE first:我们先进入 USER_SITE:

cd $(python -c "import site; print(site.getusersitepackages())")
pwd

Now that we are in the USER_SITE, let's download the Gist:现在我们在 USER_SITE 中,让我们下载 Gist:

git clone https://gist.github.com/1178136.git analytic_wfm

Finally, let's verify that the package is now available:最后,让我们验证该包现在是否可用:

cd && python -c "import analytic_wfm.analytic_wfm; print(analytic_wfm.analytic_wfm.__all__)"

If numpy is installed, it prints如果安装了numpy ,它会打印

['ACV_A1', 'ACV_A2', 'ACV_A3', 'ACV_A4', 'ACV_A5', 'ACV_A6', 'ACV_A7', 'ACV_A8']

pip点子

Let's try to install a Gist package with pip .让我们尝试使用pip安装一个 Gist 包。
For pip install we should prefix the Git URL with git+ :对于pip install我们应该在 Git URL 前面加上git+

pip install --user git+https://gist.github.com/1178136.git

This gives us the error:这给了我们错误:

ERROR: git+https://gist.github.com/1178136.git does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found.错误:git+https://gist.github.com/1178136.git 似乎不是 Python 项目:既未找到“setup.py”也未找到“pyproject.toml”。

Looks like the package we've picked is missing the necessary pip configuration!看起来我们选择的包缺少必要的pip配置!

Let's try another one :让我们尝试另一个

pip install --user git+https://gist.github.com/bf91613a021a536c7ce16cdba9168604.git

Installs NP:安装 NP:

Successfully built llog
Installing collected packages: llog
Successfully installed llog-1.0

Particularly because it has the setup.py .特别是因为它有setup.py

Note also that Gist does not support subfolders, and pip seems to depend on them in handling the packages argument, but the code in setup.py can workaround this by creating the package subfolder on the fly and copying the Python files there!另请注意,Gist 不支持子文件夹,并且pip似乎在处理packages参数时依赖它们,但setup.py中的代码可以通过动态创建包子文件夹并在那里复制 Python 文件来解决此问题!

Hence if you want to import that Gist, https://gist.github.com/sixtenbe/1178136 , with the rest of the requirements.txt dependencies, - you can fork it and add setup.py to the effect.因此,如果您想导入该 Gist, https ://gist.github.com/sixtenbe/1178136,以及其余的requirements.txt依赖项,您可以分叉它并添加setup.py效果。

pypi皮皮

Given that the analytic-wfm can also be found at the Python Package Index, https://pypi.org/project/analytic-wfm/ , you can install it with鉴于analytic-wfm也可以在 Python 包索引https://pypi.org/project/analytic-wfm/中找到,您可以使用

pip install analytic-wfm

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM