Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@masteruan

This comment has been minimized.

Copy link

@masteruan masteruan commented Mar 26, 2017

All seems OK but...
Traceback (most recent call last):
File "FlatCAM.py", line 2, in
from PyQt4 import QtGui, QtCore
ModuleNotFoundError: No module named 'PyQt4'

@CONSULitAS

This comment has been minimized.

Copy link

@CONSULitAS CONSULitAS commented May 19, 2017

With FlatCAM 8.5 similar here:

Traceback (most recent call last):
  File "/Users/hi345gr/Documents/_Sync/GitHub/FlatCAM/flatcam/FlatCAM.py", line 10, in <module>
    from PyQt4 import QtGui
ImportError: cannot import name QtGui
@jeli1

This comment has been minimized.

Copy link

@jeli1 jeli1 commented Oct 7, 2017

cd Development/Others'/ No such file or directory ?

@uvwxy

This comment has been minimized.

Copy link

@uvwxy uvwxy commented Oct 22, 2017

By default, brew installs PyQt5. I found this page that describes how to install PyQt4 instead of PyQt5:

https://robonobodojo.wordpress.com/2017/02/08/installing-pyqt4-on-mac-osx/

With this I could proceed to the next error ;)

Edit: pip2 install svg.path, was missing on my machine

@CONSULitAS

This comment has been minimized.

Copy link

@CONSULitAS CONSULitAS commented Apr 18, 2018

By default, brew installs PyQt5. I found this page that describes how to install PyQt4 instead of PyQt5:
https://robonobodojo.wordpress.com/2017/02/08/installing-pyqt4-on-mac-osx/
With this I could proceed to the next error ;)
Edit: pip2 install svg.path, was missing on my machine

@uvwxy Great!

just

brew install cartr/qt4/pyqt
pip2 install svg.path
./flatcam

Voila: Running FlatCAM 8.5 on a Mac with High Sierra

bildschirmfoto 2018-04-19 um 00 35 28

Only 11 months later 👍

@dikkedimi

This comment has been minimized.

Copy link

@dikkedimi dikkedimi commented Jul 10, 2018

can't do pip easy_install because brew won't update openssl. Anyone with experience here? starting to become annoyed :( am on macos 10.12.6 with brew python 2.7 and OpenSSL 1.0.2o 27 Mar 2018

@dikkedimi

This comment has been minimized.

Copy link

@dikkedimi dikkedimi commented Jul 10, 2018

I was able to install pip using

sudo python -m ensurepip

@appideasDOTcom

This comment has been minimized.

Copy link

@appideasDOTcom appideasDOTcom commented Aug 14, 2018

Even after following the directions at https://robonobodojo.wordpress.com/2017/02/08/installing-pyqt4-on-mac-osx/ and having PyQt4 installed, the newest "flatcam" script is specifically coded to use python 3, which I couldn't - for the life of me - get to recognize PyQt4 instead of PyQt5. The installation of python 2 is seeing PyQt4, so the only path I could think of to get FlatCAM working on macOS for me was to re-python2-ize the code:

Change line 1 of flatcam to
#!/usr/bin/env python2

Change line 11 of FlatCAMApp.py to
import urllib

Change line 19 of FlatCAMApp.py to
import Tkinter
(upper case "T")

Change line 649 of FlatCAMApp.py to
self.tcl = Tkinter.Tcl()

Change line 868 of FlatCAMApp.py to
except Tkinter.TclError as e:

Change urllib.parse.urlencode to urllib.urlencode on line 4286 of FlatCAMApp.py

Change urllib.request.urlopen to urllib.urlopen on line 4291 of FlatCAMApp.py

Remove the asterisk from line 56 of tclCommands/TclCommandListSys.py

Finally, running this command:
pip install future

After all that, running ./flatcam works.

I know that's super-kludgy and not sustainable, but it makes it so that I don't have to mess with a linux virtual machine to run FlatCAM.
screen shot 2018-08-14 at 2 26 55 pm

@Baekalfen

This comment has been minimized.

Copy link

@Baekalfen Baekalfen commented Aug 28, 2018

Additional to all of the above, I also had to change line 3401 in camlib.py to for line in StringIO(unicode(self.gcode, "utf-8")):. And the same for line 1167 in FlatCAMObj.py. Otherwise, I cannot generate gcode.

Here is my patch based on 46454c29:

diff --git a/FlatCAMApp.py b/FlatCAMApp.py
index 3fe46be..c9416c1 100644
--- a/FlatCAMApp.py
+++ b/FlatCAMApp.py
@@ -8,7 +8,7 @@
 
 import sys
 import traceback
-import urllib.request, urllib.parse, urllib.error
+import urllib
 import getopt
 import random
 import logging
@@ -16,7 +16,7 @@ import simplejson as json
 import re
 import webbrowser
 import os
-import tkinter
+import Tkinter
 from PyQt4 import Qt, QtCore, QtGui
 import time  # Just used for debugging. Double check before removing.
 from xml.dom.minidom import parseString as parse_xml_string
@@ -646,7 +646,7 @@ class App(QtCore.QObject):
             # because tcl  was execudted in old instance of TCL
             pass
         else:
-            self.tcl = tkinter.Tcl()
+            self.tcl = Tkinter.Tcl()
             self.setup_shell()
 
     def defaults_read_form(self):
@@ -865,7 +865,7 @@ class App(QtCore.QObject):
             if result != 'None':
                 self.shell.append_output(result + '\n')
 
-        except tkinter.TclError as e:
+        except Tkinter.TclError as e:
             # This will display more precise answer if something in TCL shell fails
             result = self.tcl.eval("set errorInfo")
             self.log.error("Exec command Exception: %s" % (result + '\n'))
@@ -4283,12 +4283,12 @@ class App(QtCore.QObject):
             "?s=" + str(self.defaults['serial']) + \
             "&v=" + str(self.version) + \
             "&os=" + str(self.os) + \
-            "&" + urllib.parse.urlencode(self.defaults["stats"])
+            "&" + urllib.urlencode(self.defaults["stats"])
         App.log.debug("Checking for updates @ %s" % full_url)
 
         ### Get the data
         try:
-            f = urllib.request.urlopen(full_url)
+            f = urllib.urlopen(full_url)
         except:
             # App.log.warning("Failed checking for latest version. Could not connect.")
             self.log.warning("Failed checking for latest version. Could not connect.")
diff --git a/FlatCAMObj.py b/FlatCAMObj.py
index 8529b60..bb30b01 100644
--- a/FlatCAMObj.py
+++ b/FlatCAMObj.py
@@ -1164,7 +1164,7 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
 
     def export_gcode(self, filename, preamble='', postamble='', processor=''):
 
-        lines = StringIO(self.gcode)
+        lines = StringIO(unicode(self.gcode, "utf-8"))
 
         ## Post processing
         # Dwell?
diff --git a/camlib.py b/camlib.py
index b41b08a..b49b957 100644
--- a/camlib.py
+++ b/camlib.py
@@ -3395,7 +3395,7 @@ class CNCjob(Geometry):
         path = [(0, 0)]
 
         # Process every instruction
-        for line in StringIO(self.gcode):
+        for line in StringIO(unicode(self.gcode, "utf-8")):
 
             gobj = self.codes_split(line)
 
diff --git a/flatcam b/flatcam
index fb3daa8..3c5ef0b 100755
--- a/flatcam
+++ b/flatcam
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python2
 ############################################################
 # FlatCAM: 2D Post-processing for Manufacturing            #
 # http://flatcam.org                                       #
diff --git a/tclCommands/TclCommandListSys.py b/tclCommands/TclCommandListSys.py
index 87d5a76..d4b9575 100644
--- a/tclCommands/TclCommandListSys.py
+++ b/tclCommands/TclCommandListSys.py
@@ -53,4 +53,4 @@ class TclCommandListSys(TclCommand):
             argument = args['selection']
             return str([k for k in self.app.defaults.keys() if str(k).startswith(str(argument))])
         else:
-            return str([*self.app.defaults])
\ No newline at end of file
+            return str([self.app.defaults])
@jimwildman

This comment has been minimized.

Copy link

@jimwildman jimwildman commented Dec 7, 2018

downgrading the code to python 2.7 worked well for me.
If you wish to use py2app to compile a standalone osx app, you will find the icons are missing.

If you right click on the flatcam.app and select show contents, you will be able to copy flatcam/share to the app folder/contents/MacOS the icons will reappear.

Or you can start over and use the --resources parm on the py2applet command to grab them although I believe they will then be in resources and not MacOS so you will still have to move them.
Also you can use flatcam/share/flatcamicon48.ico in the --iconfile parameter of the py2applett command to get an icon on the app.

flatcam is just like any other osx app now. in the applications folder, in launcher, can be "Kept" in the task bar, e.t.c.

Any program messages will go the the osx console.

@Bougakov

This comment has been minimized.

Copy link

@Bougakov Bougakov commented Dec 15, 2019

Since this thread pops up in Google while searching for "FlatCam on Mac OS", but the solution no longer works - here is the recipe I've found.

Dealing with Python2 and QT4 on MacOS Mojave is futile, so the only option is to move to Python3.

You'd need to check out https://muut.com/flatcam#!/developers:flatcam-beta - this page features a FlatCam fork called "FlatCAM_beta" Get the latest ZIP file with sources from https://bitbucket.org/jpcgt/flatcam/downloads/?tab=downloads (I used FlatCAM_beta_8.98_sources.zip):

mkdir FlatCAM
cd ~/FlatCAM
wget https://bitbucket.org/brainstorm/flatcam/get/e7f9fbca8519.zip
unzip e7f9fbca8519.zip
cd FlatCAM_beta_8.98_sources

You'll also need to have Homebrew installed:

xcode-select --install
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Next, install required modules and run FlatCAM:

brew install pyqt
python3 -m ensurepip
python3 -m pip install -r requirements.txt
python3 -m pip install PyQt5
python3 FlatCAM.py

To build an .app wrapper for the Launchpad:

python3 -m pip install py2app 
py2applet --make-setup flatCAM.py
python3 setup.py py2app -A 
cd dist
open .

Drag the newly built flatCAM.app to the Applications folder.

image

@Bougakov

This comment has been minimized.

Copy link

@Bougakov Bougakov commented Dec 15, 2019

https://muut.com/flatcam#!/developers:flatcam-beta-works-on-macos - brief description of my partially unsuccessful attempts to make a native app from FlatCam using py2app

@ghabreu

This comment has been minimized.

Copy link

@ghabreu ghabreu commented Dec 17, 2019

Thanks @Bougakov, got it working on 10.14.6 as well!
Instead of running each command separately, you could use only python3 -m pip install -r requirements.txt for the dependencies. A few of them were missing from your list, so I had to do it anyway. But i didn't check if only the .txt would be enough.

@charles83m

This comment has been minimized.

Copy link

@charles83m charles83m commented Mar 12, 2020

Good afternoon Bougakov,
I have been able to install Flatcam on my mac but unfortunately everything is working fine until I try to generate CNC geometry.
At that point when I hit "Generate CNCJob object" I get a crash of the app.
Do you know how can I fix this?
Thanks a lot

Carlo

@ah1102

This comment has been minimized.

Copy link

@ah1102 ah1102 commented Apr 21, 2020

I had an error during installation:

from PyQt5 import QtWidgets, QtGui ModuleNotFoundError: No module named 'PyQt5'

I had to use the command:

python3 -m pip install PyQt5


Here is an article on how to create a full-fledged application (but nothing worked for me)

From a Python script to a portable Mac application with py2app http://www.marinamele.com/from-a-python-script-to-a-portable-mac-application-with-py2app

@Bougakov

This comment has been minimized.

Copy link

@Bougakov Bougakov commented Apr 21, 2020

I had an error during installation:

probably, you've missed brew install pyqt

@ah1102

This comment has been minimized.

Copy link

@ah1102 ah1102 commented Apr 21, 2020

No, I did not miss this command. The brew install pyqt command probably installed PyQt5 in Python in a different version or somewhere else. And the python3 -m pip install PyQt5 command helped me https://www.youtube.com/watch?v=eQaK3m9j8rs&t=84s

Now I am interested in 2 things.

  1. add icon in .app.
  2. Create a standalone portable .app.

Your version of python3 setup.py py2app -A creates an incomplete application that cannot be transferred to another computer. If you use python3 setup.py py2app, then a standalone application will be created, but you need a customized setup.py file with dependencies.

Have you tried to work in this direction or can you help?

The problem is that the author does not update the repository. It publishes the latest versions in .zip without updating the repository. And no setup.py.

@Bougakov

This comment has been minimized.

Copy link

@Bougakov Bougakov commented Apr 23, 2020

creates an incomplete application that cannot be transferred to another computer

Yes, I've mentioned that the resulting app is only a "wrapper". I spent 5 mins on trying to make a standalone app, saw that it is huge (since it creates a copy of all Python libs) and unstable, and gave up.

@ah1102

This comment has been minimized.

Copy link

@ah1102 ah1102 commented Apr 23, 2020

Do you know how to connect an icon?

@ah1102

This comment has been minimized.

Copy link

@ah1102 ah1102 commented Apr 23, 2020

To add an application icon, you need to take share/dark_resources/flatcam_icon128.png from the program folder and convert it in the online converter https://cloudconvert.com/png-to-icns to the .icns format.

py2applet --iconfile=share/dark_resources/flatcam_icon128.icns --make-setup flatCAM.py

or

py2applet --iconfile=flatcam_icon128.icns --make-setup flatCAM.py

( --iconfile= required before --make-setup or there will be an error )

The setup.py file looks like this:

"""
This is a setup.py script generated by py2applet

Usage:
    python setup.py py2app
"""

from setuptools import setup

APP = ['flatCAM.py']
DATA_FILES = []
OPTIONS = {'iconfile': 'flatcam_icon128.icns'}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)

Снимок экрана 2020-04-23 в 17 54 59

@FrancescoTalotta

This comment has been minimized.

Copy link

@FrancescoTalotta FrancescoTalotta commented May 2, 2020

Hello,

I followed the procedure and I get this error when I try to execute FLATCam.Py:

"Traceback (most recent call last):
  File "FlatCAM.py", line 6, in <module>
    from FlatCAMApp import App
  File "/Users/francesco/flatcam/FlatCAMApp.py", line 48, in <module>
    from FlatCAMDB import ToolsDB2
  File "/Users/francesco/flatcam/FlatCAMDB.py", line 4, in <module>
    from camlib import to_dict
  File "/Users/francesco/flatcam/camlib.py", line 22, in <module>
    from rtree import index as rtindex
  File "/usr/local/lib/python3.8/site-packages/rtree/__init__.py", line 1, in <module>
    from .index import Rtree
  File "/usr/local/lib/python3.8/site-packages/rtree/index.py", line 6, in <module>
    from . import core
  File "/usr/local/lib/python3.8/site-packages/rtree/core.py", line 143, in <module>
    rt.Error_GetLastErrorNum.restype = ctypes.c_int
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ctypes/__init__.py", line 386, in __getattr__
    func = self.__getitem__(name)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ctypes/__init__.py", line 391, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(RTLD_DEFAULT, Error_GetLastErrorNum): symbol not found"

Any suggestion?

Thanks

@dikkedimi

This comment has been minimized.

Copy link

@dikkedimi dikkedimi commented Oct 13, 2020

Since this thread pops up in Google while searching for "FlatCam on Mac OS", but the solution no longer works - here is the recipe I've found.

Dealing with Python2 and QT4 on MacOS Mojave is futile, so the only option is to move to Python3.

You'd need to check out https://muut.com/flatcam#!/developers:flatcam-beta - this page features a FlatCam fork called "FlatCAM_beta" Get the latest ZIP file with sources from https://bitbucket.org/jpcgt/flatcam/downloads/?tab=downloads (I used FlatCAM_beta_8.98_sources.zip):

mkdir FlatCAM
cd ~/FlatCAM
wget https://bitbucket.org/brainstorm/flatcam/get/e7f9fbca8519.zip
unzip e7f9fbca8519.zip
cd FlatCAM_beta_8.98_sources

You'll also need to have Homebrew installed:

xcode-select --install
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Next, install required modules and run FlatCAM:

brew install pyqt
python3 -m ensurepip
python3 -m pip install -r requirements.txt
python3 -m pip install PyQt5
python3 FlatCAM.py

To build an .app wrapper for the Launchpad:

python3 -m pip install py2app 
py2applet --make-setup flatCAM.py
python3 setup.py py2app -A 
cd dist
open .

Drag the newly built flatCAM.app to the Applications folder.

image

My hero! This worked on macOS catalina with a few bumps in the road. Basically if python gives an error just install that package using brew and try again. Rinse & repeat until it doesn't throw errors anymore. This should be more prominently visible on the web and flatcam documentation, as I've spent 12 hours previously on other attempts. Yay.

The only issue I'm having for now is it seems the built app is sooooo much slower than the one ran from python3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.