FreeCAD / FreeCAD-snap

The official Snap package of the FreeCAD project
https://snapcraft.io/freecad
9 stars 10 forks source link

How to call with Python? #20

Closed lindow2009 closed 2 years ago

lindow2009 commented 2 years ago

I have successfully installed freecad with snap, but I can't call it with Python. Errors are reported as follows: ImportError: libFreeCADApp.so: cannot open shared object file: No such file or directory

luzpaz commented 2 years ago

@lindow2009 when opening issues, please be thorough. We need your OS specs, FreeCAD specs. How are you trying to call FreeCAD with Python?

Doing a cursory search on the error gives this solution: https://stackoverflow.com/a/1100297

lindow2009 commented 2 years ago

Issue description environment:centos 7 version:0.19.4

python code: import FreeCAD import Part import Mesh shape = Part.Shape() shape.read('my_shape.step') doc = App.newDocument('Doc') pf = doc.addObject("Part::Feature","MyShape") pf.Shape = shape Mesh.export([pf], 'my_shape.stl')

error code : import FreeCAD as App ImportError: libFreeCADApp.so: cannot open shared object file: No such file or directory

ppd commented 2 years ago

The snap is not meant to provide a python module for the host system. All modules and libraries need the snap's environment to function properly. If you want to hack around in the snap's python environment, you can access the console via freecad.cmd. You can also add your extension in ~/snap/freecad/common and develop it that way.

lindow2009 commented 2 years ago

@ppd Sorry, I don't quite understand. Can you give me an example

ppd commented 2 years ago

@lindow2009 You can only use the python modules from within the snap. You can execute your python code by creating a macro, or even a workbench. I suggest starting with https://wiki.freecadweb.org/Macros. In this way, your script will be executed in the correct environment where it will find all python modules contained in the snap.