让我们再看看。
“安装一个包”我们可能意味着这个包应该可以通过import获得。
为此,包目录应位于当前目录或导入搜索路径中的其他目录之一中。
一个这样的目录是"user-specific site-packages directory, USER_SITE":
python -c "import site; print(site.getusersitepackages())"
Git 网址
首先我们可能需要一个 Git URL。转到https://gist.github.com/sixtenbe/1178136我们可以点击Embed弹窗并切换到Clone via HTTPS:
为了获取 GIT URL:https://gist.github.com/1178136.git。
git 和 bash
有了 Git URL 和 Unix shell (bash),我们可以手动将包安装到 USER_SITE。
让我们先进入 USER_SITE:
cd $(python -c "import site; print(site.getusersitepackages())")
pwd
现在我们在 USER_SITE 中,让我们下载 Gist:
git clone https://gist.github.com/1178136.git analytic_wfm
最后,让我们验证一下这个包现在是否可用:
cd && python -c "import analytic_wfm.analytic_wfm; print(analytic_wfm.analytic_wfm.__all__)"
如果安装了numpy,它会打印
['ACV_A1', 'ACV_A2', 'ACV_A3', 'ACV_A4', 'ACV_A5', 'ACV_A6', 'ACV_A7', 'ACV_A8']
点
让我们尝试使用pip 安装 Gist 包。
对于pip install,我们应该在Git URL 前面加上git+:
pip install --user git+https://gist.github.com/1178136.git
这给了我们错误:
错误:git+https://gist.github.com/1178136.git 似乎不是
Python 项目:未找到“setup.py”和“pyproject.toml”。
看起来我们选择的包缺少必要的pip 配置!
我们试试another one:
pip install --user git+https://gist.github.com/bf91613a021a536c7ce16cdba9168604.git
安装 NP:
Successfully built llog
Installing collected packages: llog
Successfully installed llog-1.0
特别是因为它有setup.py。
另请注意,Gist 不支持子文件夹,pip 似乎在处理 packages 参数时依赖它们,但 setup.py 中的代码可以通过动态创建包子文件夹并复制那里有 Python 文件!
因此,如果您想导入该 Gist,https://gist.github.com/sixtenbe/1178136,以及其余的 requirements.txt 依赖项,您可以fork它并添加 setup.py 到效果中。
pypi
鉴于analytic-wfm 也可以在 Python 包索引https://pypi.org/project/analytic-wfm/ 中找到,您可以使用以下命令安装它
pip install analytic-wfm