'pip freeze' fails with BadCommand if vcs program is not found
Although mechanisms are in place to catch errors in the get_src_requirement() path, a BadCommand exception reaches the top-level and makes pip unusable if any package is found that has a .git directory and 'git' is not installed (or not in path).
I think this should be caught and a warning displayed in pip.vcs:get_src_requirement() instead, allowing the program to continue.
> python -m pip -v freeze
Cannot find command 'git'
Exception information:
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\pip\basecommand.py", line 139, in main
status = self.run(options, args)
File "C:\Python27\lib\site-packages\pip\commands\freeze.py", line 73, in run
req = pip.FrozenRequirement.from_dist(dist, dependency_links, find_tags=find_tags)
File "C:\Python27\lib\site-packages\pip\__init__.py", line 181, in from_dist
req = get_src_requirement(dist, location, find_tags)
File "C:\Python27\lib\site-packages\pip\vcs\__init__.py", line 249, in get_src_requirement
return version_control().get_src_requirement(dist, location, find_tags)
File "C:\Python27\lib\site-packages\pip\vcs\git.py", line 155, in get_src_requirement
repo = self.get_url(location)
File "C:\Python27\lib\site-packages\pip\vcs\git.py", line 123, in get_url
[self.cmd, 'config', 'remote.origin.url'],
File "C:\Python27\lib\site-packages\pip\vcs\__init__.py", line 110, in cmd
command = find_command(self.name)
File "C:\Python27\lib\site-packages\pip\util.py", line 107, in find_command
raise BadCommand('Cannot find command %r' % cmd)
BadCommand: Cannot find command 'git'
My attempt is here: remram44:pip (vcs-not-found) BUT I don't know what I'm doing.
This is still affecting me.
This happened to me today and I agree that it should be a warning, not a critical error. I feel shouldn't have to scour out .git folders or install non-pip package managers to get basic info from pip freeze, but I could be overlooking some important reason why git is crucial to listing Python modules that weren't installed via git—it's just that this essentially makes git a dependency for pip.
My patch is probably correct or really close, come on, surely somebody knows something about pip and can spare a minute to review it...
@remram44 If you want a review, could you make a PR from your patch? I'll take a look. But I'm not entirely sure how you have a git checkout without git installed, so it's not clear to me how to reproduce this issue.
I just verified that @remram44 patch fixes the problem on Windows 7 system without git.
@pfmoore You can reproduce the issue by installing pip as recommended in the doc (get-pip.py) on a system without git or with git binary not in PATH. If you then replace pip/cvs/__init__.py with @remram44 's version (I did raw download of the whole file from GitHub), it prints a warning but goes on with freeze command.
@washeck You mean I get this error without needing to install any packages? There's more to it than that as I just did a test with git not on my PATH and pip freeze works fine.
Sorry, I was not diligent enought. I did the test on my developement workstation with quite some packages installed, one of them being a git repository. The reason for such a strange setup is that we do the development in cygwin (so my git binary is the cygwin one) but the python application runs in Windows shell with Python, pip, etc. installed as normal Window setup (completely separated from cygwin).
With @remram44 fix, pip freeze prints
cannot determine version of editable source in c:\python26\lib\site-packages\celery.git (git command not found in path)
and then goes on with the list of installed packages.
So now I understand why you talked about git checkout without git installed. Anyway, to reproduce it, you can just copy a git repository from somewhere else and place it on PYTHONPATH.
OK, thanks. I can see why that would fail.
Of course, the output of "pip freeze" won't be much use if it doesn't include all the requirements. So what is your use case for pip freeze not including an installed project (even if it is a VCS checkout)? (Note, I'm not against the PR, just want to understand the use case)
Well, our usecase (maybe not the optimal solution, but anyway) is to deployinternally developed code with custom deployment solution and for the dependencies use "pip install -r requirements.txt" on the production systems. To update the requirements.txt I run "pip freeze" on my workstation and remove the VCS checkouts. With the PR I can at least see there is there is something from VCS, even though I don't get details. Btw, while the value of incomplete "pip freeze" is questionable, I think that for for "pip list" it is quite obvious that the warning message is much useful than failure without listing the rest of packages.
Which PR are we talking about? I can't see it referenced in this thread.
@Ivoz - still waiting for the OP to prepare a PR. @washeck - if this applies to pip list then I agree it's much more of a concern.
The fix is a single commit https://github.com/remram44/pip/commit/ed42ae662f79eb56821a5ac4f8b06e9a1b2e99bd We just need @remram44 to make it a PR.
Submitted as #1828.
@remram44 Thanks. I've commented on the PR but could you rebase it please? It needs to be automatically mergeable for Travis to be able to run the tests for us. Thanks.
Patch looks good (some style fixes needed, but I'll do that).
@pypa/pip-developers anyone have any problem with this? It seems like a reasonable fix to me.
@pfmoore LGTM