CadQuery / cadquery

A python parametric CAD scripting framework based on OCCT
https://cadquery.readthedocs.io
Other
3.21k stars 292 forks source link

Installing cadquery on macOS on Apple silicon #891

Closed jchidley closed 1 year ago

jchidley commented 3 years ago

Is there a way to install the current cadquery python library (the current master) on on an ARM based mac (currently M1)?

It is possible to install both the CQ-editor (binary download, I think) and Jupyter-CadQuery (using Docker) but not the vanilla library, as far as I can tell. I believe that there are no osx-arm64 versions of the packages.

Alternatively, is there a manual way to install the required files, perhaps by compiling them? A quick look suggests that the documentation on this is pretty sparse and that the process will be complex.

jmwright commented 3 years ago

It is a non-trivial task to build CadQuery's dependencies. You are correct that the documentation on this topic is pretty sparse. If you just want to use the library by itself, I have been doing manual assembly of an environment and then using LD_LIBRARY_PATH on MacOS and Linux to make sure the libs are loaded properly. As long as the underlying deps don't change too much, you can just pull the latest from CadQuery master to stay more current.

https://github.com/7BIndustries/Semblage/blob/master/.github/workflows/tests.yml#L34

jchidley commented 3 years ago

I understood your words @jmwright but I have failed to get to grips with the whole host of libraries and your link to Semblange tests.

Edit: this is a horrible hack but it's all I have at the moment

In the meantime, I have been taking a different route: using Docker and jupyter-cadquery.

Very roughly, you run jupyter-cadquery's docker image, adding -p 8866:8866 for jcv. Then add the Docker extension to Visual Studio before attaching to the jupyter-cadquery container. This installs the required VS Code files. The python extension will need to be added to the container.

Once attached to the container, open a terminal, run conda init then conda activate cq before starting jcv. It'll open a browser window for the viewer.

You'll have to add the python extension to the VS Code editor on the Docker container. Open your python file and then (potentially) open another terminal to run conda activate cq before changing the python interpreter to ('cq': conda).

Finally, you can run the python code and see the results.

jchidley commented 3 years ago

What I need to do, it turns out, is make another docker image.

tbo commented 2 years ago

@jmwright Are there any plans to support Apple Silicon natively?

jmwright commented 2 years ago

Are there any plans to support Apple Silicon natively?

I don't think the core team is opposed to it, but I also don't think that any of us has an M1 to develop/test on. I expect we'll run into signing requirements eventually that will require a paid developer account as well. It feels like MacOS is getting more difficult for small open source projects to support as time goes on rather than easier.

michaelgale commented 2 years ago

The key requirement is to build a native M1/arm64 OCP with pywrap. This is not trivial--I did build a macOS version of OCP to run on Mojave (10.14) (since the bundled CQ package is built for 10.15+). I do recall having to jump through many hoops to get a successful build--mainly related to C++ library dependencies and versions. I can sympathize with the CQ team that maintaining multiple build pipelines for different platforms is quite a burden. The peculiarities of the Apple toolchain ecosystem centred on Xcode doesn't help!

jchidley commented 2 years ago

Building the docker images for AMD64 on Apple M1 does work. It's a bit slow and drains the battery because it's an emulation, and you have docker to deal with too.

I'd prefer a native solution but CadQuery is worth it no matter how tricky the install is.

seanjensengrey commented 2 years ago

I am on an M1 mac running on the VMware Fusion Tech Preview for M1 the OS is Ubuntu 20.04.3 LTS. Does the CICD pipeline support doing arm64 (heh) builds?

miniforge has arm64 builds, install fails at

(cadquery) arm@arm:~$ conda install -c conda-forge -c cadquery cadquery=master
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.

PackagesNotFoundError: The following packages are not available from current channels:

  - cadquery=master

Current channels:

  - https://conda.anaconda.org/conda-forge/linux-aarch64
  - https://conda.anaconda.org/conda-forge/noarch
  - https://conda.anaconda.org/cadquery/linux-aarch64
  - https://conda.anaconda.org/cadquery/noarch

To search for alternate channels that may provide the conda package you're
looking for, navigate to

    https://anaconda.org

and use the search bar at the top of the page.
jchidley commented 2 years ago

I don't think that all of the software is available for arm64 machines, even virtual Linux ones. The only way that I could get this to work on my Mac was to use an AMD64 Docker image --platform=linux/amd64. It might be possible to do the same with your VMWare Fusion instead of Docker.

schluete commented 2 years ago

@jmwright since I'm in the same boat as others asking for an M1 version: can you elude a little bit to what exactly needs to be done for proper M1 support? After some (admittedly very little) research it seems like the primary problem is getting the OCCT wrapper compiled for M1. If that's the case, is it just that the setup is complicated, or are there closed-source components that would technically prevent an M1 version from being created? If it's the former I'd like to give it a shot.

smallstepman commented 2 years ago

I'm no expert, but I think its the former. Checkout these two links to gain deeper insight

It would be a dream come true for me to see this closed.

jmwright commented 2 years ago

I don't believe that any core developer has access to an M1 Mac for testing, but I think the bigger challenge is the lack of an Mac M1 runner in Azure Pipelines.

https://github.com/microsoft/azure-pipelines-agent/issues/3184

I don't think we are ready to do a self-hosted runner at this time.

https://itnext.io/run-azure-self-hosted-macos-agents-on-apple-m1-mac-72726555d83b

phillipthelen commented 1 year ago

I was able to install and use cadquery + cq-editor using the rosetta emulation layer. Obviously still not as good as native support, but still a bit better than using a VM or docker.

I used the following commands to get it to run

$ arch -x86_64 brew install miniconda
$ arch -x86_64 conda install -c cadquery -c conda-forge cadquery=master
$ arch -x86_64 conda install -c cadquery -c conda-forge cq-editor=master
$ arch -x86_64 /opt/homebrew/Caskroom/miniconda/base/bin/python

Instead of using arch -x86_64 in front of every command, it's also possible to do something like arch -x86_64 zsh beforehand. Then all commands run in that instance of zsh are run with rosetta.

szymansk commented 1 year ago

I am currently writing a Dockerfile for compiling OCP for arm64v8/ubuntu:22.04. Compilation and linking works, so far... The OCP.so seems to be functional. next step is to build the occ conda package... then building cadquery... when everything is done I am going to clean it up and push it to dockerhub...

Bildschirm­foto 2023-01-13 um 21 55 52
jmwright commented 1 year ago

@szymansk Please report back here when you publish that.

szymansk commented 1 year ago

@jmwright I published arm64v8 linux docker image here: https://hub.docker.com/r/szymanski2adesso/cadquery Thing is... there is currently no view... didn't have time to take a glance ad the visualisation. But we are changing the cq-server to visualise tesselated objects via REST.

I am going to make a fork of OCP and cadquery, where I add the docker file and make a pull-request.

Meanwhile the Dockerfile is here: https://github.com/szymansk/cadquery_arm64/tree/py3.9.15_ocp7.6.3_cadquery2

adam-urbanczyk commented 1 year ago

arm osx is available via conda-forge

ssbb commented 1 year ago

@adam-urbanczyk it will work for stable builds only right? (no way to build from master?)

Also cq-editor not here yet right?

adam-urbanczyk commented 1 year ago

Yes, only releases. All the deps are available, so you can technically install it, but not out of the box.

n8henrie commented 1 year ago

I've been interested in cadquery for a while but never delved in due to being on an M1 (so I've been watching this issue with interest).

Also never been a conda user (and don't really want it modifying my dotfiles). Being new to both cq and conda, I thought I'd share a few steps that got a working M1 jupyter environment for me:

#!/bin/bash

set -Eeuf -o pipefail
set -x

trap 'pkill -fl voila' EXIT

main() {
  . "/opt/homebrew/Caskroom/miniconda/base/etc/profile.d/conda.sh"

  conda deactivate || true
  # uncomment here to rebuild the conda env from scratch
  # conda env remove -n cadquery || true

  conda create \
    -y \
    -n cadquery \
    -c conda-forge \
    -c cadquery \
    python=3.11 \
    cadquery pip

  conda activate cadquery

  python -m pip install jupyter-cadquery cadquery-massembly matplotlib

  jcv &
  jupyter lab
}
main "$@"

This opens the jcv viewer as well as jupyter. If I paste into jupyter:

import cadquery as cq
from jupyter_cadquery.viewer.client import show

length = 80.0
height = 60.0
thickness = 100.0

result = cq.Workplane("XY").box(length, height, thickness)
show(result)

I can open the jcv viewer window and see the box rendered.

If I eventually figure out a plain pip (or nix) install I'll post it here, hope that's okay.

adam-urbanczyk commented 1 year ago

How is this better than https://github.com/CadQuery/cadquery#conda-installation ? You don't need to run conda init and modify any dot files. You can also use something like micromamba

n8henrie commented 1 year ago

Not trying to argue it's better in any way, just new territory for me.

Knowing nothing about conda, I had no idea what miniforge, conda forge, or minimamba are. I do all my python development with the built-in venv module and pip and generally shy away from poetry, pipenv, conda, etc.

It indeed looks like miniforge supports darwin-aarch64, and I'm sure would be a fine way to do things.

ssbb commented 1 year ago

Yeah miniforge works great on m1. To not mess with my env I just wrapped miniforge init code in function and call it when I need to work with cadquery

mosri commented 1 year ago

How is this better than https://github.com/CadQuery/cadquery#conda-installation ? You don't need to run conda init and modify any dot files. You can also use something like micromamba

So does the installation method mentioned here now work on Mac ARM? Just gotta use conda? Going to try to do this in Docker.

adam-urbanczyk commented 1 year ago

It should be possible, at least OCP is available for this platform:

osx-arm64 v7.7.0.1 linux-64 v7.7.0.1 win-64 v7.7.0.1 osx-64 v7.7.0.1

mosri commented 1 year ago

Anyone willing to help me troubleshoot installing cadquery on macOS Ventura (ARM) in Docker? Been messing with different versions of Conda and python and can't get it to install cadquery.

Also installs python 3.10 even when explicitly install 3.7.

Screenshot 2023-06-28 at 2 35 22 PM

Instructions using from miniforge https://github.com/conda-forge/miniforge

image image
jchidley commented 1 year ago

Sailing at the moment so I can’t help, sorry

Jack Chidley **@.* 07764 359921


From: @. @.> Sent: Wednesday, June 28, 2023 9:50:11 PM To: CadQuery/cadquery @.> Cc: Jack @.>; Author @.***> Subject: Re: [CadQuery/cadquery] Installing cadquery on macOS on Apple silicon (#891)

Anything willing to help me troubleshooting installing cadquery an OS X in Docker? Been messing with different versions of Conda and python and can't get it to install cadquery.

[Screenshot 2023-06-28 at 2 35 22 PM]https://user-images.githubusercontent.com/8907920/249595373-9becab26-c617-4a6e-98f4-f32dec91c9d8.png

— Reply to this email directly, view it on GitHubhttps://github.com/CadQuery/cadquery/issues/891#issuecomment-1612012255, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABYOSRORLXFJ5JCNUWRJ6WTXNSDHHANCNFSM5EXXJUCA. You are receiving this because you authored the thread.Message ID: @.***>

szymansk commented 1 year ago

try szymansk/cadquery_arm64

mosri commented 1 year ago

try szymansk/cadquery_arm64

Did not work for me. I got this error:

image

Please someone help me figure this out. I've been trying to get this to work for a really long time. Thank you.

n8henrie commented 4 months ago

Thanks to the work the cadquery team has done making wheels compatible with the M1, I was able to package up cadquery + OCP + jupyter for Apple Silicon into a nix flake.

If one has nix installed (and configured to use flakes), one can run JupyterLab with cadquery directly, without having to install anything else, with:

$ nix run github:n8henrie/nix-cadquery

I'm sure the intersection of nix + Apple Silicon + cadquery users is fairly small, but thought this might help lower the barrier for some to try it out. There are still several failing tests (having trouble figuring out casadi + ipopt -- help appreciated), but it seems to work for all of https://github.com/CadQuery/cadquery/blob/master/examples/CQ%20examples.ipynb