简体   繁体   English

Pip冻结不显示需求文件的存储库路径

[英]Pip freeze does not show repository paths for requirements file

I've created an environment and added a package django-paramfield via git: 我创建了一个环境并通过git添加了一个包django-paramfield:

$ 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? 如何让它输出整个字符串git+https://bitbucket.org/DataGreed/django-paramfield.git而不仅仅是包名? The package isn't in PyPi. 该软件包不在PyPi中。

UPD : perhaps, it has to do something with setup.py? UPD :也许,它必须用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. UPD2 :我在stackoverflow中发现了一个类似的问题 ,但是作者不确定他是如何设法解决问题的,并且不幸的是,接受的答案没有给出好的暗示,尽管从作者的评论来看它与它有关setup.py文件。

UPD3 : I've tried to pass download_url in setup.py and installing package via pip with this url, but he problem persists. UPD3 :我试图在setup.py中传递download_url并通过pip使用此url安装包,但问题仍然存在。

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 . 一个简单但有效的解决方法是使用-e标志安装包,如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. 然后pip freeze显示包的完整源路径。 It's not the best way it should be fixed in pip but it's working. 它不是应该在pip中修复的最佳方式,但它正在工作。 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. 权衡-e (编辑标志)是pip将git / hg repo克隆到/path/to/venv/src/packagename并运行python setup.py deploy而不是将其克隆到temp目录并运行python setup.py install在安装包之后python setup.py install和删除临时目录。

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()

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 这是一个老问题,但我刚刚解决了同样的问题和解决方案只需将repo的路径(在我的情况下为git)添加到需求fie而不是包名称

ie

...
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 工作就像在heroku上的魅力

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM