Hi,
i run FreeCAD succesfully on windows via python after I appended the /bin folder to the sys path.
I can then import FreeCAD
But it does not work with
import importDAE
or even the numpy module. Do I need to append additional paths?
import numpy or import importDAE
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: import numpy or import importDAE
If you are trying to execute FreeCAD as a module, in other word invoking FreeCAD as a LIbrary, you should be aware of this wiki page:
https://wiki.freecadweb.org/Embedding_F ... ithout_GUI
Under Caveats is said that:
Hope it helps.Although it is possible to import FreeCAD to an external Python interpreter, this is not a common usage scenario and requires some care.
Regards
Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
-
- Posts: 74
- Joined: Sun May 07, 2023 12:18 pm
Re: import numpy or import importDAE
I know this is an old post, but I'm facing similar problems.
I can import Part and Mesh, but this module says it's not encountered, and there is no file called importDAE.so.
What can I do instead?
I can importDEA in the FreeCAD console, and I already check the path to importDEA.py but I'm not sure I to do it while using FreeCAD as a library.
Thanks in advance.
I can import Part and Mesh, but this module says it's not encountered, and there is no file called importDAE.so.
What can I do instead?
I can importDEA in the FreeCAD console, and I already check the path to importDEA.py but I'm not sure I to do it while using FreeCAD as a library.
Thanks in advance.
Re: import numpy or import importDAE
I run FreeCAD as a library and "import importDAE" works just fine.JorgeFernandes wrote: ↑Fri May 26, 2023 9:23 pm but I'm not sure I to do it while using FreeCAD as a library.
My setup is described here: viewtopic.php?t=78047
-
- Posts: 74
- Joined: Sun May 07, 2023 12:18 pm
Re: import numpy or import importDAE
Hi.bdm wrote: ↑Sat May 27, 2023 6:27 amI run FreeCAD as a library and "import importDAE" works just fine.JorgeFernandes wrote: ↑Fri May 26, 2023 9:23 pm but I'm not sure I to do it while using FreeCAD as a library.
My setup is described here: viewtopic.php?t=78047
Thanks for the help. It's possible to do something similar with vscode?
Re: import numpy or import importDAE
Sure. Your problem with importing "numpy" or "importDAE" is not a problem of the Python-IDE but a problem of the proper Python interpreter with the proper paths to the libraries. In your vscode configuration, use the Python interpreter that is shipped with FreeCAD (or a binary compatible version) and set the paths accordingly. If you are using Linux with the FreeCAD AppImage, you can create a "python_freecad.sh" interpreter script that manages the paths for you (see the link in my previous post), and then set this as the Python executable in vscode.JorgeFernandes wrote: ↑Sat May 27, 2023 10:20 am Thanks for the help. It's possible to do something similar with vscode?
-
- Posts: 74
- Joined: Sun May 07, 2023 12:18 pm
Re: import numpy or import importDAE
Thanks. Your posts help me in a certain way.bdm wrote: ↑Sat May 27, 2023 4:46 pmSure. Your problem with importing "numpy" or "importDAE" is not a problem of the Python-IDE but a problem of the proper Python interpreter with the proper paths to the libraries. In your vscode configuration, use the Python interpreter that is shipped with FreeCAD (or a binary compatible version) and set the paths accordingly. If you are using Linux with the FreeCAD AppImage, you can create a "python_freecad.sh" interpreter script that manages the paths for you (see the link in my previous post), and then set this as the Python executable in vscode.JorgeFernandes wrote: ↑Sat May 27, 2023 10:20 am Thanks for the help. It's possible to do something similar with vscode?
I manage to be able to do imports by appending the freecad paths to the sys at the top of the script.
Thanks for your attention.
-
- Posts: 74
- Joined: Sun May 07, 2023 12:18 pm
Re: import numpy or import importDAE
This is what I did for anyone with a similar problem (not the best way for sure, but it works).
Note that you have to do this on top of each script using freecad lib.
Note that you have to do this on top of each script using freecad lib.
Code: Select all
import sys
import os
freecad_path = '/usr/lib/freecad/lib/'
freecad_path_mod = '/usr/share/freecad/Mod'
freecad_path_ext = '/usr/share/freecad/Ext'
# Get a list of all files in the directory
file_list = os.listdir(freecad_path_mod)
# Iterate over the files and append each file to sys.path
for file_name in file_list:
file_path = os.path.join(freecad_path_mod, file_name)
sys.path.append(file_path)
sys.path.append(freecad_path)
sys.path.append(freecad_path_ext)
import FreeCAD as FreeCAD
import Part
import MeshPart
import Import
import importDAE