import numpy or import importDAE

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
zoidberg
Posts: 34
Joined: Mon Nov 18, 2013 2:59 pm

import numpy or import importDAE

Post by zoidberg »

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?
User avatar
onekk
Veteran
Posts: 6149
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: import numpy or import importDAE

Post by onekk »

zoidberg wrote: Fri Sep 23, 2022 2:24 pm 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?
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:
Although it is possible to import FreeCAD to an external Python interpreter, this is not a common usage scenario and requires some care.
Hope it helps.

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/
JorgeFernandes
Posts: 74
Joined: Sun May 07, 2023 12:18 pm

Re: import numpy or import importDAE

Post by JorgeFernandes »

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.
bdm
Posts: 178
Joined: Sat Dec 31, 2022 12:10 pm

Re: import numpy or import importDAE

Post by bdm »

JorgeFernandes wrote: Fri May 26, 2023 9:23 pm but I'm not sure I to do it while using FreeCAD as a library.
I run FreeCAD as a library and "import importDAE" works just fine.
My setup is described here: viewtopic.php?t=78047
JorgeFernandes
Posts: 74
Joined: Sun May 07, 2023 12:18 pm

Re: import numpy or import importDAE

Post by JorgeFernandes »

bdm wrote: Sat May 27, 2023 6:27 am
JorgeFernandes wrote: Fri May 26, 2023 9:23 pm but I'm not sure I to do it while using FreeCAD as a library.
I run FreeCAD as a library and "import importDAE" works just fine.
My setup is described here: viewtopic.php?t=78047
Hi.

Thanks for the help. It's possible to do something similar with vscode?
bdm
Posts: 178
Joined: Sat Dec 31, 2022 12:10 pm

Re: import numpy or import importDAE

Post by bdm »

JorgeFernandes wrote: Sat May 27, 2023 10:20 am Thanks for the help. It's possible to do something similar with vscode?
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
Posts: 74
Joined: Sun May 07, 2023 12:18 pm

Re: import numpy or import importDAE

Post by JorgeFernandes »

bdm wrote: Sat May 27, 2023 4:46 pm
JorgeFernandes wrote: Sat May 27, 2023 10:20 am Thanks for the help. It's possible to do something similar with vscode?
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.
Thanks. Your posts help me in a certain way.
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.
JorgeFernandes
Posts: 74
Joined: Sun May 07, 2023 12:18 pm

Re: import numpy or import importDAE

Post by JorgeFernandes »

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.

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

Post Reply