Skip to content

Instantly share code, notes, and snippets.

@natevw
Last active March 17, 2024 21:37
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save natevw/3e6fc929aff358b38c0a to your computer and use it in GitHub Desktop.
Save natevw/3e6fc929aff358b38c0a to your computer and use it in GitHub Desktop.
how I got FlatCAM 8.1 working on OS X [a long time ago — see comment thread for lots of good tips from others!]
brew update
brew install pyqt geos spatialindex
easy_install pip
pip install virtualenv
cd Development/Others\'/
mkdir FlatCAM
cd FlatCAM
virtualenv env
source env/bin/activate
pip install numpy matplotlib rtree scipy shapely simplejson
# copy contents of FlatCAM_8.1.zip into FlatCAM folder
python FlatCAM.py
@EMRosa
Copy link

EMRosa commented Nov 5, 2021

@mjparme , @tomoyanonymous , @MiroHibler

Setting vispy==0.6.6 in requirements.txt solved the issue for me as well. I'm clearly not a python guru, and wasn't aware that I could force the downgrade that way. haha. Thanks for all the help!

image

@MiroHibler
Copy link

@lienbacher @EMRosa @mjparme Thanks for reporting these issues. I updated flatcam-beta formula to version 8.9.94. (commit: f04d8be50fb57a489f7f7aa714ecf78d0dd266a6)

vispy-related error happened on my environment too, and it was reported on Linux environment.

https://bitbucket.org/jpcgt/flatcam/issues/538/ubuntu-fail-to-run-from-source

Fixing vispy to v0.7.0 is suggested solution, so I applied a patch to requirement.txt and it worked (on Catalina)

Try brew upgrade flatcam-beta.

Thank you @tomoyanonymous for great work, installing through Homebrew is the simplest and fastest way of installing FlatCAM on macOS :)

@MiroHibler
Copy link

BTW, anyone knows how to build FlatCAM.app?

@tomoyanonymous
Copy link

BTW, anyone knows how to build FlatCAM.app?

If you need .app as just a GUI launcher (= no need to copy or move the app to another machine), Automator is the easiest solution :)

Screen Shot 2021-11-06 at 12 00 11

I guess py2app or PyInstaller can build a portable bundle but anyway it requires codesigning to use on another machine, I prefer to use Automator.

@lienbacher
Copy link

@lienbacher @EMRosa @mjparme Thanks for reporting these issues. I updated flatcam-beta formula to version 8.9.94. (commit: f04d8be50fb57a489f7f7aa714ecf78d0dd266a6)

vispy-related error happened on my environment too, and it was reported on Linux environment.

https://bitbucket.org/jpcgt/flatcam/issues/538/ubuntu-fail-to-run-from-source

Fixing vispy to v0.7.0 is suggested solution, so I applied a patch to requirement.txt and it worked (on Catalina)

Try brew upgrade flatcam-beta.

Thank you @tomoyanonymous, unfortunately the same error I reported persists for me, plus there is one additional warning about networkx not found:

/usr/local/Cellar/flatcam-beta/8.9.94/libexec/lib/python3.9/site-packages/vispy/visuals/graphs/layouts/networkx_layout.py:10: UserWarning: Networkx not found, please install network to use its layouts
  warnings.warn(
Traceback (most recent call last):
  File "/usr/local/bin/flatcam", line 7, in <module>
    from app_Main import App
  File "/usr/local/Cellar/flatcam-beta/8.9.94/libexec/app_Main.py", line 52, in <module>
    from appDatabase import ToolsDB2
  File "/usr/local/Cellar/flatcam-beta/8.9.94/libexec/appDatabase.py", line 4, in <module>
    from camlib import to_dict
  File "/usr/local/Cellar/flatcam-beta/8.9.94/libexec/camlib.py", line 43, in <module>
    import rasterio
  File "/usr/local/lib/python3.9/site-packages/rasterio/__init__.py", line 22, in <module>
    from rasterio._base import gdal_version
ImportError: dlopen(/usr/local/lib/python3.9/site-packages/rasterio/_base.cpython-39-darwin.so, 2): Library not loaded: /usr/local/opt/gdal/lib/libgdal.28.dylib
  Referenced from: /usr/local/lib/python3.9/site-packages/rasterio/_base.cpython-39-darwin.so
  Reason: image not found

@tomoyanonymous
Copy link

@lienbacher

networkx warnings are shown on my environment too but it is working without problems.

It seems that gdal library is not installed correctly. It should be installed by homebrew as a dependency...
What version of OS are you running on? Can you see the /usr/local/opt/gdal/lib/libgdal.dylib ?

@lienbacher
Copy link

@lienbacher

networkx warnings are shown on my environment too but it is working without problems.

It seems that gdal library is not installed correctly. It should be installed by homebrew as a dependency... What version of OS are you running on? Can you see the /usr/local/opt/gdal/lib/libgdal.dylib ?

yes gdal is there:

% ls -l /usr/local/opt/gdal*
lrwxr-xr-x  1 wolfgang  admin  22  6 Nov 09:24 /usr/local/opt/gdal -> ../Cellar/gdal/3.3.2_4

brew says: gdal 3.3.2_4 already installed

@tomoyanonymous
Copy link

@lienbacher

Have you previously installed gdal on another environment like Conda?
The dylib in gdal 3.3.2_4 installed by brew is /usr/local/opt/gdal/lib/libgdal.29.dylib on my environment but I see that your rasterio library is trying to load the different version on your log.

Library not loaded: /usr/local/opt/gdal/lib/libgdal.28.dylib

@MiroHibler
Copy link

BTW, anyone knows how to build FlatCAM.app?

If you need .app as just a GUI launcher (= no need to copy or move the app to another machine), Automator is the easiest solution :)

I guess py2app or PyInstaller can build a portable bundle but anyway it requires codesigning to use on another machine, I prefer to use Automator.

@tomoyanonymous, thank you again! :) I did try with py2app already but it didn't work and I was too busy to investigate and fix it, so I opted for the Automator script, with one small addition (adding line export PATH=/usr/local/bin:$PATH) which made it work for me:

image

@MiroHibler
Copy link

@tomoyanonymous, thank you again! :) I did try with py2app already but it didn't work and I was too busy to investigate and fix it...

Well, I stand corrected:

py2applet --iconfile=~/Downloads/flatcam_icon256.icns --make-setup FlatCAM.py
python3 setup.py py2app -A

worked now (from the FlatCAM_beta_8.994_sources), but the app is incredible slow compared to the one started from the command prompt...

@juansebastianUTech
Copy link

hey guys, I am following @tomoyanonymous guide for installing flatcam beta on brew and I am getting this

Collecting vispy==0.7
  Downloading vispy-0.7.0.tar.gz (13.4 MB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
  Preparing metadata (pyproject.toml): started
  Preparing metadata (pyproject.toml): finished with status 'done'
ERROR: Could not find a version that satisfies the requirement ortools>=7.0 (from versions: none)
ERROR: No matching distribution found for ortools>=7.0

I am on a Mac M1 with monterey, any thoughts on what can be done about this / has anyone has have a similar issue?

@Gobol
Copy link

Gobol commented Feb 6, 2022

Ortools is a library maintained by Google, though open-sourced. Problem is - there is no build for Mac M1 arch. Me guessing You would have big troubles building it from source yourself. Best thing to do: give up native approach - use VM/linux.

@juansebastianUTech
Copy link

fair enough, thanks!

@berkakinci
Copy link

berkakinci commented Feb 7, 2022

Another option may be installing the x86_64 version of the package and let Rosetta2 do the translating. Something like:
arch --x86_64 brew install or-tools
I expect this will require and install a whole bunch of x86_64 requirements/libraries too.
[Caution: I haven't tried this myself.]
Also, I find it suspicious that I didn't find ortools but I found or-tools. May be that's the root issue.

@juansebastianUTech
Copy link

@berkakinci actually you are correct, I didnt find ortools but or-tools when I was doing some digging; do you guys know where do the package dependencies for flatcam are defined?, I would be more than happy to try modifying that.

in theory the x86_64 should work, but from my understanding homebrew is still working under Rossetta2, I am leaning towards the issue being the package naming

@berkakinci
Copy link

I did a little more digging earlier, but gave up.
Homebrew scripts from tomoyanonymous.
It's not a direct flatCAM dependency. It appears to be a vispy dependency based on your messages.
However, even vispy is not itself showing up in homebrew search. It may be coming in under something like Python pip or there is another name mapping -- I'm not familiar enough with homebrew internals.

@juansebastianUTech
Copy link

juansebastianUTech commented Feb 7, 2022

@berkakinci thanks for checking that out. mmm it could very well be that its part of pip :/. however I tried installing it under x86_64

arch --x86_64 brew install flatcam-beta
and got:

Error: Cannot install under Rosetta 2 in ARM default prefix (/opt/homebrew)!
To rerun under ARM use:
    arch -arm64 brew install ...
To install under x86_64, install Homebrew into /usr/local.

which makes sense since homebrew on M1 macs gets installed under /opt from my understanding
I will be looking into the pip dependency

@berkakinci
Copy link

Oh @juansebastianUTech FWIW, I was able to brew install flatcam-beta earlier today without problem; MacOS 11.6.3 on x86_64.
vispy doesn't show up in my brew list but it is listed under all 4 versions of pip I know about (sigh).

@berkakinci
Copy link

which makes sense since homebrew on M1 macs gets installed under /opt from my understanding

That's actually promising. Again, I'm not speaking from any experience here...
That may mean one of two thing:

  • You can install a whole x86_64 flatcam-beta version and all of its x86_64 dependencies; independent of any other homebrew stuff you have M1 native.
  • There is some trick in homebrew to have them cross over between the two architectures. I say that because homebrew already has a habit of installing stuff in location A and linking to them from a location B in your path. I imagine any dynamically-linked libraries that aren't universal will absolutely require two arch versions installed -- somehow...
    Good luck; and let me know if you resolve it. I'd like to be prepared for the arm64 move.

@juansebastianUTech
Copy link

ahh good point, I will report back if I can make it work!

@roamerP
Copy link

roamerP commented Feb 9, 2022

Hi, when running python3 FlatCAM.py I get ModuleNotFoundError: No module named 'ezdxf.math.vector'. How do I fix it?

I am on a MacBook Pro M1 with MacOS Monterey.
Regards RonnyP

@Day0Dreamer
Copy link

Well, I got it to run on macOS Monterey v12.1 Beta (21C5021h)!

After countless hours of trying to get it to work, I caved in and used Homebrew to install it, which almost worked - I only got the AttributeError: module 'vispy.visuals.markers' has no attribute '_marker_dict' error... ;)

Then I decided to give another try with @mjparme's instructions, with one addition - in requirements.txt file I didn't remove gdal (it didn't throw an error anymore, but it may also be due to Homebrew install) AND I set vispy==0.6.6 (v0.9.3 was installed). Than I ran pip3 install -r requirements.txt again, then python3 FlatCAM.py and... voilà! 🎆

Needless to say that Homebrew version now works as well ;)

image

That's how I got to work the latest beta on Windows11 with WSL 2 (Ubuntu)

@FlyingSamson
Copy link

I wonder if it would be possible to create a FlatCAM conda package and then create a conda environment that could be shared so FlatCAM is just ready to go?

For any Conda users out there, below is the yaml file I used to get FlatCam Beta 8.994 running on an M2 Pro chip with osx-64 as well as osx-arm64 (plus point of the latter is the native support of the dark system theme). I basically took the contents of requirements.txt and installed all but or ortools and rasterio through conda and additionally enforced vispy<=0.9.0 which is the last version where the _marker_dict still existed.

Not sure if this is relevant, but I used micromamba to create the conda environment from this environment file.

For osx-arm64:

micromamba create -n FlatCAM -f <path to FlatCAM.yml>

For osx-64:

CONDA_SUBDIR=osx-64 micromamba create -n FlatCAM -f <path to FlatCAM.yml>

Then just activate that environment

micromamba activate FlatCAM

and run in the unzipped Beta 8.994 directory

python FlatCam.py

Maybe this could be used as starting point for a Conda recipe?

# Content of File FlatCAM.yml
name: FlatCAM
channels:
  - conda-forge
dependencies:
  - python=3.8
  - pyqt>=5.12.1
  - numpy>=1.16
  - matplotlib>=3.1
  - cycler>=0.10
  - python-dateutil>=2.1
  - kiwisolver>=1.1
  - six
  - setuptools
  - dill
  - rtree
  - pyopengl
  - vispy<=0.9.0          # starting with 0.9.1 _marker_dict is gone
  #- ortools-python>=7.0  # only available on linux, use pip for the moment
  - svg.path>=4.0
  - simplejson
  - shapely>=1.7.0
  - freetype-py
  - fontTools
  #- rasterio             # produces missing gdal library error use pip for now
  - lxml
  - ezdxf
  - qrcode>=6.1
  - reportlab>=3.5
  - svglib
  - gdal
  - pyserial>=3.4
  - pip:
    - ortools>=7.0
    - rasterio

@dhysuiej
Copy link

Does anyone know whether a version of FlatCAM compatible with macOS Catalina could be built directly on Github Actions?

I'm currently following the steps in this video, but it's taking me too long to install pyqt via homebrew.

@jimwildman
Copy link

jimwildman commented Jun 17, 2023 via email

@SurathepThonthan
Copy link

FlatCAM_beta_8.994_sources % python FlatCAM.py

Traceback (most recent call last):
File "/Users//FlatCAM/FlatCAM_beta_8.994_sources/FlatCAM.py", line 6, in
from app_Main import App
File "/Users//FlatCAM/FlatCAM_beta_8.994_sources/app_Main.py", line 47, in
from appCommon.Common import LoudDict
File "/Users//FlatCAM/FlatCAM_beta_8.994_sources/appCommon/Common.py", line 88, in
class LoudUniqueList(list, collections.MutableSequence):
^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'collections' has no attribute 'MutableSequence'

plc help me

@alexcode9
Copy link

if you are using python 3.10+ change import collection in appCommon/Common.py to

import collection.abc
collections.Iterable = collections.abc.Iterable
collections.Mapping = collections.abc.Mapping
collections.MutableSet = collections.abc.MutableSet
collections.MutableMapping = collections.abc.MutableMapping

@alexrohde42
Copy link

alexrohde42 commented Mar 15, 2024

if you are using python 3.10+ change import collection in appCommon/Common.py to

import collection.abc
collections.Iterable = collections.abc.Iterable
collections.Mapping = collections.abc.Mapping
collections.MutableSet = collections.abc.MutableSet
collections.MutableMapping = collections.abc.MutableMapping

After that I get the error ModuleNotFoundError: No module named 'ezdxf.math.vector'
Module ezdxf is installed

How can I fix it?

Thanks for an reply

@FlyingSamson
Copy link

After that I get the error ModuleNotFoundError: No module named 'ezdxf.math.vector'

This was fixed on the Beta branch in this commit
See also this issue

@FlyingSamson
Copy link

I'm currently in the process of getting FlatCAM build with MacPorts.

I finally got it all working, but it will still take some time until I got all newly created port files for flatcams dependencies into shape to get them into the upstream macports repo.

One thing I wanted to share here, though: The problem with

AttributeError: module 'vispy.visuals.markers' has no attribute '_marker_dict' error

is due to a "patch" in appGui/VisPyPatches.py, which has long been available in upstream VisPy. So lines 16-34 in this file can safely be removed and then flatcam also runs with newer (i.e., > 0.9.0) vispy versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment