# Debugging cythonized using visual studio 2022

**URL:** <https://discuss.python.org/t/debugging-cythonized-using-visual-studio-2022/57350>\
**Category:** Python Help\
**Created:** [July 4, 2024, 3:08pm UTC](https://discuss.python.org/t/debugging-cythonized-using-visual-studio-2022/57350 "2024-07-04T15:08:04Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![rshahrabani](https://avatars.discourse-cdn.com/v4/letter/r/77aa72/32.png) [@rshahrabani](https://discuss.python.org/u/rshahrabani)\
**Post date:** [September 11, 2024, 9:10pm UTC](https://discuss.python.org/t/debugging-cythonized-using-visual-studio-2022/57350/21 "2024-09-11T21:10:05Z")

</div>

I have the line:  
j = 99

and the below variable exists in the locals window but I cannot find the value 99 anywhere in this object; where would I need to look for that?

Ronny

Document

---

<div class="post-metadata">

**Author:** ![steve.dower](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/steve.dower/32/56_2.png) [@steve.dower](https://discuss.python.org/u/steve.dower)\
**Post date:** [September 11, 2024, 10:19pm UTC](https://discuss.python.org/t/debugging-cythonized-using-visual-studio-2022/57350/22 "2024-09-11T22:19:04Z")

</div>

Oh, for that you need to understand how to inspect PyObject values. This is fairly deep and complicated stuff, so generally it’s easiest to focus on the control flow when debugging C code (e.g. watch where it branches to figure out what may be going wrong).

For some (mostly older) versions of Python, Visual Studio supports [mixed-mode debugging](https://learn.microsoft.com/en-us/visualstudio/python/debugging-mixed-mode-c-cpp-python-in-visual-studio?view=vs-2022), which knows how to do this for you and can show you the actual value. It’s very neat how it works, but unfortunately they think that many VS users don’t care about it and so it hasn’t been updated for a while. I _think_ Python 3.9 is the last version that works properly.

---

<div class="post-metadata">

**Author:** ![rshahrabani](https://avatars.discourse-cdn.com/v4/letter/r/77aa72/32.png) [@rshahrabani](https://discuss.python.org/u/rshahrabani)\
**Post date:** [September 12, 2024, 2:12pm UTC](https://discuss.python.org/t/debugging-cythonized-using-visual-studio-2022/57350/23 "2024-09-12T14:12:25Z")

</div>

The problem is I need to inspect the values of complex objects, and analyzing the control flow isn’t going to help me here. Rolling back to python 3.9 is also not possible due to 3rd party packages requiring newer versions of python.

Any suggestions?

---

<div class="post-metadata">

**Author:** ![steve.dower](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/steve.dower/32/56_2.png) [@steve.dower](https://discuss.python.org/u/steve.dower)\
**Post date:** [September 12, 2024, 2:44pm UTC](https://discuss.python.org/t/debugging-cythonized-using-visual-studio-2022/57350/24 "2024-09-12T14:44:17Z")

</div>

Only to modify the code to either print the values that you need, or to inspect the memory manually.

I suspect you won’t, but just for completeness, you could also get the code for Visual Studio’s Python support from [GitHub - microsoft/PTVS: Python Tools for Visual Studio](https://github.com/microsoft/PTVS) and contribute the updates needed for mixed-mode debugging to work with newer versions.

Print statements are likely the way for you to go.

---

<div class="post-metadata">

**Author:** ![rshahrabani](https://avatars.discourse-cdn.com/v4/letter/r/77aa72/32.png) [@rshahrabani](https://discuss.python.org/u/rshahrabani)\
**Post date:** [September 12, 2024, 2:59pm UTC](https://discuss.python.org/t/debugging-cythonized-using-visual-studio-2022/57350/25 "2024-09-12T14:59:56Z")

</div>

What will the PTV package provide? Will it allow me to inspect variables?

---

<div class="post-metadata">

**Author:** ![steve.dower](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/steve.dower/32/56_2.png) [@steve.dower](https://discuss.python.org/u/steve.dower)\
**Post date:** [September 12, 2024, 3:00pm UTC](https://discuss.python.org/t/debugging-cythonized-using-visual-studio-2022/57350/26 "2024-09-12T15:00:55Z")

</div>

If you’re getting Python syntax highlighting and regular debugging in Visual Studio, it’s because you’ve installed PTVS. Years ago it wasn’t included in VS, but these days it is. It’s still open source though, so you can contribute if you like.

---

<div class="post-metadata">

**Author:** ![rshahrabani](https://avatars.discourse-cdn.com/v4/letter/r/77aa72/32.png) [@rshahrabani](https://discuss.python.org/u/rshahrabani)\
**Post date:** [September 12, 2024, 3:02pm UTC](https://discuss.python.org/t/debugging-cythonized-using-visual-studio-2022/57350/27 "2024-09-12T15:02:27Z")

</div>

Ok, thanks.

[Previous page](https://discuss.python.org/t/debugging-cythonized-using-visual-studio-2022/57350.md?page=1)
