How to use --extra-index-url in requirements.txt in python?

发布时间 2023-03-27 17:16:39作者: 天外归云

[本文出自天外归云的博客园]

以下内容来自chatGPT的回答(正解,已验证)

问题1:how to use --extra-index-url in requirements.txt in python?

To use `--extra-index-url` in `requirements.txt` in Python, you need to follow these steps:

1. Open `requirements.txt` in a text editor.

2. Add the `--extra-index-url` option followed by the URL of the extra index you want to use. Separate multiple URLs with commas.

   Example:

   ```

   --extra-index-url https://custom.internal.pypi.org/simple/

   ```

3. Add the package(s) you want to install from the extra index.

   Example:

   ```

   requests==2.25.1

   custom-package==1.0.0

   ```

4. Save the `requirements.txt` file.

5. Install the packages using `pip` and include the `--extra-index-url` option.

   Example:

   ```

   pip install -r requirements.txt --extra-index-url https://custom.internal.pypi.org/simple/

   ```

This will install the packages from both the default index and the extra index specified in the `requirements.txt` file.

问题2:how to use multiple --extra-index-url in requirements.txt in python?

You can use multiple `--extra-index-url` options in your `requirements.txt` file by specifying each URL separated by a space. Example:


--extra-index-url URL1 --extra-index-url URL2

In this example, `URL1` and `URL2` should be replaced with the actual URLs you want to use as extra index URLs for package installation.

Here's an example of `requirements.txt` file that uses multiple extra index URLs:


--extra-index-url https://pypi.org/simple
--extra-index-url https://some.custom.repo/simple
package1==1.0.0
package2==2.0.0

In this example, the `package1` and `package2` packages will be installed from either the default PyPI repository or the `some.custom.repo` repository depending on their availability.