Python ImportError:无法导入名称mpManager为什么会发生这种情况?没有圆形小鬼

2024-05-14 10:05:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我在pySpokyStuff/mav/init下定义了一个包级变量。py:

from __future__ import print_function

import logging
import multiprocessing

import time


# existing has to be thread safe


# class DronePoolDepletedException(PyspookyException):
#     pass

mpManager = multiprocessing.Manager()

....

当我在另一个包(pyspookystuff/mav)中导入变量mpManager时/商业伙伴)公司名称:

^{pr2}$

它抛出以下错误:

Traceback (most recent call last):
  File "/home/peng/.IntelliJIdea2016.2/config/plugins/python/helpers/pydev/_pydev_bundle/pydev_monkey_qt.py", line 71, in patched_import
    return original_import(name, *args, **kwargs)
  File "/home/peng/git/datapassport/spookystuff/mav/pyspookystuff/mav/comm/__init__.py", line 8, in <module>
    from pyspookystuff.mav import utils, mpManager
ImportError: cannot import name mpManager

为什么会发生这种情况?如何解决?我使用的是python2.7

更新:我插入系统路径在引发导入错误的行之前的发现行:

print(sys.path)

这是直接运行python -m unittest discover的结果(绕过IntelliJ IDEA/Pycharm runner):

['/home/peng/git/datapassport/spookystuff/mav', '', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/home/peng/.local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client', '/usr/lib/python2.7/dist-packages/wx-3.0-gtk2']
---------------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/multiprocessing/managers.py", line 240, in serve_client
    request = recv()
  File "/home/peng/git/datapassport/spookystuff/mav/pyspookystuff/mav/comm/__init__.py", line 10, in <module>
    from pyspookystuff.mav import utils, mpManager
ImportError: cannot import name mpManager
---------------------------------------------------------------------------

看起来很正常,这有助于找到漏洞吗?在


Tags: inpyimporthomeinitlibpackagesusr

热门问题