12

I have a project in which I have to install from git+https:

I can make it to work in this way:

virtualenv -p python3.5 bla
. bla/bin/activate
pip install numpy # must have numpy before the following pkg...
pip install 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'

However, I want to use it in a setup.py file in install_requires:

from setuptools import setup
setup(install_requires='git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI', setup_requires='numpy')

and then, pip install -e . from the dir containing the setup.py

This doesn't work due to parse error:

    Complete output (1 lines):                                                                                                             
    error in bla_bla setup command: 'install_requires' must be a string or list of strings containing valid project/version requireme
nt specifiers; Invalid requirement, parse error at "'+https:/'"                                                                             
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.  

The error doesn't occur if I install using pip install -r requires.txt (assuming I have the same string in that file) and not when using direct pip install git+......

How to fix this parsing error?

What I've tried so far:

  1. wrapping the string with " / """ / ' / '''
  2. adding 'r' before the string
Bram Vanroy
  • 27,032
  • 24
  • 137
  • 239
CIsForCookies
  • 12,097
  • 11
  • 59
  • 124
  • 1
    Does this answer your question? [How to write setup.py to include a git repo as a dependency](https://stackoverflow.com/questions/32688688/how-to-write-setup-py-to-include-a-git-repo-as-a-dependency) – Bram Vanroy Feb 26 '20 at 13:53
  • Related: https://stackoverflow.com/q/60370913/11138259 – sinoroc Feb 26 '20 at 14:51
  • @BramVanroy `dependency_links` were declared obsolete and finally [removed](https://setuptools.readthedocs.io/en/latest/setuptools.html#dependencies-that-aren-t-in-pypi) in `pip` 19.0. Please retract your vote. – phd Feb 26 '20 at 15:45
  • @phd It's the same core question, though, and answers on the duplicate question also answer this one (https://stackoverflow.com/a/54794506/1150683). – Bram Vanroy Feb 26 '20 at 16:10
  • @BramVanroy 4 out of 5 answers there mention `dependency_links`. The answers are outdated and should not be pointed at. – phd Feb 26 '20 at 16:12
  • 1
    @phd Updated this question to be specific about install_requires to better distinguish the questions and retracted my vote. – Bram Vanroy Feb 26 '20 at 16:14

1 Answers1

25

install_requires must be a string or a list of strings with names and optionally URLs to get the package from:

install_requires=[
    'pycocotools @ git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
]

See https://pip.pypa.io/en/stable/reference/requirement-specifiers/ and https://www.python.org/dev/peps/pep-0440/#direct-references

This requires pip install including pip install . and doesn't work with python setup.py install.

ZachB
  • 13,051
  • 4
  • 61
  • 89
phd
  • 82,685
  • 13
  • 120
  • 165
  • I'll add this reference for the `python setup.py install` vs. `pip install .` part: [comment from _pganssle_ in the discussion "Setuptools install fails with PEP508 URLs" in _setuptools_'s issue tracker](https://github.com/pypa/setuptools/issues/1983#issuecomment-584130062): "_Our policy to date has been that if using `pip install` fixes your problem, you should use `pip install` and we won't fix the issue_" – sinoroc Feb 26 '20 at 14:49
  • That sucks, because there is an inconsistency between `pip install "pkg_name" / pip install -r ` and `pip install -e .`. Thanks anyway! – CIsForCookies Feb 26 '20 at 14:57
  • @ClsForCookies What is the inconsistency? I believe if all the requirements follow _PEP 508_ and `setup.py` is not called directly then it should be consistent. – sinoroc Feb 26 '20 at 16:26
  • Can you tell what role does this part play in the command? `#subdirectory=PythonAPI` – Prince Mathur Aug 03 '21 at 08:25