如何在Dockerfile中本地安装pip包?

我想从github克隆一个python包,然后用pip -e在本地安装它,如下所示:

 RUN git clone https://github.com/st4lk/django-rest-social-auth.git RUN pip install -e django-rest-social-auth 

但我收到错误消息:

 Step 6 : RUN pip install -e django-rest-social-auth ---> Running in 8943e688573f Traceback (most recent call last): File "/usr/bin/pip", line 9, in <module> load_entry_point('pip==1.5.6', 'console_scripts', 'pip')() File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 356, in load_entry_point return get_distribution(dist).load_entry_point(group, name) File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2476, in load_entry_point return ep.load() File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2190, in load ['__name__']) File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 74, in <module> from pip.vcs import git, mercurial, subversion, bazaar # noqa File "/usr/lib/python2.7/dist-packages/pip/vcs/mercurial.py", line 9, in <module> from pip.download import path_to_url File "/usr/lib/python2.7/dist-packages/pip/download.py", line 25, in <module> from requests.compat import IncompleteRead ImportError: cannot import name IncompleteRead 

怎么了?


完整的Dockerfile供参考:

 FROM debian:jessie ADD . /workflows # Install dependencies RUN apt-get update && apt-get install -y \ git \ python-django \ python-psycopg2 \ python-django-celery \ rabbitmq-server \ python-django-jsonfield \ python-pip RUN pip install djangorestframework \ python-social-auth RUN git clone https://github.com/st4lk/django-rest-social-auth.git RUN pip install -e django-rest-social-auth # Get everything ready and run RUN python /workflows/manage.py validate RUN python /workflows/manage.py collectstatic --noinput CMD python /workflows/manage.py runserver 0.0.0.0:8000 

IncompleteRead名称已从https://github.com/kennethreitz/requests/commit/47d0517d66e8cf5832768262221f0357ae134ad1中&#x7684; requests.compat中删除。

完成Dockerfile的这一部分之后…

 RUN apt-get update && apt-get install -y \ git \ python-django \ python-psycopg2 \ python-django-celery \ rabbitmq-server \ python-django-jsonfield \ python-pip 

你有请求版本2.4.3和点1.5.6。 这两个都很古老。 当你下次运行pip install

 RUN pip install djangorestframework \ python-social-auth 

…这将您的请求包升级到2.9.1,它不再与图像中安装的旧版pip兼容。

您可以通过安装较新版本的pip来避免此问题。 而不是安装python-pip软件包,只需使用easy_install来获取pip

 RUN apt-get update && apt-get install -y \ git \ python-django \ python-psycopg2 \ python-django-celery \ rabbitmq-server \ python-django-jsonfield RUN easy_install pip 

这将安装最新版本的pip ,这个版本可以在您安装后续Python模块所需的安装请求版本的情况下成功运行。