Problem Description
Hello,
I have used Spyder for years without issues. However, after getting a new laptop and reinstalling Spyder, I encountered problems with pythonnet.
Code that imports pythonnet modules like clr works on first run, but fails on reload with the error "RuntimeError: Failed to initialize Python.Runtime.dll".
As suggested in pythonnet/pythonnet#2079, I adjusted Pythhonnet code when importing clr which fixed the reload issue.
However, this then surfaces another error on reload - "AttributeError: module 'clr' has no attribute 'AddReference'".
I have tried this with multiple versions of Anaconda, Miniconda, and Spyder but observe the same reloading issue.
Interestingly, the code works flawlessly when run in other IDEs like PyCharm, VSCode, and Visual Studio.
In Spyder, I have to restart the kernels everytime to avoid this error.
A similar error has been also reported here for Spyder.
It seems to be an isolated problem with reusing pythonnet in Spyder. I would appreciate any suggestions on how to resolve the reload errors when importing clr. Let me know if any other details would be helpful.
Paste Traceback/Error Below (if applicable)
Traceback (most recent call last):
File ~\AppData\Local\miniconda3\Lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
exec(code, globals, locals)
File e:\TEST\python test\TEST_2023.py:15
clr.AddReference('OSIsoft.AFSDK')
AttributeError: module 'clr' has no attribute 'AddReference'
Versions
- Spyder version: 5.4.4
- Python version: 3.11.4
- Qt version (qt-main): 5.15.2
- PyQt version: 5.15.7
- Operating System name/version: Windows 10 Pro
Problem Description
Hello,
I have used Spyder for years without issues. However, after getting a new laptop and reinstalling Spyder, I encountered problems with pythonnet.
Code that imports pythonnet modules like clr works on first run, but fails on reload with the error "RuntimeError: Failed to initialize Python.Runtime.dll".
As suggested in pythonnet/pythonnet#2079, I adjusted Pythhonnet code when importing clr which fixed the reload issue.
However, this then surfaces another error on reload - "AttributeError: module 'clr' has no attribute 'AddReference'".
I have tried this with multiple versions of Anaconda, Miniconda, and Spyder but observe the same reloading issue.
Interestingly, the code works flawlessly when run in other IDEs like PyCharm, VSCode, and Visual Studio.
In Spyder, I have to restart the kernels everytime to avoid this error.
A similar error has been also reported here for Spyder.
It seems to be an isolated problem with reusing pythonnet in Spyder. I would appreciate any suggestions on how to resolve the reload errors when importing clr. Let me know if any other details would be helpful.
Paste Traceback/Error Below (if applicable)
Traceback (most recent call last): File ~\AppData\Local\miniconda3\Lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec exec(code, globals, locals) File e:\TEST\python test\TEST_2023.py:15 clr.AddReference('OSIsoft.AFSDK') AttributeError: module 'clr' has no attribute 'AddReference'Versions