Pip freeze does not show repository paths for requ

2019-02-05 20:29发布

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.

3条回答
干净又极端
2楼-- · 2019-02-05 21:20

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

查看更多
甜甜的少女心
3楼-- · 2019-02-05 21:23

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.

查看更多
The star\"
4楼-- · 2019-02-05 21:30

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()
查看更多
登录 后发表回答