[英]Pip install with requirements.txt from private repo prompting for password
I am trying to install a python package my_package
from a private Github repo using pip
.我正在尝试使用
pip
从私有 Github 存储库安装 python 包my_package
。 I am using Github oauth tokens (aka personal access tokens) for security.我正在使用 Github oauth 令牌(又名个人访问令牌)来保证安全。 My token is stored in the environment variable
$API_TOKEN
.我的令牌存储在环境变量
$API_TOKEN
中。
From the console if I do: pip install git+https://${API_TOKEN}@github.com/johnf1004/my_package.git
then it works perfectly.如果我这样做,请从控制台:
pip install git+https://${API_TOKEN}@github.com/johnf1004/my_package.git
然后它可以完美运行。
According to the documentation , you should be able to use environment variables inside requirements.txt
.根据文档,您应该能够在
requirements.txt
中使用环境变量。 However if I do pip install -r requirements.txt
where the file has the exact same address as above ( git+https://${API_TOKEN}@github.com/johnf1004/my_package.git
) then it fails with a password prompt.但是,如果我执行
pip install -r requirements.txt
,其中文件具有与上述完全相同的地址( git+https://${API_TOKEN}@github.com/johnf1004/my_package.git
),那么它会失败并提示密码. FWIW, even a correct password for my Github account still results in failure. FWIW,即使我的 Github 帐户的密码正确,仍然会导致失败。
Am I formatting the address/env variable wrong in the requirements file, or what am I missing?我是否在需求文件中错误地格式化了地址/环境变量,或者我缺少什么?
Rather than encoding your credentials (either directly or via an environment variable) into your requirements.txt
file, you should configure a credentials helper for git.与其将您的凭据(直接或通过环境变量)编码到您的
requirements.txt
文件中,不如为 git 配置凭据帮助程序。
Leave the bare URL in your requirements.txt
file:在您的
requirements.txt
文件中保留裸 URL:
git+https://github.com/johnf1004/my_package.git
Configure an appropriate credentials helper, such as the gh
cli .配置适当的凭据帮助程序,例如
gh
cli 。 In recent versions, you can run gh auth setup-git
to create the necessary configuration.在最近的版本中,您可以运行
gh auth setup-git
来创建必要的配置。
Run gh auth login
to authenticate to GitHub:运行
gh auth login
以向 GitHub 进行身份验证:
$ gh auth login
? What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations? SSH
? Upload your SSH public key to your GitHub account? Skip
? How would you like to authenticate GitHub CLI? Login with a web browser
! First copy your one-time code: ABCD-1234
Press Enter to open github.com in your browser...
Opening in existing browser session.
✓ Authentication complete.
- gh config set -h github.com git_protocol ssh
✓ Configured git protocol
✓ Logged in as larsks
Now git
will get credentials for https://github.com
URLs from gh
without requiring any interaction on your part.现在
git
将从gh
获取https://github.com
URL 的凭据,而无需您进行任何交互。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.