当我进入python shell并尝试导入例如numpy
或tensorflow
时,没有错误,但是当我运行导入numpy
的脚本时,它会抛出此错误:
Traceback (most recent call last):
File ".\org.py", line 1, in <module>
import tensorflow as tf
File "C:\Python3\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import *
File "C:\Python3\lib\site-packages\tensorflow\python\__init__.py", line 47, in <module>
import numpy as np
File "C:\Python3\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "C:\Python3\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Python3\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Python3\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Python3\lib\site-packages\numpy\core\__init__.py", line 38, in <module>
from . import numeric
File "C:\Python3\lib\site-packages\numpy\core\numeric.py", line 37, in <module>
import pickle
File "C:\Python3\lib\pickle.py", line 93, in <module>
from org.python.core import PyStringMap
File "C:\Users\Jakub\desktop\Nowy\workspace\python\org.py", line 2, in <module>
from tensorflow.examples.tutorials.mnist import input_data
File "C:\Python3\lib\site-packages\tensorflow\examples\tutorials\mnist\__init__.py", line 21, in <module>
from tensorflow.examples.tutorials.mnist import input_data
File "C:\Python3\lib\site-packages\tensorflow\examples\tutorials\mnist\input_data.py", line 29, in <module>
from tensorflow.contrib.learn.python.learn.datasets.mnist import read_data_sets
File "C:\Python3\lib\site-packages\tensorflow\contrib\__init__.py", line 22, in <module>
from tensorflow.contrib import bayesflow
File "C:\Python3\lib\site-packages\tensorflow\contrib\bayesflow\__init__.py", line 24, in <module>
from tensorflow.contrib.bayesflow.python.ops import csiszar_divergence
File "C:\Python3\lib\site-packages\tensorflow\contrib\bayesflow\python\ops\csiszar_divergence.py", line 26, in <module>
from tensorflow.contrib.bayesflow.python.ops.csiszar_divergence_impl import *
File "C:\Python3\lib\site-packages\tensorflow\contrib\bayesflow\python\ops\csiszar_divergence_impl.py", line 43, in <module>
from tensorflow.contrib import framework as contrib_framework
File "C:\Python3\lib\site-packages\tensorflow\contrib\framework\__init__.py", line 88, in <module>
from tensorflow.contrib.framework.python.framework import *
File "C:\Python3\lib\site-packages\tensorflow\contrib\framework\python\framework\__init__.py", line 22, in <module>
from tensorflow.contrib.framework.python.framework.checkpoint_utils import *
File "C:\Python3\lib\site-packages\tensorflow\contrib\framework\python\framework\checkpoint_utils.py", line 24, in <module>
from tensorflow.python.ops import io_ops
File "C:\Python3\lib\site-packages\tensorflow\python\ops\io_ops.py", line 73, in <module>
from tensorflow.python.framework import dtypes
File "C:\Python3\lib\site-packages\tensorflow\python\framework\dtypes.py", line 297, in <module>
dtype_range = {np.bool_: (False, True),
AttributeError: module 'numpy' has no attribute 'bool_'
和tensorflow:
Traceback (most recent call last):
File ".\org.py", line 1, in <module>
import numpy as np
File "C:\Python3\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "C:\Python3\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Python3\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Python3\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Python3\lib\site-packages\numpy\core\__init__.py", line 38, in <module>
from . import numeric
File "C:\Python3\lib\site-packages\numpy\core\numeric.py", line 37, in <module>
import pickle
File "C:\Python3\lib\pickle.py", line 93, in <module>
from org.python.core import PyStringMap
File "C:\Users\Jakub\desktop\Nowy\workspace\python\org.py", line 2, in <module>
import tensorflow as tf
File "C:\Python3\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import *
File "C:\Python3\lib\site-packages\tensorflow\python\__init__.py", line 63, in <module>
from tensorflow.python.framework.framework_lib import *
File "C:\Python3\lib\site-packages\tensorflow\python\framework\framework_lib.py", line 76, in <module>
from tensorflow.python.framework.ops import Graph
File "C:\Python3\lib\site-packages\tensorflow\python\framework\ops.py", line 37, in <module>
from tensorflow.python.eager import context
File "C:\Python3\lib\site-packages\tensorflow\python\eager\context.py", line 27, in <module>
from tensorflow.python.framework import errors
File "C:\Python3\lib\site-packages\tensorflow\python\framework\errors.py", line 22, in <module>
from tensorflow.python.framework import errors_impl as _impl
File "C:\Python3\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 27, in <module>
from tensorflow.python.util import compat
File "C:\Python3\lib\site-packages\tensorflow\python\util\compat.py", line 113, in <module>
integral_types = (_numbers.Integral, _np.integer)
AttributeError: module 'numpy' has no attribute 'integer'
它更早发挥作用。我正在使用Windows 10 x64,Python 3.5.2。我也尝试过ubuntu 17,同样的情况。此外,当我在执行脚本后输入python shell时,导入会给我同样的错误,直到我重启,在我的情况下,powershell。
答案 0 :(得分:1)
您有一个名为org.py
的本地文件,它隐藏了一个可选的内置包(仅在Jython中使用)。
来自追溯:
File "C:\Python3\lib\site-packages\numpy\core\numeric.py", line 37, in
import pickle
File "C:\Python3\lib\pickle.py", line 93, in
from org.python.core import PyStringMap
File "C:\Users\Jakub\desktop\Nowy\workspace\python\org.py", line 2, in <module>
from tensorflow.examples.tutorials.mnist import input_data
C:\Users\Jakub\desktop\Nowy\workspace\python\org.py
不是pickle
模块查找的Jython包。
您运行脚本时才会看到此异常,因为脚本所在的目录(C:\Users\Jakub\desktop\Nowy\workspace\python
此处)会自动添加到sys.path
。
属性错误是由循环导入引起的; numpy
导入pickle
再次导入org
脚本,导入numpy
,但该模块尚未完成所有导入,因此此时缺少名称。< / p>