pythonazureazure-devopscommand-line-interfaceazure-artifacts

How to install private python package from Azure Artifact feed via CLI


I have setup a pypi feed in Azure Artifacts, but I can't seem to be able to authenticate via CLI to be able to install the python packages locally. I want to be able to just run pip install and provide the repo url but I can't get pass the login/verification step.

I have keyring and artifacts-keyring installed just like MS suggests, but whenever I try to pip install I get a prompt for User and Password like below:

C:\Users\user-name-here> pip install -r "url-to-feed-here" package-name
User for pkgs.dev.azure.com: <my MS/DevOps username>
Password: <my MS/DevOps password>
WARNING: 401 Error, Credentials not correct for feed-url-here
ERROR: 401 Client Error: Unauthorized for url: feed-url-here

that always fails to authenticate, and on remote servers via ssh it doesn't even indicate credentials were incorrect just that a 401 http message was returned.

What doesn't make sense to me is that I'm using the exact same user/password combo to sign into DevOps and create the feed, yet I can't use those credentials to pull packages from it? Does that mean MS has a different set of credentials one must setup to use this?

All the other questions I've seen have either been about using Pipelines, NuGet, or some other means than straight cli commands which doesn't help, because I want to be using the CLI and possibly scripting this out in something simple later on.


Solution

  • How to install private python package from Azure Artifact feed via CLI

    According to the document Get started with Python packages in Azure Artifacts, it provide two primary ways to connect to a feed to push or pull Python packages:

    Looks like you're using option1 from the document to do the install. I happen to get the same error as you if I use your install command line pip install -r "url-to-feed-here" package-name.

    But, if I use the command line from the document, it works fine:

    pip install <package-name> --index-url https://pkgs.dev.azure.com/<your-organization-name>/_packaging/<your-feed-name>/pypi/simple
    

    Note:

    The Python Credential Provider lets the pip and twine commands authenticate by sending you through an authentication flow in your web browser.

    My test result:

    enter image description here

    So, please try to use this command line to install private python package from Azure Artifact feed via CLI.

    Besides, you could also try to install the private python package by the second option.