3

On my OSX M1 Mac I have the following keyring setup which works with Google Artifact Repository to resolve dependencies when using python on the command line shell. Refer to https://cloud.google.com/artifact-registry/docs/python/store-python

$ keyring --list-backends         
keyring.backends.chainer.ChainerBackend (priority: 10)
keyring.backends.fail.Keyring (priority: 0)
keyring.backends.macOS.Keyring (priority: 5)
keyrings.gauth.GooglePythonAuth (priority: 9)

If I try to install the dependencies from within PyCharm it does not work automatically, it prompts for a user as can be seen. I expected it to resolve the dependencies automatically from my already authenticated account. How to get PyCharm to work with Google Artifact Repository?

Prompt for username for Google Artifact Repository

Phil
  • 46,436
  • 33
  • 110
  • 175

2 Answers2

1

Based on your description, I suppose you have successfully set up the Python virtual environment (venv) and installed all the dependencies via the terminal (Step 1-4 in https://cloud.google.com/artifact-registry/docs/python/store-python). And you want PyCharm also run your Python codes using that virtual environment.

Usually, PyCharm will create a new Python virtual environment or use the default Python interpreter on your machine when you first open a project. That is why you will have to install the dependencies again.

In order to make PyCharm run your project using the venv you have created earlier (through the command line), go to the Setting -> Project: your-project-name -> Python interpreter -> Add -> Choose Existing environment -> Hit ... -> Navigate to the the venv folder you created -> Select venv/bin/python.exe or venv/bin/python3.exe or venv/bin/python.

After that PyCharm will run your project using the existing virtual environment, and you don't have to install everything again. I am from Upwork, by the way.

0

It's basically the same as what you found already on your link but you missed the following site :)

  1. Setup service account with roles/artifactregistry.writer rights
  2. Create key file (json file with your credentials) using gcloud iam service-accounts keys create FILE_NAME.json --iam-account=SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com
  3. After this you can follow the following website. Setting up authentication to Python package repositories
Jordy van Eijk
  • 2,718
  • 2
  • 19
  • 37
  • I'm within a company and I cannot create a service account, I can only gcloud application auth login, also it already works for command line, it doesn't work for Pycharm, can you instructions work for Pycharm? – Phil May 21 '22 at 00:19
  • Hi @Phil I also use the application auth login atm because the service account had some issues. But it looks like Pycharm can't coop with private registries that require username and password – Jordy van Eijk May 25 '22 at 13:29
  • Does application auth login with private repo work with pycharm for you? – Phil May 25 '22 at 23:47