FS#57926 - Cannot import numpy: AttributeError

Attached to Project: Arch Linux
Opened by Alex Seiler (aexl) - Friday, 23 March 2018, 12:02 GMT
Last edited by Eli Schwartz (eschwartz) - Friday, 23 March 2018, 13:10 GMT
Task Type Bug Report
Category Packages: Extra
Status Closed
Assigned To No-one
Architecture All
Severity High
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description: Importing numpy in a python console leads to the following:

Python 3.6.4 (default, Jan 5 2018, 02:35:40)
[GCC 7.2.1 20171224] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.6/site-packages/numpy/__init__.py", line 142, in <module>
from . import add_newdocs
File "/usr/lib/python3.6/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python3.6/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/lib/python3.6/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/lib/python3.6/site-packages/numpy/core/__init__.py", line 35, in <module>
from . import _internal # for freeze programs
File "/usr/lib/python3.6/site-packages/numpy/core/_internal.py", line 18, in <module>
from .numerictypes import object_
File "/usr/lib/python3.6/site-packages/numpy/core/numerictypes.py", line 960, in <module>
_register_types()
File "/usr/lib/python3.6/site-packages/numpy/core/numerictypes.py", line 955, in _register_types
numbers.Integral.register(integer)
AttributeError: module 'numbers' has no attribute 'Integral'


Additional info:
* python-numpy-1.14.2-1, the same applies to python2-numpy-1.14.2-1


Steps to reproduce:
Start python. Type "import numpy" and press Enter.
This task depends upon

Closed by  Eli Schwartz (eschwartz)
Friday, 23 March 2018, 13:10 GMT
Reason for closing:  Not a bug
Additional comments about closing:  user had a bad "numbers" module in their current working directory
Comment by Antonio Rojas (arojas) - Friday, 23 March 2018, 12:37 GMT
Output of
python -c 'import numbers; print(numbers.__file__)'
?
Comment by Alex Seiler (aexl) - Friday, 23 March 2018, 12:59 GMT
@Anonio Rojas:

Here is the output:

Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: bad magic number in 'numbers': b'\x03\xf3\r\n'
Comment by Alex Seiler (aexl) - Friday, 23 March 2018, 13:02 GMT
I previously had a file 'numbers.py' in my directory /home/user. This might have interfered with the python output. I deleted it now. Trying in to import 'numpy' gives me now the following output:

Python 3.6.4 (default, Jan 5 2018, 02:35:40)
[GCC 7.2.1 20171224] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.6/site-packages/numpy/__init__.py", line 142, in <module>
from . import add_newdocs
File "/usr/lib/python3.6/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python3.6/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/lib/python3.6/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/lib/python3.6/site-packages/numpy/core/__init__.py", line 35, in <module>
from . import _internal # for freeze programs
File "/usr/lib/python3.6/site-packages/numpy/core/_internal.py", line 18, in <module>
from .numerictypes import object_
File "/usr/lib/python3.6/site-packages/numpy/core/numerictypes.py", line 87, in <module>
import numbers
ImportError: bad magic number in 'numbers': b'\x03\xf3\r\n'
Comment by Antonio Rojas (arojas) - Friday, 23 March 2018, 13:03 GMT
You have to delete the .pyc too
Comment by Alex Seiler (aexl) - Friday, 23 March 2018, 13:08 GMT
Thanks, now it works! So I guess, this can be closed.

One question: Is it expected behavior, that having a python file with a unlucky name can break the numpy package?
Comment by Antonio Rojas (arojas) - Friday, 23 March 2018, 13:10 GMT
If you put it in your PYTHONPATH it will break lots of things, not just numpy.

Loading...