Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 未使用pip在docker容器内安装包_Python_Docker_Docker Compose - Fatal编程技术网

Python 未使用pip在docker容器内安装包

Python 未使用pip在docker容器内安装包,python,docker,docker-compose,Python,Docker,Docker Compose,我对docker compose面临的一个奇怪问题感到困惑。requirements.txt文件中的某些软件包的Pip安装失败 docker版本 Client: Version: 18.09.9 API version: 1.39 Go version: go1.13.4 Git commit: 1752eb3 Built: Sat Nov 16 01:05:26 2019 OS/Arch:

我对docker compose面临的一个奇怪问题感到困惑。requirements.txt文件中的某些软件包的Pip安装失败

docker版本

Client:
 Version:           18.09.9
 API version:       1.39
 Go version:        go1.13.4
 Git commit:        1752eb3
 Built:             Sat Nov 16 01:05:26 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server:
 Engine:
  Version:          18.09.9
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.13.4
  Git commit:       9552f2b
  Built:            Sat Nov 16 01:07:48 2019
  OS/Arch:          linux/amd64
  Experimental:     false
我的
docker compose.yml
文件是:

version: "3.7"

services:

  flask:
    build: ./flask
    container_name: flask
    restart: always
    environment:
      - APP_NAME=MyFlaskApp
    expose:
      - 8080

  nginx:
    build: ./nginx
    container_name: nginx
    restart: always
    ports:
      - "80:80"
./flask目录中
Dockerfile
的内容是:

# Use the Python3.7.5 image
FROM python:3.7.5

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
ADD . /app

# Install the dependencies
RUN pip3 install -r requirements.txt

# run the command to start uWSGI
CMD ["uwsgi", "app.ini"]
我的
requirements.txt
文件是(前几行):

但是,当我运行
docker compose up
命令时,它无法在
requirements.txt
文件中安装第二个包

Building flask
Step 1/6 : FROM python:3.7.5
 ---> fbf9f709ca9f
Step 2/6 : WORKDIR /app
 ---> Using cache
 ---> 39ab3ee34991
Step 3/6 : ADD . /app
 ---> Using cache
 ---> 8968809ff844
Step 4/6 : RUN python3 -m pip install --upgrade pip
 ---> Using cache
 ---> 15f717de5181
Step 5/6 : RUN pip3 install -r requirements.txt
 ---> Running in 7068f09498dc
Collecting appdirs==1.4.3
  Downloading appdirs-1.4.3-py2.py3-none-any.whl (12 kB)
ERROR: Could not find a version that satisfies the requirement apturl==0.5.2 (from -r requirements.txt (line 2)) (from versions: none)
ERROR: No matching distribution found for apturl==0.5.2 (from -r requirements.txt (line 2))
ERROR: Service 'flask' failed to build: The command '/bin/sh -c pip3 install -r requirements.txt' returned a non-zero code: 1
我尝试了很多可能的选择,但没有用。例如:

  • 在容器内运行pip升级
  • 根据线程更新docker中的DNS

  • @WilliamD.Irons已经指出,
    apturl
    是一个包,您可以使用:

    RUN apt install apturl
    RUN pip3 install -r requirements.txt
    

    并从您的
    requirements.txt

    中删除
    apturl
    ,因为@WilliamD.Irons已经指出
    apturl
    是一个包,您可以使用:

    RUN apt install apturl
    RUN pip3 install -r requirements.txt
    
    并从
    requirements.txt
    apturl
    中删除
    apturl
    ,这是一个客户端Ubuntu程序,用于在网页中添加对
    等链接的支持:

    apturl
    是一个图形化的小程序,用于从用户拥有的存储库中安装软件包。它是从7.10版开始预装在Ubuntu上的,Firefox和Pidgin程序都支持它

    此外,在Ubuntu之外也没有对它的支持。由于官方的
    python:3.7.5
    图像是基于
    Debian GNU/Linux
    的,因此无论如何这都不可用

    我想问一下,为什么你的Flask应用程序需要这样做,因为你应该能够编写自己的python函数来在应用程序中生成兼容的链接。任何从受支持的客户端点击这些链接的人(上面提到的任何带有Firefox的Ubuntu框)都应该能够成功处理这些链接。

    apturl
    一个客户端Ubuntu程序,用于在网页中添加对链接的支持,如

    apturl
    是一个图形化的小程序,用于从用户拥有的存储库中安装软件包。它是从7.10版开始预装在Ubuntu上的,Firefox和Pidgin程序都支持它

    此外,在Ubuntu之外也没有对它的支持。由于官方的
    python:3.7.5
    图像是基于
    Debian GNU/Linux
    的,因此无论如何这都不可用


    我想问一下,为什么你的Flask应用程序需要这样做,因为你应该能够编写自己的python函数来在应用程序中生成兼容的链接。任何人从受支持的客户端(上面提到的任何带有Firefox的Ubuntu框)点击这些链接都应该能够成功处理这些链接。

    如果使用基本容器不是问题,请尝试Ubuntu环境并安装python。
    apturl
    是由ubuntu提供的,特别是它使用了
    apt

    # Use the ubuntu
    FROM ubuntu:lts
    
    
    # Set the working directory to /app
    WORKDIR /app
    
    # install python and pip, and delete cache
    RUN apt update && apt install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
    
    # Copy the current directory contents into the container at /app
    ADD . /app
    
    # Install the dependencies
    RUN pip3 install -r requirements.txt
    
    # run the command to start uWSGI
    CMD ["uwsgi", "app.ini"]
    

    如果使用基本容器不是问题,请尝试Ubuntu环境并安装python。
    apturl
    是由ubuntu提供的,特别是它使用了
    apt

    # Use the ubuntu
    FROM ubuntu:lts
    
    
    # Set the working directory to /app
    WORKDIR /app
    
    # install python and pip, and delete cache
    RUN apt update && apt install -y python3 python3-pip && rm -rf /var/lib/apt/lists/*
    
    # Copy the current directory contents into the container at /app
    ADD . /app
    
    # Install the dependencies
    RUN pip3 install -r requirements.txt
    
    # run the command to start uWSGI
    CMD ["uwsgi", "app.ini"]
    

    看起来像。这在非Docker环境下工作吗?我认为这个问题与Docker无关,您不能pip安装apturl,因为pypi不提供它。请参阅:@DavidMaze是的,它在Ubuntu主机上工作。相同的requirements.txt在docker环境之外工作。这在非Docker环境下工作吗?我认为这个问题与Docker无关,您不能pip安装apturl,因为pypi不提供它。请参阅:@DavidMaze是的,它在Ubuntu主机上工作。相同的requirements.txt在docker环境之外工作。