Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#63294 closed defect (fixed)

py-numpy: No module named 'numpy.core._multiarray_umath'

Reported by: fmw42 (Fred Weinhaus) Owned by: michaelld (Michael Dickens)
Priority: Normal Milestone:
Component: ports Version: 2.7.1
Keywords: Cc: mascguy (Christopher Nielsen)
Port: py-numpy

Description

I was upgrading ports (Python37 and OpenCV3) and also installing Python39 and OpenCV3. The Python37/OpenCV3 upgrade worked fine and my scripts work again. But when installing Python39 and OpenCV3 (py39-opencv3), which seems to install properly, when I try to run a script, I get an error about Numpy. I did upgrade Numpy. I have the following versions.

  py37-numpy @1.15.4_0+gfortran
  py37-numpy @1.16.1_0+gfortran
  py37-numpy @1.16.2_1+gfortran+openblas
  py37-numpy @1.17.4_0+gfortran+openblas
  py37-numpy @1.21.1_0+gfortran+openblas (active)
  py37-opencv3 @3.4.14_0 (active)

  py39-numpy @1.21.1_0+gfortran+openblas (active)
  py39-opencv3 @3.4.14_0 (active)

The latter do not seem to be working and I get the following when I run my Python/OpenCV/Numpy script.

python3.9 python_fit_ellipse.py

OpenCV bindings requires "numpy" package.
Install it via command:
    pip install numpy
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/core/__init__.py", line 22, in <module>
    from . import multiarray
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/core/multiarray.py", line 12, in <module>
    from . import overrides
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/core/overrides.py", line 7, in <module>
    from numpy.core._multiarray_umath import (
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'

I did verify my PythonPath.

PYTHONPATH: /opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages

I am sorry. I do not know how to resolve this. Thanks for any help.

Attachments (1)

python_import_numpy.py (32 bytes) - added by fmw42 (Fred Weinhaus) 3 years ago.
Simple script that fails

Download all attachments as: .zip

Change History (11)

comment:1 Changed 3 years ago by mascguy (Christopher Nielsen)

Cc: mascguy added

comment:2 Changed 3 years ago by ryandesign (Ryan Carsten Schmidt)

Cc: michaelld@… removed
Keywords: Numpy Python OpenCV removed
Owner: set to michaelld
Port: py-numpy added; Numpy removed
Status: newassigned
Summary: No module named 'numpy.core._multiarray_umath'py-numpy: No module named 'numpy.core._multiarray_umath'

comment:3 Changed 3 years ago by mascguy (Christopher Nielsen)

Fred, can you provide a minimal Python script, which reproduces the issue?

comment:4 Changed 3 years ago by fmw42 (Fred Weinhaus)

A simple import of OpenCV and Numpy fails. The script is called as

python3.9 python_import_numpy.py

and contains simply:

import cv2
import numpy as np

Here is what returns:

python3.9 python_import_numpy.py

OpenCV bindings requires "numpy" package.
Install it via command:
    pip install numpy
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/core/__init__.py", line 22, in <module>
    from . import multiarray
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/core/multiarray.py", line 12, in <module>
    from . import overrides
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/core/overrides.py", line 7, in <module>
    from numpy.core._multiarray_umath import (
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/fred/Desktop/python_import_numpy.py", line 1, in <module>
    import cv2
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/cv2/__init__.py", line 8, in <module>
    import numpy
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/__init__.py", line 150, in <module>
    from . import core
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/core/__init__.py", line 48, in <module>
    raise ImportError(msg)
ImportError: 

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

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.9 from "/opt/local/bin/python3.9"
  * The NumPy version is: "1.21.1"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

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

My .profile file includes:

export PYTHONPATH=/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages

My Ports include:

  opencv3 @3.4.14_0 (active)
 
  py39-alabaster @0.7.12_0 (active)
  py39-babel @2.9.0_0 (active)
  py39-beaker @1.11.0_0 (active)
  py39-cairo @1.20.1_0+x11 (active)
  py39-certifi @2021.5.30_0 (active)
  py39-chardet @4.0.0_0 (active)
  py39-charset-normalizer @2.0.3_0 (active)
  py39-cycler @0.10.0_0 (active)
  py39-cython @0.29.24_0 (active)
  py39-dateutil @2.8.2_0 (active)
  py39-decorator @5.0.9_0 (active)
  py39-docutils @0.17.1_0 (active)
  py39-gobject3 @3.38.0_0 (active)
  py39-idna @3.2_0 (active)
  py39-imageio @2.9.0_0 (active)
  py39-imagesize @1.2.0_0 (active)
  py39-jinja2 @3.0.1_0 (active)
  py39-joblib @1.0.1_0 (active)
  py39-kiwisolver @1.3.1_0 (active)
  py39-lxml @4.4.1_0 (active)
  py39-mako @1.1.4_0 (active)
  py39-markdown @3.3.4_0 (active)
  py39-markupsafe @2.0.1_0 (active)
  py39-matplotlib @3.4.2_0+cairo+webagg (active)
  py39-mypy @0.910_0 (active)
  py39-mypy_extensions @0.4.3_0 (active)
  py39-networkx @2.5.1_0 (active)
  py39-numpy @1.21.1_0+gfortran+openblas (active)
  py39-olefile @0.46_0 (active)
  py39-opencv3 @3.4.14_0 (active)
  py39-packaging @21.0_0 (active)
  py39-parsing @2.4.7_0 (active)
  py39-Pillow @8.3.1_0 (active)
  py39-pip @21.1.3_0 (active)
  py39-pybind11 @2.7.0_0 (active)
  py39-pygments @2.9.0_0 (active)
  py39-pywavelets @1.1.1_0 (active)
  py39-requests @2.26.0_1 (active)
  py39-roman @3.3_0 (active)
  py39-scikit-image @0.18.1_0 (active)
  py39-scikit-learn @0.24.2_0 (active)
  py39-scipy @1.7.0_0+gfortran+openblas (active)
  py39-setuptools @57.1.0_0 (active)
  py39-setuptools_scm @6.0.1_0 (active)
  py39-six @1.16.0_0 (active)
  py39-snowballstemmer @2.1.0_0 (active)
  py39-sphinx @4.1.1_0 (active)
  py39-sphinxcontrib-applehelp @1.0.2_0 (active)
  py39-sphinxcontrib-devhelp @1.0.2_0 (active)
  py39-sphinxcontrib-htmlhelp @2.0.0_0 (active)
  py39-sphinxcontrib-jsmath @1.0.1_1 (active)
  py39-sphinxcontrib-qthelp @1.0.3_0 (active)
  py39-sphinxcontrib-serializinghtml @1.1.5_0 (active)
  py39-sphinxcontrib-websupport @1.2.2_0 (active)
  py39-threadpoolctl @2.2.0_0 (active)
  py39-tifffile @2021.7.2_0 (active)
  py39-tkinter @3.9.6_0 (active)
  py39-toml @0.10.2_0 (active)
  py39-tornado @6.1_0 (active)
  py39-typed-ast @1.4.3_0 (active)
  py39-typing_extensions @3.10.0.0_0 (active)
  py39-tz @2021.1_0 (active)
  py39-urllib3 @1.26.6_0 (active)
  py39-wand @0.6.6_0 (active)

  python2_select @0.0_3 (active)
  python3_select @0.0_2 (active)

Changed 3 years ago by fmw42 (Fred Weinhaus)

Attachment: python_import_numpy.py added

Simple script that fails

comment:5 Changed 3 years ago by fmw42 (Fred Weinhaus)

I have resolved this issue.

I just needed to restart my computer after editing my .profile to switch from python37 to python39.

However, I was told that I could have more than one version of Python/OpenCV and have both py37-opencv3 and py39-opencv3 installed. I modified my .profile to include both python versions as follows:

export PYTHONPATH=/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages:/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages

but I can now only run python3.9. If I try to run the same script with python3.7, then I get the same message above about Numpy. I do have py37-numpy installed.

Can you tell me what I need to do so that I can run either version without having to switch my .profile and reboot?

comment:6 Changed 3 years ago by reneeotten (Renee Otten)

you shouldn't need to set PYTHONPATH; depending on whether you use python37 or python39 it should know where to look for the site-packages.

comment:7 Changed 3 years ago by fmw42 (Fred Weinhaus)

Thank you. Much appreciated.

If I comment out PYTHONPATH in my .profile and reboot, then it works using either python3.7 or python3.9 to call the script.

comment:8 Changed 3 years ago by mascguy (Christopher Nielsen)

Resolution: fixed
Status: assignedclosed

Great, glad we could help!

comment:9 in reply to:  7 Changed 3 years ago by jmroot (Joshua Root)

Replying to fmw42:

If I comment out PYTHONPATH in my .profile and reboot, then it works using either python3.7 or python3.9 to call the script.

You don't need to reboot for .profile changes BTW; it is read when the shell starts, so you only need to start a new shell, usually by opening a new window or tab in Terminal.

comment:10 Changed 3 years ago by fmw42 (Fred Weinhaus)

Thanks for that information. That explains why I had my issue. I though I just needed to edit the .profile and it would take. But without rebooting or starting a new shell, it was causing my issue.

Your comment here really helps me understand the situation better.

Note: See TracTickets for help on using tickets.