【问题标题】:Python 2 Script to Python 3 in a Docker Container :: "No module named 'Queue'"Python 2 Script to Python 3 in a Docker Container :: \"No module named \'Queue\'\"
【发布时间】:2022-12-27 23:43:01
【问题描述】:

I have a Python 2 script that I'm trying to run within the latest Python docker container. That container supports Python 3, and I thought could manually adapt the script. My manual adaptations worked just fine... except for this:

The original Python 2 script contained this line:

from multiprocessing import Queue, Manager, Lock

But thanks to post like this and this, I know that "Queue" isn't a Python 3 module; the module I need is "queue". So I changed my code to this:

import queue
from multiprocessing import Manager, Lock

When I spin up my container then run the script (within the container), I get this:

Traceback (most recent call last):
  File "/usr/local/bin/myscript", line 4, in <module>
    __import__('pkg_resources').run_script('myscript==0.1.0', 'myscript')
  File "/usr/local/lib/python3.9/site-packages/pkg_resources/__init__.py", line 651, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/local/lib/python3.9/site-packages/pkg_resources/__init__.py", line 1455, in run_script
    exec(script_code, namespace, namespace)
  File "/usr/local/lib/python3.9/site-packages/myscript-0.1.0-py3.9.egg/EGG-INFO/scripts/myscript", line 21, in <module>
  File "<frozen zipimport>", line 259, in load_module
  File "/usr/local/lib/python3.9/site-packages/myscript-0.1.0-py3.9.egg/openbmp/myscript/logger.py", line 15, in <module>
ModuleNotFoundError: No module named 'Queue'

The above makes little sense to me; here's the referenced part of the script, with line numbers included:

15 import sys
16 import signal
17 #from multiprocessing import queue, Manager, Lock
18 import queue
19 from multiprocessing import Manager, Lock
20
21 from myscript.logger import LoggerThread

Ugh. The Docker container is adding as extra layer of complexity and I don't understand what's going on.

More experienced programmers: Is there a suitable fix here? Or should I just give up and use the Python 2 Docker container? Thank you.

【问题讨论】:

    标签: python docker module version


    【解决方案1】:

    In your error message it says;

    ModuleNotFoundError: No module named 'Queue'
    

    "Queue" isn't a Python 3 module; the module I need is "queue"

    Somehow, your code is stilling running this line:

    from multiprocessing import Queue, Manager, Lock
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-13
      • 1970-01-01
      • 2018-03-08
      • 2017-02-10
      • 2022-12-19
      • 1970-01-01
      • 2022-12-27
      • 2022-08-24
      相关资源
      最近更新 更多