1

How can I specify a local git repo as a dependency in requirements.txt so that I can install it with pip install -r requirements.txt? The issue is not that I am unable to install or clone from that location, but how to escape the spaces in the path to the repo directory in the requirements.txt. To be completely clear, both cloning and pip installing work by enclosing the path in ", it only fails with pip install -r.

I have tried

  • git+"K:/my/path with/lots of/spaces/repo/.git"

  • git+git://"K:/my/path with/lots of/spaces/repo/.git"

  • git+git:"//K:/my/path with/lots of/spaces/repo/.git"

  • git+"git://K:/my/path with/lots of/spaces/repo/.git"

  • "K:/my/path with/lots of/spaces/repo/.git"

  • git+file://K:/my/path\ with/lots\ of/spaces/repo/.git

But in every case I receive the error ValueError: No closing quotation.

If I try to escape the spaces with \ it is interpreted as a Windows Path separator and fails.

EDIT:

So the following works:

pip install git+file:///"k/my/path with/lots of/spaces/repo/.git/"

However, when I put the exact same thing into my requirements.txt (without pip install, of course), I get the ValueError: No closing quotation. Any ideas on how to solve this would be highly appreciated. Is it something I should open an issue with pip for?

lukas
  • 121
  • 7
  • Have you read the [docs](https://pip.pypa.io/en/stable/reference/pip_install/#vcs-support). You need a branch name at least. – Pedro Rodrigues Oct 02 '19 at 11:57
  • 2
    Possible duplicate of [pip install from git repo branch](https://stackoverflow.com/questions/20101834/pip-install-from-git-repo-branch) – Pedro Rodrigues Oct 02 '19 at 11:57
  • If I specify a branch name I get the same error. I am able to clone the repo with `git clone "K:/my/path with/lots of/spaces/repo/.git"`. How is this a duplicate? It's not about a specific branch at all. – lukas Oct 02 '19 at 12:56
  • @PedroRodrigues not a duplicate: this deals with a local file path, not something from github or bitbucket (which all the answers on that question show). – 9769953 Oct 18 '19 at 09:08
  • Is this the only line in your `requirements.txt` file, or are there other lines (with possible quotes) in that file? – 9769953 Oct 18 '19 at 09:14
  • @00 there are more lines in there, but all of them are "normal" dependencies from pypi so without quotes. – lukas Oct 18 '19 at 09:17
  • try `git+file:///k/my/path with/lots of/spaces/repo/.git/`, *without* quotes. The quotes are necessary to escape the shell breaking up the path by whitespace, but Python, and thus pip, when reading the requirements file, will read the whole line as a single string, and not break it by space. – 9769953 Oct 18 '19 at 09:24
  • Aside: that is the weirdest path I've seen in a while: starts with `/k/` a the root, and has a hidden subdirectory `.git/` which apparently contains the actual repository, even if the directory above that is called `repo/` (I can only assume there is also a `.svn/` subdir somewhere). Usually, the `.git/` subdirectory is reserved for git, and implicit when installing directory from a git repository. – 9769953 Oct 18 '19 at 09:26
  • There is no `.svn` directory anywhere, this is indeed a `git` repo. This is a Windows path and I "converted" it according to the answer to [this](https://stackoverflow.com/questions/21045061/git-clone-from-another-directory) question. If there is a better/more concise way, I'm all ears. – lukas Oct 18 '19 at 09:57
  • Without quotes the path is broken at the first space, so it tries to clone from `git+file:/k/my/path`. – lukas Oct 18 '19 at 09:58
  • 1
    You mean broken when used inside the requirements file? Because testing on my side doesn't show that. – 9769953 Oct 18 '19 at 11:09
  • Yes, without quotation marks, so `requirements.txt` contains `git+file:///k/my/path with/lots of/spaces/repo/.git/`. After `pip install -r requirements.txt`: `ERROR: Command "git clone -q git+file:///k/my/path 'C:\Users\username\AppData\Local\Temp\1\pip-req-build-1gzemqen'" failed with error code 128 in None` – lukas Oct 18 '19 at 11:32
  • I wonder if this is something intrinsic to Windows then; I could only test it on a Mac, where this worked. – 9769953 Oct 18 '19 at 14:22

1 Answers1

2

I'm quoting user chrahunt here who answered to the issue on GitHub.

The handling of quotes when pip is executed directly is governed by your shell. In Bash, for example, non-nested pairs of quotes are stripped and their contents concatenated with what comes before/after to create each argument.

Requirements files, on the other hand, are read as-is by optparse and no special quote handling or stripping takes place.

That said, in this case when trying to provide a URL, the non-valid URL characters (like space) must be percent-encoded (space is %20).

So in my case, I had to change the requirements.txt entry to git+file:///k/my/path%20with/lots%20of/spaces/repo/.git/ and it worked. This should not be platform dependent and %20 should work everywhere.

Community
  • 1
  • 1
lukas
  • 121
  • 7