voneiden / ocp-freecad-cam

CAM for CadQuery and Build123d by leveraging FreeCAD
https://pypi.org/project/ocp-freecad-cam/
Apache License 2.0
30 stars 3 forks source link

Installation - Import error with numpy #22

Closed mukral closed 8 months ago

mukral commented 10 months ago

Hello, my environment is Linux-Ubuntu with VS Code and working build123d package on python 3.11. freecad_ocp_cam installation is done with freecad.pth file in site-packages and I think it works because I got an error trying to execute freecad_ocp_cam-code which calls numpy from a package in this path.

The error message is:

File "/home/.../freecad/squashfs-root/usr/lib/python3.10/site-packages/numpy/init.py", line 135, in raise ImportError(msg) from e ImportError: Error importing numpy: you should not try to import numpy from its source directory; please exit the numpy source tree, and relaunch your python interpreter from there.

Has anyone had this before?

Thank you Markus

voneiden commented 10 months ago

One possible issue (I should highlight this in the readme) is that if your system interpreter is 3.11 it will probably not work with the 3.10 python modules in the squashfs-root.

voneiden commented 10 months ago

I ran the CI job to rule out any issues with the newer versions of the appimage and it did pass https://github.com/voneiden/ocp-freecad-cam/actions/runs/6548879401

mukral commented 10 months ago

I don't think it's a versioning problem (not at this point). It seems to have something to do with the working directories. I've found on stackoverflow something similar: "You cannot import tensorflow whilst you are in the tensorflow source directory. Change Directory i.e. cd .. first before running python." But code and freecad-packages are in different directories.

Ah ok - yes, I was in the directory where my code saved. Solved sorry, (got module not found error...)

mukral commented 10 months ago

Ah no, is back - I also deleted the freecad.pth-file and this cleared the error, not leaving the directory. File is back, error is back... I'm looking into it...

mukral commented 10 months ago

I set up new Ubuntu environment. And came a step further: Seems to import some of the packages where it stopped before (numpy). Some packages that were installed in freecad environment but not in python-environment caused errors, I removed the freecad.pth file, installed via pip, pasted freecad.pth file back and could go on (sheboken2, pyside,...).

Final stop is here, nothing worked to get over that error (pip & apt-get install and uninstall), it seems to do with pyqt5-library.

File "/home/.../.venv/freecad/squashfs-root/usr/Ext/PySide/QtCore.py", line 1, in from PySide2.QtCore import * ImportError: /home/tux/Dokumente/.venv/lib/python3.11/site-packages/PySide2/Qt/lib/libQt5Network.so.5: undefined symbol: _ZdaPvm, version Qt_5

Any idea?

mukral commented 10 months ago

Finally I've got it running: in a conda environment it worked. I've startet from scratch again, this time with debian.

Here is from beginning step by step, I hope I didn't forget anything:

install Debian + XFCE sudo apt install pip sudo apt install git

Install Conda (good description https://docs.conda.io/projects/conda/en/latest/user-guide/install/rpm-debian.html)

sudo apt install snapd snap install --classic code #visual studio code sudo ln -s /var/lib/snapd/desktop/applications /usr/share/applications/snapd #make vs code available in Application Finder start vs code in application finder in VS Code: go to marketplace and install: python OCP CAD Viewer press F1 - type python -look for "select interpreter" and choose you interpreter goto Explorer and open a folder press F1 type python create conda environment as python interpreter set python3.10 goto OCP CAD Viewer (symbol on left menue) Quickstart build123d install jupyter (from Viewer Manager) Install Freecad libs like in description make Directory "freecad" in your venv environment Download freecad weekly paste freecad weekly to freecad-directory extract (chmod + appimage-extract) create freecad.pth -> copy&paste your venv-paths -> save as described in VS Code goto terminal check environment: which python (should be .conda) check interpreter with F1 python: select interpreter goto to terminal: python -m pip install ocp_freecad_cam If you are not in your correct conda-environment: F1 -> python: create environment -> choose conda -> choose existing -> close vs code -> open vs code Create file and test

In OCP-Viewer the path is not shown like in example but no error and I can download freecad-file and open in Freecad

Sorry that it looks like this - all my tabs are gone.

Maybe it helps... Markus

voneiden commented 10 months ago

Good to hear! I'll try to check what's up with ocp viewer. I have a faint memory it has worked at some point at least, but let's see.

voneiden commented 10 months ago

It looks like OCP viewer works for me, with the following code

from ocp_vscode import (
    get_defaults,
    reset_show,
    set_defaults,
    set_port,
    show,
    show_object,
 )

set_port(3939)

import cadquery as cq

from ocp_freecad_cam import Endmill
from ocp_freecad_cam.api import Dogbone, Job

wp = (
    cq.Workplane()
    .rect(10, 10)
    .extrude(5)
    .faces(">Z")
    .workplane()
    .rect(8, 8)
    .cutBlind(-2)
    .faces(">Z")
    .rect(10, 2)
    .cutBlind(-2)
)

pckt = wp.faces(">Z[1]")
avoid = wp.faces(">Z")
top = avoid.workplane()
tool = Endmill(diameter=1)
tool2 = Endmill(diameter=2)
job = Job(top, wp.objects[0], "grbl")
job = job.pocket(pckt, tool=tool, pattern="offset")import logging
import sys

job = job.profile(
    pckt.objects[0].outerWire(), side="in", tool=tool, dressups=[Dogbone()]
)

# job.show will display the toolpaths
ais_job = job.show(show_object)

# show the pocket face
show_object(pckt)

I get

image

voneiden commented 8 months ago

Hi @mukral

I've just confirmed that ocp-freecad-cam works with FreeCAD 0.21.2 under Python 3.11 and Ubuntu. There are a few gotchas:

1) If using AppImage, Ubuntu and probably Debian now requires using my fork of the AppImage which contains an older version of OpenSSL: https://github.com/voneiden/FreeCAD-Bundle/releases/tag/0.21.2 (this is due to issue #24) 2) PYTHONPATH must include /home/user/freecad/squashfs-root/usr/lib/python3.11/site-packages/ instead of python3.10.

voneiden commented 8 months ago

Recommended linux installation guide has been updated with a more reliable method: https://github.com/voneiden/ocp-freecad-cam#linux-appimage-installation-example-using-a-venv