Advice requested concerning FreeCAD python configuration

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
falviani
Posts: 253
Joined: Tue May 07, 2019 8:49 pm

Advice requested concerning FreeCAD python configuration

Post by falviani »

Hi All,

Extended info regarding my setup configuration, including python:
Weekly FC version:
OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.20.25645 (Git)
Build type: Release
Branch: master
Hash: 37d9757399b4c2ec30318eb88d7cd7c508246345
Python version: 3.8.6+
Qt version: 5.15.2
Coin version: 4.0.1
OCC version: 7.5.0
Locale: English/United States (en_US)

There are 2 versions of python installed in the Appdata/Local/Programs folder, as shown in the user-specific environment variables:
C:\Users\frank\AppData\Local\Programs\Python\Python38\Scripts\
C:\Users\frank\AppData\Local\Programs\Python\Python38\
C:\Users\frank\AppData\Local\Programs\Python\Python37-32\Scripts\
C:\Users\frank\AppData\Local\Programs\Python\Python37-32\

There is an old version of Python (Python 3.5) installed in it's own folder.

I installed debug.py while CDed into the appropriate FreeCad bin folder; it was installed in the python38 site-files folder.

In the workbench init.py folder I have the following suggested code:

Code: Select all

import debugpy
debugpy.configure(python="python")
debugpy.listen(5678)
debugpy.trace_this_thread(True)
debugpy.debug_this_thread()
In a previous question, it was suggested that I use the following configuration in the launch.json file:

Code: Select all

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Attach",
            "type": "python",
            "request": "attach",
            "connect": {
              "host": "localhost",
              "port": 5678
            },
            "justMyCode": false,
            "redirectOutput": true,
            "logToFile": true
          }
    ]
}
If I use this as is, I just get a 'connection refused error

In a previous version of the launch file, I would get the following error when I tried to debug the running app:

Code: Select all

"configurations": [     
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "E:\\FreeCAD\\FreeCAD_0.20.25645_Win-LPv12.5.4_vc17.x-x86-64\\FreeCAD_0.20.25645_Win-LPv12.5.4_vc17.x-x86-64\\bin\\FreeCAD.exe",
            "console": "integratedTerminal"
        }
    ]
File "C:\Users\frank\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 239, in _get_code_from_file
code = compile(f.read(), fname, 'exec')
ValueError: source code string cannot contain null bytes

My question is: Is there an issue with my python configuration? If so, how should I correct it so I can debug the workbench I am attempting to create?

I am a retired programmer with a variety of experience, but my professional experience was in C# for the last 13 years of my career. I did some Python on the side, but not a huge amount, and I am refreshing my knowledge of the language. The available MS documentation on debugging Python in VS Code doesn't match what I see in my version of VSC at all, and isn't useful. I did read the wiki chapter on creating workbenches, and I based my code on the starter kit by Joel Graff. I have spent several days trying to track down the source of the error, and a fix, with no success. I must be doing something quite wrong, as all suggestions I have received haven't worked for me.

All suggestions will be greatly appreciated.
-Frank Alviani
Post Reply