21

I've created an environment and added a package django-paramfield via git:

$ pip install git+https://bitbucket.org/DataGreed/django-paramfield.git
Downloading/unpacking git+https://bitbucket.org/DataGreed/django-paramfield.git
  Cloning https://bitbucket.org/DataGreed/django-paramfield.git to /var/folders/9Z/9ZQZ1Q3WGMOW+JguzcBKNU+++TI/-Tmp-/pip-49Eokm-build
Unpacking objects: 100% (29/29), done.
  Running setup.py egg_info for package from git+https://bitbucket.org/DataGreed/django-paramfield.git
Installing collected packages: paramfield
  Running setup.py install for paramfield
Successfully installed paramfield
Cleaning up...

But when i want to create a requirements file, i see only the package name:

$ pip freeze
paramfield==0.1
wsgiref==0.1.2

How can I make it output the whole string git+https://bitbucket.org/DataGreed/django-paramfield.git instead of just a package name? The package isn't in PyPi.

UPD: perhaps, it has to do something with setup.py? Should I change it somehow to reflect repo url?

UPD2: I found quite a similar question in stackoverflow, but the author was not sure how did he manage to resolve an issue and the accepted answer doesn't give a good hint unfortunately, though judging from the author's commentary it has something to do with the setup.py file.

UPD3: I've tried to pass download_url in setup.py and installing package via pip with this url, but he problem persists.

Community
  • 1
  • 1
DataGreed
  • 13,245
  • 8
  • 45
  • 64

3 Answers3

19

A simple but working workaround would be to install the package with the -e flag like pip install -e git+https://bitbucket.org/DataGreed/django-paramfield.git#egg=django-paramfield.

Then pip freeze shows the full source path of the package. It's not the best way it should be fixed in pip but it's working. The trade off -e (editing flag) is that pip clones the git/hg repo into /path/to/venv/src/packagename and run python setup.py deploy instead of clone it into a temp dir and run python setup.py install and remove the temp dir after the setup of the package.

Hengjie
  • 4,598
  • 2
  • 30
  • 35
Jarus
  • 1,748
  • 2
  • 13
  • 22
  • Thanks, that really is a possible workaround, but I believe the right syntax for this is pip install -e git+https://bitbucket.org/DataGreed/django-paramfield.git#egg=paramfield - but what does -e flag exactly do? Specify a directory to install the package? – DataGreed Jul 24 '12 at 13:24
3

Here's a script that will do that:

#!/usr/bin/env python

from subprocess import check_output
from pkg_resources import get_distribution

def download_url(package):
    dist = get_distribution(package)
    for line in dist._get_metadata('PKG-INFO'):
        if line.startswith('Download-URL:'):
            return line.split(':', 1)[1]


def main(argv=None):
    import sys
    from argparse import ArgumentParser

    argv = argv or sys.argv

    parser = ArgumentParser(
        description='show download urls for installed packages')
    parser.parse_args(argv[1:])

    for package in check_output(['pip', 'freeze']).splitlines():
        print('{}: {}'.format(package, download_url(package) or 'UNKNOWN'))


if __name__ == '__main__':
    main()
SingleNegationElimination
  • 151,563
  • 33
  • 264
  • 304
Miki Tebeka
  • 13,428
  • 4
  • 37
  • 49
1

This is an old question but I have just worked through this same issue and the resolution Simply add the path to the repo (git in my case) to the requirements fie instead of the package name

i.e.

...
celery==3.0.19
# chunkdata isn't available on PyPi
https://github.com/aaronmccall/chunkdata/zipball/master
distribute==0.6.34
... 

Worked like a charm deplying on heroku

Morgan
  • 11
  • 2