Python新手:“ImportError:无法导入名称”

时间:2016-11-23 11:03:59

标签: python python-2.7 module

我是Python的新手,并继承了在一个环境中运行但在另一个环境中运行的项目。这就是我得到的......

Traceback (most recent call last):
  File "/Users/orengross/Development/Clyng/infra/tests/clyng/tests/cl_same_item_in_array_twice.py", line 6, in <module>
    from clyng.config.cl_testconfig import get_customer, Accounts, hostname
  File "/Users/orengross/Development/Clyng/infra/tests/clyng/config/cl_testconfig.py", line 4, in <module>
    from clyng.utils import clyngcustomeruser
  File "/Users/orengross/Development/Clyng/infra/tests/clyng/utils/clyngcustomeruser.py", line 5, in <module>
    from clyng.networking.network_wraper import NetworkWrapper
  File "/Users/orengross/Development/Clyng/infra/tests/clyng/networking/network_wraper.py", line 7, in <module>
    from clyng.utils.clyngutils import logger, normalise
  File "/Users/orengross/Development/Clyng/infra/tests/clyng/utils/clyngutils.py", line 13, in <module>
    from faker import Factory
  File "/Library/Python/2.7/site-packages/faker/__init__.py", line 4, in <module>
    from faker.factory import Factory
  File "/Library/Python/2.7/site-packages/faker/factory.py", line 10, in <module>
    from faker.config import DEFAULT_LOCALE, PROVIDERS, AVAILABLE_LOCALES
  File "/Library/Python/2.7/site-packages/faker/config.py", line 13, in <module>
    AVAILABLE_LOCALES = find_available_locales(PROVIDERS)
  File "/Library/Python/2.7/site-packages/faker/utils/loading.py", line 19, in find_available_locales
    provider_module = import_module(provider_path)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Library/Python/2.7/site-packages/faker/providers/address/__init__.py", line 6, in <module>
    from .. import date_time
  File "/Library/Python/2.7/site-packages/faker/providers/date_time/__init__.py", line 10, in <module>
    from dateutil.tz import tzlocal
  File "/Library/Python/2.7/site-packages/dateutil/tz/__init__.py", line 1, in <module>
    from .tz import *
  File "/Library/Python/2.7/site-packages/dateutil/tz/tz.py", line 23, in <module>
    from ._common import tzname_in_python2, _tzinfo, _total_seconds
  File "/Library/Python/2.7/site-packages/dateutil/tz/_common.py", line 2, in <module>
    from six.moves import _thread
ImportError: cannot import name _thread

我将不胜感激。

1 个答案:

答案 0 :(得分:0)

错误的最后一行是尝试从模块_thread导入函数six.moves

'six'模块旨在允许Python程序在安装了2.x或3.x Python基础的机器上工作。在这种情况下,它正在Python 2.x代码中查找关键字thread的实例,并在机器运行Python 3.x时将其替换为_thread。 six.moves的文档在https://pypi.python.org/pypi/six

修复建议

  1. 检查新机器是否安装了six.moves模块
  2. 如果代码和新机器都在运行Python 2.x,请尝试删除该导入指令。查找一行代码“from six.moves import _thread'
  3. 您可能会发现清除第一个错误会使其他错误暴露出来,通常会在每个错误处理之后再进行操作。