Python debugger cannot display source for scripts #45955

Closed
opened 2015-08-29 23:49:44 +02:00 by Geoffrey Bantle · 11 comments

System Information:

Windows 7 Enterprise 64 bit
Blender 2.75a 64 bit official windows build
Python 3.4.2 64 bit official windows build from python.org

Python debugger cannot display source for scripts. To reproduce, run the attached script "bug.py" from command line like this:

blender.exe --background --python bug.py

1
2

(7)()

(Pdb)

Compare this to output from python:

python.exe bug.py

1
2

c:\sandbox\bug.py(7)()

  • print(3)
    (Pdb)

I also tested and reproduced the same bug with the ipdb and pycharm debuggers.

bug.py

System Information: Windows 7 Enterprise 64 bit Blender 2.75a 64 bit official windows build Python 3.4.2 64 bit official windows build from python.org Python debugger cannot display source for scripts. To reproduce, run the attached script "bug.py" from command line like this: blender.exe --background --python bug.py 1 2 > <string>(7)<module>() (Pdb) Compare this to output from python: python.exe bug.py 1 2 > c:\sandbox\bug.py(7)<module>() - > print(3) (Pdb) I also tested and reproduced the same bug with the ipdb and pycharm debuggers. [bug.py](https://archive.blender.org/developer/F229070/bug.py)

Changed status to: 'Open'

Changed status to: 'Open'
Campbell Barton was assigned by Geoffrey Bantle 2015-08-29 23:49:44 +02:00

Added subscriber: @gbantle-3

Added subscriber: @gbantle-3

Added subscriber: @mont29

Added subscriber: @mont29

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'

Thanks for the report, but no bug here… Embedding python implies some differences from the vanilla interpreter - here Blender reads given py scripts and feeds interpreter with that text, so py indeed does not have access to the file itself (for windows only, due to likely different versions between Blender C lib and python C lib - sigh).

Thanks for the report, but no bug here… Embedding python implies some differences from the vanilla interpreter - here Blender reads given py scripts and feeds interpreter with that text, so py indeed does not have access to the file itself (for windows only, due to likely different versions between Blender C lib and python C lib - *sigh*).

Hi Bastien,

Thank you for the quick response.

Am I to understand this means it's simply not possible to debug python scripts on windows? Is this limitation documented somewhere?

Hi Bastien, Thank you for the quick response. Am I to understand this means it's simply not possible to debug python scripts on windows? Is this limitation documented somewhere?

It’s not impossible at all, you just do not have access to main file's name in this case, that’s all. Should not be a big issue, since you know which file you passed to Blender's options. ;)

It’s not impossible at all, you just do not have access to main file's name in this case, that’s all. Should not be a big issue, since you know which file you passed to Blender's options. ;)

Hi Bastien,

Thanks for the response.

I don't fully agree that since the developer knows the name of the source file all is well, although it certainly helps. I think the relevant point is that since pdb doesn't know the name of the file it no longer works as intended and pdb ships with blender on windows.

Even more interesting, say you don't want to use pdb (which admittedly is not too useful compared to more advanced debuggers), it seems this same issue prevents stack traces from printing properly when unhandled exceptions are thrown. Compare what happens when you run the attached script bug2.py in Blender to what happens when you run it with python.

Blender:

Traceback (most recent call last):

File "<string>", line 1, in <module>
File "<string>", line 17, in <module>
File "<string>", line 2, in a
File "<string>", line 6, in b
File "<string>", line 10, in c
File "<string>", line 14, in d

ZeroDivisionError: division by zero

Blender quit

Python:

Traceback (most recent call last):

File "bug2.py", line 17, in <module>
  a()
File "bug2.py", line 2, in a
  b()
File "bug2.py", line 6, in b
  c()
File "bug2.py", line 10, in c
  d()
File "bug2.py", line 14, in d
1/0

ZeroDivisionError: division by zero

Admittedly all is not lost since the line numbers are preserved and you can cross reference it with your source file by hand to see the actual content of the offending line. However the way Blender does it right now is not too useful when you just want to get a quick look at the error and the code that caused it. Further it may be quite confusing to someone who doesn't know the technical reasons behind this behavior.

Regardless, my motivation here is simply to advocate for a solution that helps others who might run into this same issue in the future. Thanks to your help I know what the problem is and can easily work around it (I just wrote a wrapper which imports my other code that can then be debugged as normal). However this was after quite a bit of confusion on my part and tinkering with the configuration of my debugger. It would be nice if others don't have to go through the same thing in the future.

Hi Bastien, Thanks for the response. I don't fully agree that since the developer knows the name of the source file all is well, although it certainly helps. I think the relevant point is that since pdb doesn't know the name of the file it no longer works as intended and pdb ships with blender on windows. Even more interesting, say you don't want to use pdb (which admittedly is not too useful compared to more advanced debuggers), it seems this same issue prevents stack traces from printing properly when unhandled exceptions are thrown. Compare what happens when you run the attached script [bug2.py](https://archive.blender.org/developer/F229214/bug2.py) in Blender to what happens when you run it with python. Blender: Traceback (most recent call last): ``` File "<string>", line 1, in <module> File "<string>", line 17, in <module> File "<string>", line 2, in a File "<string>", line 6, in b File "<string>", line 10, in c File "<string>", line 14, in d ``` ZeroDivisionError: division by zero Blender quit Python: Traceback (most recent call last): ``` File "bug2.py", line 17, in <module> a() File "bug2.py", line 2, in a b() File "bug2.py", line 6, in b c() File "bug2.py", line 10, in c d() File "bug2.py", line 14, in d ``` 1/0 ZeroDivisionError: division by zero Admittedly all is not lost since the line numbers are preserved and you can cross reference it with your source file by hand to see the actual content of the offending line. However the way Blender does it right now is not too useful when you just want to get a quick look at the error and the code that caused it. Further it may be quite confusing to someone who doesn't know the technical reasons behind this behavior. Regardless, my motivation here is simply to advocate for a solution that helps others who might run into this same issue in the future. Thanks to your help I know what the problem is and can easily work around it (I just wrote a wrapper which imports my other code that can then be debugged as normal). However this was after quite a bit of confusion on my part and tinkering with the configuration of my debugger. It would be nice if others don't have to go through the same thing in the future.

Hi @gbantle-3, we had a surprising amount of trouble with Python on Windows, (can't use PyRun_File because of incompatible FILE structs), nevertheless, this is possible to support - looking into it.

Hi @gbantle-3, we had a surprising amount of trouble with Python on Windows, (can't use `PyRun_File` because of incompatible `FILE` structs), nevertheless, this is possible to support - looking into it.

This issue was referenced by 5f64b77ca5

This issue was referenced by 5f64b77ca5235465b52183d2ea519606253a354e

Changed status from 'Archived' to: 'Resolved'

Changed status from 'Archived' to: 'Resolved'
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#45955
No description provided.