python - 无法在 docker 容器内安装 pip azure-cognitiveservices-speech

标签 python azure docker pip text-to-speech

原始问题

我无法使用 pip 在 docker 容器中安装 azure-cognitiveservices-speech。我的容器运行良好,并且能够使用以下 dockerfile 安装所有其他软件包(例如 django、google-cloud-translate、boto3),没有任何问题。

原始 DockerFile

FROM python:3.8.2
ENV PYTHONUNBUFFERED=1

WORKDIR /code
COPY requirements.txt /code/
COPY . /code/
RUN pip install --no-cache-dir -r requirements.txt
COPY entrypoint.sh /code/entrypoint.sh
RUN chmod u+x /code/entrypoint.sh

原始要求.txt

amqp==5.0.2
asgiref==3.3.1
billiard==3.6.3.0
celery==5.0.4
click==7.1.2
click-didyoumean==0.0.3
click-plugins==1.1.1
click-repl==0.1.6
dj-database-url==0.5.0
Django==3.1.3
django-crispy-forms==1.9.2
django-filter==2.4.0
django-rest-auth==0.9.5
djangorestframework==3.12.2
kombu==5.0.2
Markdown==3.3.3
prompt-toolkit==3.0.8
psycopg2==2.8.6
pytz==2020.4
six==1.15.0
sqlparse==0.4.1
vine==5.0.0
wcwidth==0.2.5
google-cloud-translate==3.0.2
django-storages==1.9.1
gunicorn==20.0.4
boto3==1.16.43 

但是,当 azure-cognitiveservices-speech 添加到此列表时,我收到以下错误:

原始错误

ERROR: Could not find a version that satisfies the requirement azure-cognitiveservices-speech (from versions: none)
ERROR: No matching distribution found for azure-cognitiveservices-speech

我也尝试过指定模块的特定版本。

尝试的解决方案

我简化了 dockerfile 并指定在 Ubuntu 上运行,同时安装我从其他资源 ( https://github.com/Azure-Samples/cognitive-services-speech-sdk/issues/747 ) 读取的一些依赖项,这些依赖项可能是 azure-cognitiveservices-speech 包所必需的,但无济于事。

调整后的 DockerFile

FROM ubuntu:18.04

RUN mkdir /code
WORKDIR /code
RUN apt-get update && apt-get install -y \
    build-essential \
    libssl1.0.0 \
    libasound2 \
    python3.7

RUN apt-get install -y python3-pip
ADD requirements.txt /code/
RUN pip3 install --upgrade pip
RUN pip3 install azure-cognitiveservices-speech
ADD . /code/

我还在两个版本的 docker 容器中尝试了多个版本的 Python。 但是,我仍然收到上面看到的原始错误。

按照这个答案( Can't pip microsoft azure-cognitiveservices-speech? ),我已经运行了原始容器并进入终端,确认我正在运行合适的 64 位版本的 python。

# python -c "import struct; print(struct.calcsize('P') * 8)"
64

有人有解决方案/适当的环境来在容器中运行这个包吗?对于这个长问题,我深表歉意,我已经尝试了很多方法来安装这个软件包。我是否遗漏了一些基本的东西?

或者,是否有其他方法可以在不安装此软件包的情况下访问此 API?

其他信息

我在 M1 macbook pro 上运行此容器,但是我在较旧的 intel mac 上尝试过它,看看这是否是问题所在,但我仍然看到相同的错误。

最佳答案

所以我现在似乎终于开始工作了。老实说,我不确定我是否完全理解是什么最终导致这个 pip install 开始工作。然而,这是我的第一个问题,我认为最好只发布为我解决的问题,以防其他人遇到它。

Dockerfile

FROM --platform=linux/amd64 ubuntu:18.04 AS myubuntu
RUN mkdir /code
WORKDIR /code
RUN apt-get update && apt-get install -y \
    build-essential \
    libssl1.0.0 \
    libasound2 \
    python3.6

RUN apt-get install -y python3-pip
RUN pip3 install --upgrade pip
ADD . /code/
ENV LC_ALL=C.UTF-8 
ENV LANG=C.UTF-8
RUN pip3 install -r ./requirements.txt

似乎我需要指定平台(可能是 Apple M1 preview version of docker 的已知错误),安装 azure-cognitiveservices-speech 所需的 ubuntu 软件包,然后设置 ENV 变量,因为这也会导致错误.

然后构建镜像(指定 network=host),对其进行标记并在我的 docker-compose 文件中引用本地镜像。

docker build --network=host -t testinstall2 .
docker tag testinstall2:latest testinstall:staging

docker-compose.yml

version: "3.8"
   
services:
  db:
    # restart: always
    image: postgres:13.1
    environment:
      - POSTGRES_DB=
      - POSTGRES_USER=
      - POSTGRES_PASSWORD=
    volumes:
      - postgres_data:/var/lib/postgresql/data/
  web:
    image: testinstall:staging
    entrypoint: /code/entrypoint.sh
    volumes:
      - .:/code
    env_file: &envfile
      - SecretKeys/env.env
    ports:
      - "8000:8000"
    depends_on:
      - db
      - broker
  celery:
    image: testinstall:staging
    restart: "no"
    command : celery -A MyProject worker -l info
    env_file: *envfile
    volumes:
      - .:/code
    depends_on: 
      - db
      - broker
  celery-beat:
    image: testinstall:staging
    restart: "always"
    command: celery -A MyProject beat -l info
    env_file: *envfile
    volumes:
      - .:/code
    depends_on:
      - db
      - broker
  broker:
    image: rabbitmq:3
    env_file: *envfile
    ports: 
      - 5672:5672




volumes:
  postgres_data:

在此之后,我的所有容器和 celery 工作人员都按预期使用 azure 包运行。如果有人有任何想法,我仍然有兴趣了解到底是什么原因造成的!

关于python - 无法在 docker 容器内安装 pip azure-cognitiveservices-speech,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65656063/

相关文章:

python - 将 Python 中的打印列表转换回实际列表的最佳方法是什么

docker - 为什么有些 docker 镜像在运行时需要命令?

python - 如何在图像比例变大时围绕其中心旋转图像(在 Pygame 中)

python - 在 doxygen 代码片段中插入空行

azure - 错误 [405] 机器人中不允许使用方法 Microsoft Azure

azure - 如何从 Azure 中引用 SSL 证书

sql - 当我从 Azure 流作业插入数据时,如何在 CosmosDB 中使用 GUID 作为 ID

mongodb - 如何在docker镜像中访问mongorestore/mongodump

maven - Teamcity 中 maven 构建的 protoc 权限被拒绝

python - 在python中生成随机句子