错误“导入string_types ValueError:尝试在非软件包中进行相对导入”

时间:2019-05-30 12:37:24

标签: python-2.7 importerror

在Windows 10上使用cmd运行Python 2.7.16。当我运行导入.py的{​​{1}}文件时,出现错误:

  

“文件“ C:\ Python27 \ scipy.py”,第18行,在       从.python导入string_types   ValueError:尝试以非包形式进行相对导入”

由于string_types应该已经包含在python中,所以我不明白为什么会发生此错误,并且似乎无法通过它。有人知道如何解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

您尝试过

>>> from . import MyModule #MyModule.py
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Attempted relative import in non-package
>>> 

此处.表示您当前的路径

尝试,     从MyModule导入*

现在您可以使用string_types

import MyModule as m
m.string_types
相关问题