简体   繁体   中英

How to resolve the import error for numpy in python3.8 on linux?

I've installed python3.8 and the up-to-date version of numpy.

# pip list
Package          Version
---------------- ---------
appdirs          1.4.4
certifi          2020.6.20
distlib          0.3.0
filelock         3.0.12
numpy            1.19.0
opencv-python    4.2.0.34
pandas           1.0.5
pip              20.1.1
pipenv           2020.6.2
PyMySQL          0.9.3
python-dateutil  2.8.1
pytz             2020.1
scipy            1.5.0
setuptools       41.2.0
six              1.15.0
virtualenv       20.0.25
virtualenv-clone 0.5.4

Here's c simple code:

import numpy

but python can't import numpy.

Python 2.7.5 (default, Apr  9 2019, 14:30:50)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/site-packages/numpy/__init__.py", line 140, in <module>
    from . import core
  File "/usr/local/lib/python3.8/site-packages/numpy/core/__init__.py", line 22, in <module>
    from . import multiarray
  File "/usr/local/lib/python3.8/site-packages/numpy/core/multiarray.py", line 12, in <module>
    from . import overrides
  File "/usr/local/lib/python3.8/site-packages/numpy/core/overrides.py", line 188
    exec(source_object, scope)
SyntaxError: unqualified exec is not allowed in function 'decorator' it is a nested function
>>>

how can I resolve this trouble? help me. plz..

Try to run the script by using the command python3 script_name.py . The reason for the error could be because script is using python 2.7.5 version.

You may have to check your PYTHONPATH

To print the python search path type this in python shell

import sys  
print sys.path

Here you should find the directory containing your numpy library. But if it is missing then manually locate the directory containing numpy library and add it to your python path using this code

sys.path.append('your directory path here')

then try importing again

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM