help with Python import path

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
rtoller
Posts: 3
Joined: Sat Mar 12, 2011 4:32 pm

help with Python import path

Post by rtoller »

Hi,

I'm running FreeCAD on Fedora, using wine - because it seemed easier to install the exe rather than than trying to build FreeCAD myself from source. It's working fine, except...

I'm trying to debug a python script by running it from the linux console (if there's a bug in the script and I run it from FreeCAD, nothing happens - i.e. I don't get a message in FreeCAD telling me what the problem is with the script). The problem is, I have this at the top of my script:

Code: Select all

import sys
sys.path.append("/home/richard/.wine/drive_c/Program Files/FreeCAD0.10/bin")
but when I run it from the console, I get

Code: Select all

ImportError: No module named FreeCAD
If I look in /home/richard/.wine/drive_c/Program Files/FreeCAD0.10/bin I see what look like the requisite files - including FreeCAD.pyd, FreeCADGui.dll, etc.

Should this work? Any help much appreciated - I'm new to all this.

Many thanks,
Richard
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: help with Python import path

Post by wmayer »

Make sure that the path where FreeCAD.pyd is located is in your system path because otherwise it may have troubles to load the DLL files.
rtoller
Posts: 3
Joined: Sat Mar 12, 2011 4:32 pm

Re: help with Python import path

Post by rtoller »

Isn't that what

Code: Select all

sys.path.append("/home/richard/.wine/drive_c/Program Files/FreeCAD0.10/bin")
does?

Is there something else I have to do to get it in the system path?
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: help with Python import path

Post by wmayer »

No.
sys.path.append("/home/richard/.wine/drive_c/Program Files/FreeCAD0.10/bin")
makes only sure that Python knows where to find the Python module. But since this is a Python extension module, i.e. o normal DLL (or .so file) Windows/Wine must also know where to load this DLL. So, you have to do something like (I don't know whether this is the right syntax for Wine)
set PATH=%PATH%;/home/richard/.wine/drive_c/Program Files/FreeCAD0.10/bin
rtoller
Posts: 3
Joined: Sat Mar 12, 2011 4:32 pm

Re: help with Python import path

Post by rtoller »

Ah, of course - I need to run Python from Wine too. I was trying to run the script directly from my Linux console.
Thanks.
Post Reply