簡體   English   中英

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

[英]How to install a pip package locally in Dockerfile?

我正在嘗試從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名字從取出requests.compathttps://github.com/kennethreitz/requests/commit/47d0517d66e8cf5832768262221f0357ae134ad1

在完成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模塊安裝所需的請求版本一起成功運行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM