PySCIPOpt
PySCIPOpt copied to clipboard
Problem with debugging in Pycharm
Describe the bug After upgrading SCIPOptimization suite to 9.0.0 and pyscipopt to 5.0.0., it is not possible to use the same code in debug mode in Pycharm. Impor of pyscipopt.Model fails with error code
To Reproduce same error on different win 11 machines
Expected behavior A clear and concise description of what you expected to happen.
Screenshots
from pyscipopt.scip import Model File "complex.pxd", line 19, in init pyscipopt.scip File "src\\pyscipopt\\scip.pyx", line 19, in __Pyx_PyMODINIT_FUNC PyInit_scip(void) TypeError: 'NoneType' object is not callable python-BaseException
System
- OS: Win 11
- Version 5.0.0.
- SCIP 9.0.0
- How did you install
pyscipopt
? based on https://github.com/scipopt/PySCIPOpt/blob/master/INSTALL.md, using pip
Additional context nothing
Hello, @jirkacigler! Can you please provide the code which is creating the error? Also, what happens if you run the code not using PyCharm, from the command line, for example?
Debugging crashes on importing of Model
from pyscipopt import Model
For example in pdb, debugging works. But in Pycharm, it fails. This is the complete error output.
`
Connected to pydev debugger (build 223.8836.43)
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2022.2.4\plugins\python\helpers\pydev\pydevd.py", line 2195, in
File "C:\Program Files\JetBrains\PyCharm 2022.2.4\plugins\python\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:\dev\tuning_opt.py", line 3, in
So some minor thoughts:
- This isn't general to PyCharm (or at least I am not getting errors for PyCharm 2023 on Debian)
- The error seems to be Cython related. Can you try and run
pip install Cython==3.0.9
and then run everything again? (Alternatively if that fails trypip install Cython==0.29
)
I'm having a similar issue on import of Model, except I'm using VIsual Studio Code on Windows 11 with debugpy to debug.
Running the file directly from python in the terminal, with no debugger attaching, works as expected.
Hello, @jirkacigler! Can you please provide the code which is creating the error? Also, what happens if you run the code not using PyCharm, from the command line, for example?
I have the same problem, just open a py file and write the following one-line code
import pyscipopt as scip
and then use pycharm to Debug that file, error would orrur, same error as jirkacigler's
I'm facing the same issue using the Spyder IDE.
OS: Win 11 Version 5.0.0. SCIP 8.0.4
When trying to run in debug I get the following error:
File ~\AppData\Local\anaconda3\Lib\site-packages\spyder_kernels\customize\spyderpdb.py:900 in run super(SpyderPdb, self).run(cmd, globals, locals)
File ~\AppData\Local\anaconda3\Lib\bdb.py:600 in run exec(cmd, globals, locals)
[...]
model = Model("Test")
File src\pyscipopt\scip.pxi:1004 in pyscipopt.scip.Model.init
TypeError: 'NoneType' object is not callable
I encounter the same error
OS: macOS (ARM) Version: 5.0.0 SCIP: 9.0.0 Python: 3.12
Furthermore, I used conda to install the relevant dependencies
Reproducible example:
from pyscipopt import Model
model = Model(" modleName ")
This is the produced error:
File "/home/test/venv/lib/python3.12/site-packages/pyscipopt/__init__.py", line 11, in <module>
from pyscipopt.scip import Model
File "complex.pxd", line 19, in init pyscipopt.scip
TypeError: 'NoneType' object is not callable
Please let me know whether there are further details needed to reproduce the error.
So some minor thoughts:
- This isn't general to PyCharm (or at least I am not getting errors for PyCharm 2023 on Debian)
- The error seems to be Cython related. Can you try and run
pip install Cython==3.0.9
and then run everything again? (Alternatively if that fails trypip install Cython==0.29
)
here is my environment: python: 3.8 os: windows scip: pyscipopt-5.0.0 ide: visual studio code 1.88
my code is
from pyscipopt import Model
I have installed pip install Cython==3.0.9
, pip install Cython==0.29.21
,both of them not work。
I have tried PySCIPOpt-4.4.0, it has the same question.
I have the same problem in VSCODE
Anyone has solutions up to now?
@mmghannam is looking into it. I'm also trying to get the next release in order across all platforms, and maybe when that is done then this issue will just resolve itself. (Would not get too hopeful for that though)
I also think that the issues are probably related to a problem with an old Cython version (similar to the one in https://github.com/pandas-dev/pandas/issues/47429). We recently updated to Cython 3, and I couldn't reproduce the buggy behavior on the master branch. This should be fixed in the next release. For now, I suggest manually installing pyscipopt following the instructions in here. Hope this helps!
Can anyone please verify if this issue still persists for the version 5.0.1
?
I'm seeing exactly the same error using PyCharm on a MacBook running OS 13.6.7. When I run in debug mode I see this error:
**from pyscipopt.scip import Model
File "complex.pxd", line 19, in init pyscipopt.scip File "src/pyscipopt/scip.pyx", line 19, in __Pyx_PyMODINIT_FUNC PyInit_scip(void) TypeError: 'NoneType' object is not callable**
I think the problem is related to this comment I found in the code where if fails: #execute the script (note: it's important to compile first to have the filename set in debug mode) exec(compile(contents+"\n", file, 'exec'), glob, loc)
This is in the file: /PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_imps/_pydev_execfile.py on line 17
But how do I do that pre-compile and what do I compile?
Can anyone please verify if this issue still persists for the version
5.0.1
?
Yes, still persists
I will look into this with @mmghannam next week. Sorry for this taking so long. We are a bit lost, and it's not trivial to recreate this error with the computers we have.
I also think that the issues are probably related to a problem with an old Cython version (similar to the one in pandas-dev/pandas#47429). We recently updated to Cython 3, and I couldn't reproduce the buggy behavior on the master branch. This should be fixed in the next release. For now, I suggest manually installing pyscipopt following the instructions in here. Hope this helps!
Building PyScipOpt from source works for newest version (5.0.1, cython 3.10), however the version in pip repository does not work.
I and @Opt-Mucca looked into it, and we think the problem was caused from compiling Cython with line tracing enabled (used to compute test coverage). I'm not sure why that caused problems with debugging but we disabled it in the latest release 5.1.1
and I tested and couldn't reproduce the problem.
Could you please check again if the problem still persists in the latest release?
I and @Opt-Mucca looked into it, and we think the problem was caused from compiling Cython with line tracing enabled (used to compute test coverage). I'm not sure why that caused problems with debugging but we disabled it in the latest release
5.1.1
and I tested and couldn't reproduce the problem.Could you please check again if the problem still persists in the latest release?
I tried it out, and 5.1.1 works fine in VSCode.