Skip to main content
ModuleNotFoundError No module named '_ctypes'

背景

在 Linux 上运行 celery,执行 celery -A _celery worker -l INFO 的时候报错

/root/.pyenv/versions/3.8.0/envs/python-3.8.0/lib/python3.8/site-packages/celery/platforms.py:829: SecurityWarning: You're running the worker with superuser privileges: this is
absolutely not recommended!

Please specify a different user using the --uid option.

User information: uid=0 euid=0 gid=0 egid=0

  warnings.warn(SecurityWarning(ROOT_DISCOURAGED.format(
 
 -------------- celery@DESKTOP-I2O884V v5.4.0 (opalescent)
--- ***** ----- 
-- ******* ---- Linux-5.15.153.1-microsoft-standard-WSL2-x86_64-with-glibc2.34 2024-07-18 10:32:43
- *** --- * --- 
- ** ---------- [config]
- ** ---------- .> app:         spiders:0x7f0aa7fda520
- ** ---------- .> transport:   redis://localhost:6379/0
- ** ---------- .> results:     redis://
- *** --- * --- .> concurrency: 16 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** ----- 
 -------------- [queues]
                .> celery           exchange=celery(direct) key=celery


[tasks]
  . _celery.tasks.add
  . _celery.tasks.multiplication
  . _celery.tasks.xsum

[2024-07-18 10:32:43,612: CRITICAL/MainProcess] Unrecoverable error: ModuleNotFoundError("No module named '_ctypes'")
Traceback (most recent call last):
  File "/root/.pyenv/versions/3.8.0/envs/python-3.8.0/lib/python3.8/site-packages/celery/worker/worker.py", line 202, in start
    self.blueprint.start(self)
  File "/root/.pyenv/versions/3.8.0/envs/python-3.8.0/lib/python3.8/site-packages/celery/bootsteps.py", line 116, in start
    step.start(parent)
  File "/root/.pyenv/versions/3.8.0/envs/python-3.8.0/lib/python3.8/site-packages/celery/bootsteps.py", line 365, in start
    return self.obj.start()
  File "/root/.pyenv/versions/3.8.0/envs/python-3.8.0/lib/python3.8/site-packages/celery/concurrency/base.py", line 130, in start
    self.on_start()
  File "/root/.pyenv/versions/3.8.0/envs/python-3.8.0/lib/python3.8/site-packages/celery/concurrency/prefork.py", line 109, in on_start
    P = self._pool = Pool(processes=self.limit,
  File "/root/.pyenv/versions/3.8.0/envs/python-3.8.0/lib/python3.8/site-packages/celery/concurrency/asynpool.py", line 464, in __init__
    super().__init__(processes, *args, **kwargs)
  File "/root/.pyenv/versions/3.8.0/envs/python-3.8.0/lib/python3.8/site-packages/billiard/pool.py", line 1045, in __init__
    self._create_worker_process(i)
  File "/root/.pyenv/versions/3.8.0/envs/python-3.8.0/lib/python3.8/site-packages/celery/concurrency/asynpool.py", line 482, in _create_worker_process
    return super()._create_worker_process(i)
  File "/root/.pyenv/versions/3.8.0/envs/python-3.8.0/lib/python3.8/site-packages/billiard/pool.py", line 1141, in _create_worker_process
    on_ready_counter = self._ctx.Value('i')
  File "/root/.pyenv/versions/3.8.0/envs/python-3.8.0/lib/python3.8/site-packages/billiard/context.py", line 177, in Value
    from .sharedctypes import Value
  File "/root/.pyenv/versions/3.8.0/envs/python-3.8.0/lib/python3.8/site-packages/billiard/sharedctypes.py", line 10, in <module>
    import ctypes
  File "/root/.pyenv/versions/3.8.0/lib/python3.8/ctypes/__init__.py", line 7, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'

MarshioAbout 1 minpythonpython小技巧
not enough values to unpack (expected 3, got 0)

背景

在 Windows 上运行 celery,执行 res.get(timeout=10) 的时候报错

res.get(timeout=10)
Traceback (most recent call last):
  File "C:\Apps\JetBrains\PyCharm 2023.3.3\plugins\python\helpers\pydev\pydevconsole.py", line 364, in runcode
    coro = func()
  File "<input>", line 1, in <module>
  File "C:\Tools\miniconda3\envs\python3.8\lib\site-packages\celery\result.py", line 251, in get
    return self.backend.wait_for_pending(
  File "C:\Tools\miniconda3\envs\python3.8\lib\site-packages\celery\backends\asynchronous.py", line 223, in wait_for_pending
    return result.maybe_throw(callback=callback, propagate=propagate)
  File "C:\Tools\miniconda3\envs\python3.8\lib\site-packages\celery\result.py", line 365, in maybe_throw
    self.throw(value, self._to_remote_traceback(tb))
  File "C:\Tools\miniconda3\envs\python3.8\lib\site-packages\celery\result.py", line 358, in throw
    self.on_ready.throw(*args, **kwargs)
  File "C:\Tools\miniconda3\envs\python3.8\lib\site-packages\vine\promises.py", line 235, in throw
    reraise(type(exc), exc, tb)
  File "C:\Tools\miniconda3\envs\python3.8\lib\site-packages\vine\utils.py", line 27, in reraise
    raise value
ValueError: not enough values to unpack (expected 3, got 0)

MarshioLess than 1 minutepythonpython小技巧
ModuleNotFoundError

背景:想要使用命令行执行 python 脚本,但是得到了 ModuleNotFoundError: No module named 'xxx'

项目结构

py-spider
└── util
    ├── request.py
    ├── mysql_pool.py
    ├── logger.py
    └── __init__.py
└── spider
    ├── spider_demo.py
    └── __init__.py
└── main.py

MarshioAbout 4 minpythonpython小技巧