Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

[Cloud Build]: Unable to fetch packages from Pypi Artifact Registry on another project

While deploying a gen2 Cloud Function the following cloud build is unable to fetch any python packages (public and/or private).

The cloud build service account that gets used has the necessary Artifact Registry roles (Writer, Reader). 

Both projects are also a part of a Shared VPC and the requirements.txt file contains 
"--index-url https://europe-west1-python.pkg.dev/<other-project-name>/virtual-pypi/simple".

```

ERROR: Could not find a version that satisfies the requirement pydantic==2.* (from versions: none)
```

And other private packages also fail.

Any suggestions are welcomed!

0 1 559
1 REPLY 1

Hi @jcraps,

Welcome to Google Cloud Community!

The error message you are encountering indicates that your Cloud Build environment can't find a compatible version of the pydantic library (specifically within the major version 2 range). This is likely due to a combination of factors related to how you're configuring your build environment and how you're accessing packages.

Here are some suggestions that might help resolve the issue you're encountering:

  1. Check PyPI compatibility
    • Verify that 'pydantic' package versions are compatible with '2.*' which are available on PyPI (Python Package Index). You can do this by visiting the Pydantic page. Ensure that versions start with '2.' are listed.
  2. Specify the exact version: 
    • Here is an example of a Cloud Build configuration cloudbuild.yaml that specifies an exact version of 'pydantic':
      steps:
        - name: 'python:3.9'
          entrypoint: pip
          args:
            - install
            - pydantic==2.8.2  
            - ...

      Note: Replace '2.8.2' with an exact version that you verified exists on PyPI. This ensures that Cloud Build can find a specific version that matches your requirement.

  3. Update pip and setuptools:
    • If you're having trouble fetching packages, it could be because the versions of pip and setuptools on your system are outdated. To avoid this, make sure to include the following commands in your Cloud Build steps to upgrade them:
      steps:
      - name: 'python:3.9'  # Or your preferred Python version
        entrypoint: 'bash'
        args:
          - '-c'
          - |
            # Upgrade pip first
            pip install --upgrade pip 
            # Upgrade setuptools
            pip install --upgrade setuptools
      
  4. Network Issues:
    • If Cloud Build is unable to access PyPI due to network restrictions or issues, it might fail to fetch packages. Check if there are any network restrictions in place that could be blocking access.
  5. Retry Build:
    • Sometimes, if you are experiencing package fetching failures, this could be due to temporary issues. Please try running Cloud Build again.

I hope the above information is helpful for you.