Menu

Cannot import numpy on console

Help
2019-09-04
2019-09-14
  • Nick Bowsher

    Nick Bowsher - 2019-09-04

    First of all thumbs up for this very useful tool!

    I have created a custom console just as done in the PyScriptingConsole provided with the source code. Everything works fine except there seems to be issues when attempting to load numpy on Python 3.7.4
    Yes, I have removed PythonQt::IgnoreSiteModule and yes, I do have the very latest version of numpy installed via pip. It also runs perfectly if I start python from cmd.exe in Windows.

    if I input the following in my app though I get:


    py>import sys
    py>sys.path.clear()
    py> sys.path.insert(0,"D:\python37\DLLs")
    py> sys.path.insert(0,"D:\python37\Lib\site-packages")
    py> import numpy
    Traceback (most recent call last):
    File "D:\python37\Lib\site-packages\numpy\core__init__.py", line 17, in <module>
    from . import multiarray
    File "D:\python37\Lib\site-packages\numpy\core\multiarray.py", line 14, in <module>
    from . import overrides
    File "D:\python37\Lib\site-packages\numpy\core\overrides.py", line 7, in <module>
    from numpy.core._multiarray_umath import (
    ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'</module></module></module>

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "D:\python37\Lib\site-packages\numpy__init.py", line 142, in <module>
    from . import core
    File "D:\python37\Lib\site-packages\numpy\core__init</module>
    .py", line 47, in <module>
    raise ImportError(msg)
    ImportError: </module></module></string>

    IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

    Importing the numpy c-extensions failed.
    - Try uninstalling and reinstalling numpy.
    - If you have already done that, then:
    1. Check that you expected to use Python3.7 from "C:\Users\Praktikanten\source\repos\pythonQtTestRuns\Win32\Debug\pythonQtTestRuns.exe",
    and that you have no directories in your PATH or PYTHONPATH that can
    interfere with the Python and numpy version "1.16.3" you're trying to use.
    2. If (1) looks fine, you can open a new issue at
    https://github.com/numpy/numpy/issues. Please include details on:
    - how you installed Python
    - how you installed numpy
    - your operating system
    - whether or not you have multiple versions of Python installed
    - if you built from source, your compiler versions and ideally a build log

    • If you're working with a numpy git repository, try git clean -xdf
      (removes all files not under version control) and rebuild numpy.

    Note: this error has many possible causes, so please don't comment on
    an existing issue about this - open a new one instead.

    Original error was: No module named 'numpy.core._multiarray_umath'


    I have also tried it without clearing sys.path and the console spits out the same error.
    note that _multiarray_umath.cp37-win32.pyd is contained within my site-packages, maybe there is an issue opening .pyd files in general?

    thanks in advance

     

    Last edit: Nick Bowsher 2019-09-04
    • Marius Alexander

      Can you try to add these paths to the system PATH variable? Might be worth a try.

      (1) D:\python37\Library\mingw-w64\bin
      (2) D:\python37\Library\usr\bin
      (3) D:\python37\Library\bin
      (4) D:\python37\Library\Scripts
      (5) D:\python37\bin
      

      You can do that in the python console, too:

      import os
      os.environ['PATH'] += ";(1);(2);(3);(4);(5)"
      import numpy
      
       
  • Marius Alexander

    Hello,

    I have a very similar error when importing numpy. It occures when numpy wants to import numpy.core._muliarray_umath, but exits with "undefined symbol: PyExc_ImportError":


    import numpy as np
    Traceback (most recent call last):
    File "pathToPython37/lib/python3.7/site-packages/numpy/core/init.py", line 17, in <module>
    from . import multiarray
    File "pathToPython37/lib/python3.7/site-packages/numpy/core/multiarray.py", line 14, in <module>
    from . import overrides
    File "pathToPython37/lib/python3.7/site-packages/numpy/core/overrides.py", line 7, in <module>
    from numpy.core._multiarray_umath import (
    ImportError: pathToPython37/lib/python3.7/site-packages/numpy/core/_multiarray_umath.cpython-37m-x86_64-linux-gnu.so: undefined symbol: PyExc_ImportError</module></module></module>

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "pathToPython37/lib/python3.7/site-packages/numpy/init.py", line 142, in <module>
    from . import core
    File "pathToPython37/lib/python3.7/site-packages/numpy/core/init.py", line 47, in <module>
    raise ImportError(msg)
    ImportError: </module></module></module></string>

    IMPORTANT: PLEASE READ THIS FOR ADVICE ...
    ...

    Original error was: pathToPython37/lib/python3.7/site-packages/numpy/core/_multiarray_umath.cpython-37m-x86_64-linux-gnu.so: undefined symbol: PyExc_ImportError


    I intalled python 3.7.4 and numpy 1.17.2 via Miniconda on Debian 10, but I also tried different version of numpy - with no luck. I can import numpy from the console of the OS, but not from within my application.

    My python.prf:

    unix:PYTHON_VERSION=3.7
    unix:LIBS += $$system(pathToPython37/bin/python3.7m-config --libs)
    unix:QMAKE_CXXFLAGS += $$system(pathToPython37/bin/python3.7m-config --includes)
    

    Does anybody have a solution or hint?

     

    Last edit: Marius Alexander 2019-09-11
  • Nick Bowsher

    Nick Bowsher - 2019-09-13

    Alright so I solved my problem. The whole time I was on Debug mode and the external package imports would not work for whatever reason. Even though I correctly linked all debug libs etc.
    Luckily I just switched over to release mode and everything is working fine now. It wouldn't be bad to know why it doesn't work in Debug mode though.

     
  • Nick Bowsher

    Nick Bowsher - 2019-09-13

    wow. That actually sounds quite tedious considering all the site packages one can use in a project. Does anyone know how to get some precompiled debug module libraries for windows ?(from OSGeo maybe?). And that still does't solve the mystery as to why the standard modules such as os or sys run in debug and release mode. (I don't see any debug libraries for those in my distro yet they work)

     
  • Nick Bowsher

    Nick Bowsher - 2019-09-13

    wow. That actually sounds quite tedious considering all the site packages one can use in a project. Does anyone know how to get some precompiled debug module libraries for windows ?(from OSGeo maybe?). And that still does't solve the mystery as to why the standard modules such as os or sys run in debug and release mode. (I don't see any debug libraries for those in my distro yet they work)

     
  • Florian Link

    Florian Link - 2019-09-14

    C extensions are typically not deployed in debug mode (there are no wheels for them) and building them yourself in debug mode can be difficult or even mostly impossible (scipy for example is really hard to build yourself on Windows).

    So you can choose between tryping to get a debug build running (which almost nobody of the Python community uses), or to live with a release build. The VS debugger works on release mode as well, so it may not be such a big limitation. Anyways, it is not a PythonQt issue, but a problem of Python in general.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.