Error with numpy import only in debugging

Code which imports numpy runs fine normally (from command line or in PyCharm using the run button) but fails when debugging in pycharm (using the debug button).

PyCharm version 2020.1.5 professional (although I tested it in 2021.2.2 Community as well), Python on windows64 version 3.9.7 installed from python.org using the windows installer. Numpy version 1.21.2 installed using pip.

Output when not debugging:

C:\Python39\python.exe C:/Users/holt/Documents/python/numpyTest/test.py
numpy import complete

Process finished with exit code 0

Output when debugging:

C:\Python39\python.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2021.2.2\plugins\python-ce\helpers\pydev\pydevd.py" --multiproc --qt-support=auto --client 127.0.0.1 --port 61088 --file C:/Users/holt/Documents/python/numpyTest/test.py
Connected to pydev debugger (build 212.5284.44)
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Python39\lib\site-packages\numpy\__init__.py", line 200, in <module>
core.numerictypes.typeDict,
AttributeError: module 'numpy.core' has no attribute 'numerictypes'
python-BaseExceptionError: module 'numpy.core' has no attribute 'numerictypes'

 

Code to reproduce:

import numpy as np
print('numpy import complete')

 

1
10 comments

Hello, 

 

It is not reproducible for me. Please try this with another python interpreter. Will it work? 

0

On a new computer with a fresh install of Pycharm, python 3.9 and numpy I don't see the problem. It must be an interaction with some other package, I'll check the two other computers I saw the problem on and look for common packages.

0

I'm having the exact same issue and I'm currently I'm using PyCharm 2021.2.2 Community Edition.
The only workaround that solved the issue was downgrading numpy from version 1.21.2 to 1.20.3, but I know it's not a permanent solution.
The strange thing is that, with the same virtual environment and numpy 1.21.2, I was able to debug my module using Visual Studio Code.

Here i post my console output, I hope it will be useful:

C:\Users\andre\Repository\app\venv\Scripts\python.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2021.1.2\plugins\python-ce\helpers\pydev\pydevd.py" --module --multiproc --qt-support=auto --client 127.0.0.1 --port 56982 --file app
Connected to pydev debugger (build 212.5284.44)
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\andre\Repository\app\app\MainWindow.py", line 20, in <module>
from ._ui.MainWindow_ui import Ui_MainWindow
File "C:\Users\andre\Repository\app\venv\Lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py", line 142, in _import
return original_import(name, *args, **kwargs)
File "C:\Users\andre\Repository\app\app\_ui\MainWindow_ui.py", line 17, in <module>
from app.calibration.Calibration import Calibration
File "C:\Users\andre\Repository\app\venv\Lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py", line 142, in _import
return original_import(name, *args, **kwargs)
File "C:\Users\andre\Repository\app\app\calibration\Calibration.py", line 4, in <module>
import pyqtgraph as pg
File "C:\Users\andre\Repository\app\venv\Lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py", line 142, in _import
return original_import(name, *args, **kwargs)
File "C:\Users\andre\Repository\app\venv\lib\site-packages\pyqtgraph\__init__.py", line 20, in <module>
import numpy ## pyqtgraph requires numpy
File "C:\Users\andre\Repository\app\venv\Lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py", line 142, in _import
return original_import(name, *args, **kwargs)
File "C:\Users\andre\Repository\app\venv\lib\site-packages\numpy\__init__.py", line 200, in <module>
core.numerictypes.typeDict,
AttributeError: module 'numpy.core' has no attribute 'numerictypes'
python-BaseException

Process finished with exit code -1073741510 (0xC000013A: interrupted by Ctrl+C)

1

I found some more info on my problem. It seems to be an interaction with PySide2 and the debugger. With PySide2 installed and the "PyQt compatible" checkbox in settings->build execution development->python debugger checked and the option set to "auto" or "pyside2" I get the error. if I uncheck the "PyQt compatible" checkbox, then the test code runs in the debugger fine. I am not importing pyside2 in the test code, but I do need it in my real code, so the compatibility is probably necessary.

Downgrading numpy to 1.20.3  as mentioned above also fixes the problem. This is the solution I will go with for now.

3

I can confirm the last statement regarding PySide2. When I disable a package which depends on PySide2, I have no problem, otherwise the debugger fails.

0

Hello, 

 

I have tested a project with all mentioned packages installed, but still no luck. If anyone could share a requirements.txt file and a code sample to reproduce it would be very helpful! 

0

I have an example project now, but how to attach a ZIP file here? Anyway, it's easy to reproduce, I use PyCharm Professional 2021.2.2 on Ubuntu Mate 20.04.

requirements.txt

PySide2
numpy

main.py

import numpy as np


def print_hi(name):
print(f'Hi, {name}')
x = np.zeros([480, 640], dtype=np.uint8)


if __name__ == '__main__':
print_hi('PyCharm')

Running main.py with Shift-F10 works, but running the debugger with Shift-F9 fails:

/home/user/Desktop/numpy-debug-problem/venv/bin/python /home/user/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/212.5284.44/plugins/python/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 43335 --file /home/user/Desktop/numpy-debug-problem/main.py
Connected to pydev debugger (build 212.5284.44)
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 848, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/user/Desktop/numpy-debug-problem/venv/lib/python3.8/site-packages/numpy/__init__.py", line 200, in <module>
core.numerictypes.typeDict,
AttributeError: module 'numpy.core' has no attribute 'numerictypes'
python-BaseException

Process finished with exit code 1

 

 

0

Hello, 

 

Please attach a zipped project to the ticket https://youtrack.jetbrains.com/issue/PY-50959

 

Thank you in advance! 

0

Thank you everyone for reporting this. 

The bug is submitted, please vote for it here https://youtrack.jetbrains.com/issue/PY-50959 in order to increase its priority. 

The workaround is: 

in PyCharm | Preferences | Build, Execution, Deployment | Python Debugger ->  PyQt compatible -> PySide

1

Please sign in to leave a comment.