Embedding FreeCAD in a Python virtual environment

Having trouble installing or compiling FreeCAD? Get help here.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
mlaura.leonardi
Posts: 12
Joined: Mon Sep 26, 2022 3:02 pm

Re: Embedding FreeCAD in a Python virtual environment

Post by mlaura.leonardi »

Its probably this!(see figure attached). I was wondering if it is possible to compile manually FreeCAD in such a way of having the Python version that I wish
Attachments
Screenshot 2022-09-29 092055.png
Screenshot 2022-09-29 092055.png (156.14 KiB) Viewed 565 times
mlaura.leonardi
Posts: 12
Joined: Mon Sep 26, 2022 3:02 pm

Re: Embedding FreeCAD in a Python virtual environment

Post by mlaura.leonardi »

I am not sure it is this problem, because since I have installed the Python 3.8, the problem persist
mlaura.leonardi
Posts: 12
Joined: Mon Sep 26, 2022 3:02 pm

Re: Embedding FreeCAD in a Python virtual environment

Post by mlaura.leonardi »

Guys!!! Its is now working. In windows it is needed to specify: :D

Code: Select all

import sys
PATH = 'C:\\Program Files\\FreeCAD 0.20\\bin'
sys.path.append(PATH)

from bin import FreeCAD
doc = FreeCAD.open('document.FCStd')
maybe we should add this detail in the wiki documentation ;)
Attachments
bin.png
bin.png (9.02 KiB) Viewed 525 times
mlaura.leonardi
Posts: 12
Joined: Mon Sep 26, 2022 3:02 pm

Re: Embedding FreeCAD in a Python virtual environment

Post by mlaura.leonardi »

mmm... not even this really works as it should. I am not sure that in windows the possibility of embedding FreeCAD is actually working.. i am loosing hopes
Screenshot 2022-09-29 121127.png
Screenshot 2022-09-29 121127.png (14.46 KiB) Viewed 506 times
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Embedding FreeCAD in a Python virtual environment

Post by wmayer »

I am not sure that in windows the possibility of embedding FreeCAD is actually working.. i am losing hopes
I wonder what this line does:

Code: Select all

from bin import FreeCAD
Does it really load the file FreeCAD.pyd? You should check the content of FreeCAD.__file__

Then the next statement (import Part) seems to cause a problem but you didn't post an error message. In order to troubleshoot the error you need the utility Dependency Walker (DW). Assuming you have unpacked the zip into C:\Temp you should add this line before import Part.

Code: Select all

import os
os.system("C:/Temp/depends.exe")
This will block the further execution of the script and you can load a dll into DW. Now load the file Part.pyd and check if there is any dll that cannot be resolved.
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: Embedding FreeCAD in a Python virtual environment

Post by adrianinsaval »

try the conda version please: https://github.com/FreeCAD/FreeCAD-Bund ... tag/0.20.1
running python3.10 I had no trouble adding freecad to sys.path and then importing, didn't even need the add_dll_directory line
Post Reply