【问题标题】:Python 'Queue' not defined in docker container but works on hostPython 'Queue' 未在 docker 容器中定义,但可在主机上运行
【发布时间】:2020-03-17 09:02:35
【问题描述】:

我有一个运行 Queue 对象的 Python API,定义为:

from queue import Queue    
frame_queue = Queue(maxsize = 0)

我使用 conda run 命令在 conda 环境中运行它:

conda run -n my_env python my_api.py

当这个命令在主机上运行时,它可以完美运行,但是当它在容器上运行时(在容器镜像的 Dockerfile 中指定,它会记录以下错误:

Traceback (most recent call last):
  File "queue_api.py", line 13, in <module>
    frame_queue = Queue(maxsize = 0)
NameError: name 'Queue' is not defined

【问题讨论】:

  • docker 中的 Python 版本?
  • 我使用 continuumio/anaconda 作为我的基础镜像。我刚刚检查过,它使用 Python 2.7
  • Python2 已停产。请升级

标签: python docker conda


【解决方案1】:

在 python 3 中使用 anaconda docker 镜像。 可以用continuumio/anaconda3代替continuumio/anaconda

错误源于python版本的不同,在Python 3.x中是import Queue as queue;,而在Python 2.x中是import queue

ImportError: No module named 'Queue'

【讨论】:

    猜你喜欢
    • 2019-05-09
    • 1970-01-01
    • 2019-08-25
    • 1970-01-01
    • 2019-10-13
    • 2020-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多