Hi Steve,
I’ve been trying to debug a very simple Cythonized project in Visual Studio 2022 Professional (zip file containing the scripts and the project file is attached), and the IDE correctly stops at the breakpoints but I am unable to inspect any variables.
In this case, I’ve placed breakpoints in the init method of the TickerParserDEP class in ticker_dep.py. My startup script is rtf_bootstrap.py which is placed in the build folder which is a subfolder of the businesslib folder. structure is as follows:
C:\CythonDebug\businesslib\build
The businesslib folder contains all the .py scripts and the build folder contains the Cythonized binaries. I’ve included the setup.py script which builds the binaries from the 2 script files (ticker.py and ticker_dep.py). You need to run the command python setup.py build_ext --build-lib ./build from the businesslib folder.
As rtf_bootstrap.py is in the build folder, Visual Studio correctly debugs the binaries. Everything runs fine but when I try to inspect the i or j variable in the TickerParserDEP.init method, I get the following error in Visual Studio:
Document
Name | Value | Type |
j | identifier “j” is undefined | |
Do you have experience debugging Cythonized binaries using Visual Studio? Or do you prefer some other tools for debugging? My project has Enable native code debugging option checked and the Search Paths property set to …\businesslib in the Debug tab of the project properties. Also, it is using Python 3.12 as the Interpreter (see the General tab).
Any information would be much appreciated.
Ronny
setup.py:
from setuptools import setup, Extension
from Cython.Build import cythonize
python setup.py build_ext --build-lib ./build
extensions = [
Extension(“ticker”, [“ticker.py”],
# extra_compile_args=[“-Ox”, “-Zi”],
extra_compile_args=[“-Od”, “-Zi”],
extra_link_args=[“-debug:full”]),
Extension(“ticker_dep”, [“ticker_dep.py”],
# extra_compile_args=[“-Ox”, “-Zi”],
extra_compile_args=[“-Od”, “-Zi”],
extra_link_args=[“-debug:full”])
]
setup(
ext_modules=cythonize(extensions, emit_linenums=True)
)
ticker_dep.py:
from ticker import Ticker
import cython
class TickerParserDEP(Ticker):
# @cython.locals(j=cython.int, i=cython.int)
def init(self):
print(‘top of ticker_dep.init’)
j = 99
Ticker.init(self)
i = 100
print('bottom of ticker_dep.init: ’ + str(i) + ‘/’ + str(j))
def start(self) -> None:
print('top of ticker_dep.start')
ticker.py:
import abc
class Ticker(metaclass=abc.ABCMeta):
def init(self):
print(‘top of ticker.init’)
rtf_bootstrap.py:
from ticker_dep import TickerParserDEP
class RtfBootstrap:
def init(self, print_to_console: bool=False, print_stats: bool=False):
print(‘top of bootstrap.init’)
tickerDep = TickerParserDEP()
tickerDep.start()
def start(self) -> None:
print('top of rtf_bootstrap.start')
__rtf_bootstrap = RtfBootstrap(print_to_console=False, print_stats=False)
__rtf_bootstrap.start()