Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format requirements.txt when package source is from specific websites?

I am trying to convert the following installation commands using pip that downloads from another website, into a requirements.txt format, but just can't figure out how. Can anyone assist?

pip install torch==1.5.0+cu101 torchvision==0.6.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html

pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/index.html
like image 738
Jake Avatar asked May 12 '20 00:05

Jake


People also ask

How do I add an index URL to requirements txt?

To add the azure artifacts index to the install command, we've added --extra-index-url https://pkgs.dev.azure.com/<org>/_packaging/mypackage/pypi/simple/ at the top of the requirements. txt file and added the mypackage package to the requirements. txt list.

Where should I place requirements txt?

Typically the requirements. txt file is located in the root directory of your project. Notice we have a line for each package, then a version number. This is important because as you start developing your python applications, you will develop the application with specific versions of the packages in mind.


Video Answer


1 Answers

The structure of the contents of a requirements.txt file is defined as follows:

[[--option]...]
<requirement specifier> [; markers] [[--option]...]
<archive url/path>
[-e] <local project path>
[-e] <vcs project url>

The <requirement specifier> defines the package and an optional version.

SomeProject
SomeProject == 1.3
SomeProject >=1.2,<2.0
SomeProject[foo, bar]
SomeProject~=1.4.2

The --option (such as the -f/--find-links) is the same as the pip install options you would use if you were doing pip install from the command line.

The following options are supported:

  • -i, --index-url
  • --extra-index-url
  • --no-index
  • -c, --constraint
  • -r, --requirement
  • -e, --editable
  • -f, --find-links
  • --no-binary
  • --only-binary
  • --require-hashes
  • --pre
  • --trusted-host

So, for your install commands, the requirements.txt would look like this:

# Torch
--find-links https://download.pytorch.org/whl/torch_stable.html
torch==1.5.0+cu101
torchvision==0.6.0+cu101

# Detectron
--find-links https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/index.html
detectron2

Make sure to verify that the links are correctly used:

$ pip install -r requirements.txt 
Looking in links: https://download.pytorch.org/whl/torch_stable.html, https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/index.html
Collecting torch==1.5.0+cu101 (from -r requirements.txt (line 3))
  Using cached https://download.pytorch.org/whl/cu101/torch-1.5.0%2Bcu101-cp38-cp38-linux_x86_64.whl
Collecting torchvision==0.6.0+cu101 (from -r requirements.txt (line 4))
  Using cached https://download.pytorch.org/whl/cu101/torchvision-0.6.0%2Bcu101-cp38-cp38-linux_x86_64.whl
Collecting detectron2 (from -r requirements.txt (line 8))
  Using cached https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/detectron2-0.1.2%2Bcu101-cp38-cp38-linux_x86_64.whl
...

As a side note, you originally said "(not github)" in your title. The default source of packages installed using pip is hosted on PyPi: https://files.pythonhosted.org/. You can see the actual links when going to the Download Files section of a package in PyPi (example for Torch).

like image 160
Gino Mempin Avatar answered Sep 18 '22 20:09

Gino Mempin