0

When I enter the python shell and try import for example numpy or tensorflow, there is no error, but when I run script that imports numpy it throws this error:

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_'

and 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'

It works earlier. I'm working on windows 10 x64, Python 3.5.2. I also tried on ubuntu 17, same case. Also when I enter python shell after executing script, importing gives me same error until i restart, in my case, powershell.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Waxy
  • 11
  • 4

1 Answers1

1

You have a local file named org.py that shadows an optional built-in package (only used in Jython).

From your traceback:

  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 is not the Jython package the pickle module looks for.

You only see this exception when you run your script because the directory your script is located in (C:\Users\Jakub\desktop\Nowy\workspace\python here) is added to sys.path automatically.

The attribute error is caused by the circular import; numpy imports pickle which imports your org script again, which imports numpy, but that module has not yet completed all its imports, so names are missing at this time.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343