PySCIPOpt icon indicating copy to clipboard operation
PySCIPOpt copied to clipboard

Problem with debugging in Pycharm

Open jirkacigler opened this issue 11 months ago • 8 comments

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

jirkacigler avatar Mar 19 '24 12:03 jirkacigler

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?

Joao-Dionisio avatar Mar 20 '24 10:03 Joao-Dionisio

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 main() File "C:\Program Files\JetBrains\PyCharm 2022.2.4\plugins\python\helpers\pydev\pydevd.py", line 2177, in main globals = debugger.run(setup['file'], None, None, is_module) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\JetBrains\PyCharm 2022.2.4\plugins\python\helpers\pydev\pydevd.py", line 1489, in run return self._exec(is_module, entry_point_fn, module_name, file, globals, locals) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\JetBrains\PyCharm 2022.2.4\plugins\python\helpers\pydev\pydevd.py", line 1496, in _exec pydev_imports.execfile(file, globals, locals) # execute the script ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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 from pyscipopt import Model File "C:\Program Files\Python311\Lib\site-packages\pyscipopt_init_.py", line 23, in 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 `

jirkacigler avatar Mar 20 '24 21:03 jirkacigler

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 try pip install Cython==0.29)

Opt-Mucca avatar Mar 21 '24 14:03 Opt-Mucca

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.

NeonDactyl avatar Mar 27 '24 18:03 NeonDactyl

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

GasCan666 avatar Apr 01 '24 03:04 GasCan666

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

banjodd avatar Apr 05 '24 10:04 banjodd

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.

PHonest avatar Apr 19 '24 07:04 PHonest

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 try pip 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.

chuzhixing avatar May 10 '24 05:05 chuzhixing

I have the same problem in VSCODE

zengbin5966 avatar May 28 '24 08:05 zengbin5966

Anyone has solutions up to now?

chronican avatar Jun 04 '24 09:06 chronican

@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)

Opt-Mucca avatar Jun 04 '24 09:06 Opt-Mucca

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!

mmghannam avatar Jun 05 '24 05:06 mmghannam

Can anyone please verify if this issue still persists for the version 5.0.1?

Opt-Mucca avatar Jun 18 '24 08:06 Opt-Mucca

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?

richardlevinson avatar Jun 18 '24 17:06 richardlevinson

Can anyone please verify if this issue still persists for the version 5.0.1?

Yes, still persists

paradiseland avatar Jun 19 '24 07:06 paradiseland

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.

Opt-Mucca avatar Jun 19 '24 09:06 Opt-Mucca

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.

jirkacigler avatar Jun 20 '24 11:06 jirkacigler

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?

mmghannam avatar Jun 22 '24 12:06 mmghannam

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.

zengbin5966 avatar Jun 24 '24 06:06 zengbin5966