This quickstart shows you how to set up a private Artifact Registry Python repository, upload a package, and then install the package.
Before you beginIn the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.Verify that billing is enabled for your Google Cloud project.
Enable the Artifact Registry API.
Make sure that you have the following role or roles on the project: Artifact Registry Administrator
Check for the rolesIn the Google Cloud console, go to the IAM page.
Go to IAMIn the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
In the Google Cloud console, go to the IAM page.
Go to IAMIn the New principals field, enter your user identifier. This is typically the email address for a Google Account.
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.Verify that billing is enabled for your Google Cloud project.
Enable the Artifact Registry API.
Make sure that you have the following role or roles on the project: Artifact Registry Administrator
Check for the rolesIn the Google Cloud console, go to the IAM page.
Go to IAMIn the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
In the Google Cloud console, go to the IAM page.
Go to IAMIn the New principals field, enter your user identifier. This is typically the email address for a Google Account.
In this quickstart, you will use Cloud Shell, which is a shell environment for managing resources hosted on Google Cloud.
Cloud Shell comes preinstalled with the Google Cloud CLI and Python. The gcloud CLI provides the primary command-line interface for Google Cloud.
Launch Cloud Shell:
Go to Google Cloud console.
On the Google Cloud console toolbar, click Activate Cloud Shell:
A Cloud Shell session opens inside a frame lower on the console. You use this shell to run gcloud
commands.
Twine is a tool for publishing Python packages. You'll use Twine to upload a package to Artifact Registry.
In this quickstart, you use the Python installation included with Cloud Shell. This default installation includes the Artifact Registry keyring backend: to handle authentication with Artifact Registry. If you create a virtual environment or set up Python outside of Cloud Shell, you must install the keyring backend for authentication. For details, see Authenticating with keyring.
To install Twine, run the command:
pip install twine
You are now ready to set up Artifact Registry.
Create a repositoryCreate the repository for your packages.
Run the following command to create a new Python package repository in the current project named quickstart-python-repo
in the location us-central1
.
gcloud artifacts repositories create quickstart-python-repo \
--repository-format=python \
--location=us-central1 \
--description="Python package repository"
Run the following command to verify that your repository was created:
gcloud artifacts repositories list
To simplify gcloud
commands, set the default repository to quickstart-python-repo
and the default location to us-central1
. After the values are set, you do not need to specify them in gcloud
commands that require a repository or a location.
To set the repository, run the command:
gcloud config set artifacts/repository quickstart-python-repo
To set the location, run the command:
gcloud config set artifacts/location us-central1
For more information about these commands, see the gcloud config set documentation.
The Artifact Registry keyring backend finds your credentials using Application Default Credentials (ADC), a strategy that looks for credentials in your environment.
In this quickstart, you'll:
GOOGLE_APPLICATION_CREDENTIALS
environment variable.pip
and twine
commands so that you do not need to configure pip and Twine with the repository URL.To generate credentials for ADC, run the following command:
gcloud auth application-default login
For details on authentication methods and adding repositories to pip and Twine configuration, see Setting up authentication to Python package repositories.
Obtain an example packageWhen you build a Python project, distribution files are saved in a dist
subdirectory in your Python project. To simplify this quickstart, you will download prebuilt package files.
Create a Python project folder named python-quickstart
.
mkdir python-quickstart
Create a subdirectory named dist
and then change to the directory.
mkdir python-quickstart/dist
cd python-quickstart/dist
Download the sample Python packages that are used in the Python Packaging User Guide tutorial Packaging Python Projects.
pip download sampleproject
The command downloads the sampleproject
package and its dependency, peppercorn
.
Use Twine to upload your packages to your repository.
From the dist
directory, change to the parent python-quickstart
directory.
cd ..
Upload the packages to the repository from your dist
directory.
python3 -m twine upload --repository-url https://us-central1-python.pkg.dev/PROJECT_ID/quickstart-python-repo/ dist/*
When you run the command with python3 -m
, Python locates twine and runs the command. If the twine
command is in your system path, you can run it without python3 -m
.
Twine uploads both sampleproject
and peppercorn
to your repository.
To verify that your package was added, list the packages in the quickstart-python-repo
repository.
Run the following command:
gcloud artifacts packages list --repository=quickstart-python-repo
To view versions for a package, run the following command:
gcloud artifacts versions list --package=PACKAGE
Where PACKAGE is the package ID.
Install the packageRun the following command to install the package:
pip install --index-url https://us-central1-python.pkg.dev/PROJECT_ID/quickstart-python-repo/simple/ sampleproject
Troubleshooting
By default, tools such as pip and Twine do not return detailed error messages. If you encounter an error, rerun the command with the --verbose
flag to get more detailed output. See Troubleshooting for Python packages for more information.
To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.
Before you remove the repository, ensure that any packages you want to keep are available in another location.
To delete the repository:
To delete the quickstart-python-repo
repository, run the following command:
gcloud artifacts repositories delete quickstart-python-repo
If you want to remove the default repository and location settings that you configured for the active gcloud
configuration, run the following commands:
gcloud config unset artifacts/repository
gcloud config unset artifacts/location
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4