Configuring Python Environments

Once you have obtained the repository URL, your environment must be configured to use the URL to download and install packages.

pip

To configure pip globally for all projects, use the pip config command to set the global.index-url to your repository URL:

Terminal
pip config set global.index-url https://packagemanager.posit.co/pypi/latest/simple
Tip

If using virtual environments with venv, activate your virtual environment first, then run the pip config command above to set the Package Manager repository for that specific environment. Refer to Installing packages using pip and virtual environments in the Python documentation for more information.

requirements.txt

To use a Package Manager repository with a specific project defined by a requirements.txt file, add -i [repositoryURL] to the top of your file, for example:

requirements.txt
-i https://packagemanager.posit.co/pypi/latest/simple
pandas
scipy
...

Authenticated Repositories

If your Package Manager repository requires authentication, you can configure Python to use a .netrc file for credentials.

This method is widely supported and provides a secure way to access authenticated repositories in Python. It can be used with various tools, including pip.

You can also use the system keyring to store your credentials. See the pip documentation for more information.

Getting a token

Your Package Manager administrator can provide you with a token to use for authentication. See Creating API Tokens for details.

Configure Python to use .netrc

  1. Create a .netrc file in your home directory at ~/.netrc.

    Add the following content, replacing [packagemanager.example.com] with your Package Manager server address and [your-token] with your actual token.

    ~/.netrc
    machine [packagemanager.example.com]
    login __token__
    password [your-token]

    The machine field should not contain a protocol, port, or repository path. If your repository URL is https://packagemanager.example.com/pypi/latest, use packagemanager.example.com for the machine field.

  2. Since the credentials are stored in plaintext, ensure that the ~/.netrc file is only accessible to you by running:

    Terminal
    chmod 600 ~/.netrc
  1. Create a .netrc file in your home directory at ~/.netrc.

    Add the following content, replacing [packagemanager.example.com] with your Package Manager server address and [your-token] with your actual token.

    ~/.netrc
    machine [packagemanager.example.com]
    login __token__
    password [your-token]

    The machine field should not contain a protocol, port, or repository path. If your repository URL is https://packagemanager.example.com/pypi/latest, use packagemanager.example.com for the machine field.

  2. Since the credentials are stored in plaintext, ensure that the ~/.netrc file is only accessible to you by running:

    Terminal
    chmod 600 ~/.netrc
  1. Create a .netrc file in your home directory at ~/.netrc. On Windows, this location should be your Windows user folder (typically C:\Users\[user], where [user] is your Windows username).

    Add the following content, replacing [packagemanager.example.com] with your Package Manager server address and [your-token] with your actual token.

    ~/.netrc
    machine [packagemanager.example.com]
    login __token__
    password [your-token]

    The machine field should not contain a protocol, port, or repository path. If your repository URL is https://packagemanager.example.com/pypi/latest, use packagemanager.example.com for the machine field.

Note

.netrc files only support configuring a single set of credentials per server. This means that if you have multiple repositories, you need to use the same token for all of them. The token must have access to each repository.

Back to top