我正在尝试使用 pip
的私人github存储库中安装python软件包 my_package
。我正在使用Github Oauth令牌(又称个人访问令牌)来安全。我的令牌存储在环境变量 $ api_token
中。
如果我这样做,请从控制台上:
pip install git+https:// $ {api_token}@github.com/johnf1004/my_package.git
根据 documentation ,,,,,,,,,,,您应该能够在 unigess.txt
内使用环境变量。但是,如果我做 pip install -r unigess.txt
,文件的地址与上述完全相同( git+https:// $ {api_token}@github.com/johnf1004/my_package .git
)然后使用密码提示符失败。 FWIW,即使是我的GitHub帐户的正确密码仍然会导致故障。
我是在需求文件中格式化的地址/ENV变量错误,还是我缺少什么?
I am trying to install a python package my_package
from a private Github repo using pip
. I am using Github oauth tokens (aka personal access tokens) for security. My token is stored in the environment variable $API_TOKEN
.
From the console if I do:
pip install git+https://${API_TOKEN}@github.com/johnf1004/my_package.git
then it works perfectly.
According to the documentation, you should be able to use environment variables inside 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. FWIW, even a correct password for my Github account still results in failure.
Am I formatting the address/env variable wrong in the requirements file, or what am I missing?
发布评论
评论(1)
而不是将您的凭据(直接或通过环境变量)编码
suppiect.txt
文件,而是应该配置凭证助手用于git。将裸露的URL留在您的
unignts.txt
文件:配置适当的凭据助手,例如 GH CLI 。在最近的版本中,您可以运行
gh auth setup-git
来创建必要的配置。运行
GH auth Login
以对GitHub进行身份验证:现在
git
将获得https://github.com
urls的凭据。 /代码>不需要您的任何互动。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.Leave the bare URL in your
requirements.txt
file:Configure an appropriate credentials helper, such as the
gh
cli. In recent versions, you can rungh auth setup-git
to create the necessary configuration.Run
gh auth login
to authenticate to GitHub:Now
git
will get credentials forhttps://github.com
URLs fromgh
without requiring any interaction on your part.