简体   繁体   中英

Can't import numpy and scipy in Ubuntu for python 3.6.8

I am attempting to load numpy & scipy into my Ubuntu VM.

I have ensured that both are installed:

con@VB:~/Scripts$ pip3 install numpy
Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (1.14.2)
con@VB:~/Scripts$ pip3 install scipy
Requirement already satisfied: scipy in /usr/local/lib/python3.6/dist-packages (1.1.0)
Requirement already satisfied: numpy>=1.8.2 in /usr/local/lib/python3.6/dist-packages (from scipy) (1.14.2)

but when I get to python3:

con@VB:~/Scripts$ python3
Python 3.6.8 (default, Oct  7 2019, 12:59:55) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy

I get this horrific message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/numpy/__init__.py", line 142, in <module>
    from . import add_newdocs
  File "/usr/local/lib/python3.6/dist-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/usr/local/lib/python3.6/dist-packages/numpy/lib/__init__.py", line 8, in <module>
    from .type_check import *
  File "/usr/local/lib/python3.6/dist-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/usr/local/lib/python3.6/dist-packages/numpy/core/__init__.py", line 35, in <module>
    from . import _internal  # for freeze programs
  File "/usr/local/lib/python3.6/dist-packages/numpy/core/_internal.py", line 9, in <module>
    import re
  File "/home/con/Scripts/re.py", line 4
    print 'string matches'
                         ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print('string matches')?
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 53, in apport_excepthook
    if not enabled():
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 24, in enabled
    import re
  File "/home/con/Scripts/re.py", line 4
    print 'string matches'
                         ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print('string matches')?

Original exception was:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/numpy/__init__.py", line 142, in <module>
    from . import add_newdocs
  File "/usr/local/lib/python3.6/dist-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/usr/local/lib/python3.6/dist-packages/numpy/lib/__init__.py", line 8, in <module>
    from .type_check import *
  File "/usr/local/lib/python3.6/dist-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/usr/local/lib/python3.6/dist-packages/numpy/core/__init__.py", line 35, in <module>
    from . import _internal  # for freeze programs
  File "/usr/local/lib/python3.6/dist-packages/numpy/core/_internal.py", line 9, in <module>
    import re
  File "/home/con/Scripts/re.py", line 4
    print 'string matches'
                         ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print('string matches')?

this error seems like a rookie mistake about switching from python2 to python3 and the parentheses that are necessary for print statements, but I didn't write any of these files.

I've checked What does "SyntaxError: Missing parentheses in call to 'print'" mean in Python? and Cannot import numpy in python3 and How to install NumPy for Python 3.6 but cannot find any useful solutions

how can I load numpy and scipy in python3?

You have syntax error. In python3 you need to use print("string") . Not print 'string' .

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