Setting up OctoPrint on MacOS

Preparation

  • Must be performed with a user with Administrative privileges.

  • Requires the latest version of Xcode suitable for your OS X. For example, OS X 10.15.x (Catalina) requires Xcode 11.x. Specifically, this is to ensure that locally compiled components of Python libraries (such as pyobjc) can be installed successfully.

Check your current (active) Command Line Tools (CLT) version

  • Open up the macOS Terminal and check if and which version of the CLT you have with /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -version
    If you run the latest version, you can skip the next steps.

  • If you have, for whatever reason, more than one version of Xcode installed, switch to the latest one sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

Install Xcode's Command Line Tools if necessary

  • xcode-select --install – this may ask you to accept the Xcode user license.
  • It doesn't hurt to also run sudo xcodebuild, to be sure the license acceptance process completed. If successful, you should see something like this: The directory /Users/YOURUSERNAME does not contain an Xcode project.

Install Homebrew and use it to install Python 2

Depending on which version of macOS you are running Python 2.7 and/or Python 3.x may be already installed on your system. You can check this by simply running python -V in your Terminal.

  • If the shown version is 2.7, you're good to go and you can skip to the next section.

  • However, if you encounter 3.x as your installed python interpreter, you have to install Python 2.7 manually. The easiest way is to use Homebrew, or brew for short. Check out the official web page: https://brew.sh to learn more about it.

  1. Install brew by running:
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

  2. Install the missing Python 2.7 versions:

  • Python 2.7: brew install python@2

Install virtualenv

Note: for users with Anaconda or multiple python versions installed, make sure to use Python 2.7 from Homebrew. Homebrew uses this default directory: /usr/local/opt/python/libexec/bin. If needed, replace two of the below commands with /usr/local/opt/python/libexec/bin/python -m pip install virtualenv and /usr/local/opt/python/libexec/bin/python -m virtualenv venv.

We utilize virtualenv to maintain an isolated Python environment for OctoPrint development. This prevents other, global Python libraries or updates from breaking OctoPrint. While not strictly required, virtualenv can save us from headaches, down the road. See the virtualdev docs for more detail.

  • pip install virtualenv

Installing OctoPrint

Warning: Make sure the path to the location where you git clone, install and run OctoPrint does not contain spaces! Otherwise, Python will not run OctoPrint! This is especially important for users which use iCloud Drive to sync their Folders, as iCloud stores its content in /Users/YOURUSERNAME/Library/Mobile Documents/com~apple~CloudDocs/- too many fancy characters for Python!

You can check your locations path by running pwd in the Terminal inside the folder where you cant to execute the next steps inside.

  • git clone https://github.com/foosel/OctoPrint.git
  • cd OctoPrint
  • virtualenv venv
  • source venv/bin/activate
    (assumes you're using the BASH shell, which was the default until Catalina, or ZSH from Catalina onwards. Otherwise, active.csh is also available.)
  • pip install -U pyobjc
  • pip install .

Alternatively, if you don't need the sources (e.g. you just want to run OctoPrint, not develop against it) you can just install from PyPI without the git checkout:

  • mkdir OctoPrint
  • cd OctoPrint
  • virtualenv venv
  • source venv/bin/activate
    (assumes you're using the BASH shell, which was the default until Catalina, or ZSH from Catalina onwards. Otherwise, active.csh is also available.)
  • pip install -U pyobjc
  • pip install OctoPrint

Running OctoPrint

Assuming that you are still inside the OctoPrint folder from above:

  • source venv/bin/activate
  • octoprint serve

or from any location (tap the Tab key (twice) on your keyboard after every / to get the next available path content suggestions shown)

  • /./path/to/OctoPrint/venv/bin/octoprint serve

Accessing the web interface

Assuming that you haven't also installed haproxy you can get to the OctoPrint web interface from its default port of 5000 locally on your Mac via http://localhost:5000/.

Auto start on boot

Credit to Fahim Hossain on medium

Using a plist like this you can start octoprint when turning on the mac, even without logging in.

  • sudo nano /Library/LaunchDaemons/it.YOURNAME.octoprint.plist – edit this file
  • replace "USER" with your username (the short one on the left in the terminal)
  • assuming you have install OctoPrint in ~/OctoPrint
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>EnvironmentVariables</key>
    <dict>
      <key>PATH</key>
      <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:</string>
    </dict>
    <key>Label</key>
    <string>it.YOURNAME.octoprint</string>
    <key>Program</key>
    <string>/Users/USER/OctoPrint/venv/bin/octoprint</string>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <false/>
    <key>LaunchOnlyOnce</key>        
    <true/>
    <key>StandardOutPath</key>
    <string>/tmp/startup-octoprint.stdout</string>
    <key>StandardErrorPath</key>
    <string>/tmp/startup-octoprint.stderr</string>
    <key>UserName</key>
    <string>USER</string>
    <key>GroupName</key>
    <string>staff</string>
    <key>InitGroups</key>
    <true/>
  </dict>
</plist>

This is a wiki post that anyone with trust level 2 or higher can contribute to. Please do so.


Originally part of the OctoPrint wiki on Github, migrated on 2019-11-13.

5 Likes

I'm getting
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128)

Traceback (most recent call last):
File "setup.py", line 233, in
setup(**params())
File "setup.py", line 159, in params
version = versioneer.get_version()
File "/Users/Nathan/OctoPrint/versioneer.py", line 1909, in get_version
return get_versions()["version"]
File "/Users/Nathan/OctoPrint/versioneer.py", line 1871, in get_versions
pieces = versions_from_lookup_f(lookup_data, root, verbose)
File "/Users/Nathan/OctoPrint/versioneer.py", line 1435, in git_pieces_from_lookup
cwd=root)
File "/Users/Nathan/OctoPrint/versioneer.py", line 484, in run_command
else None))
File "/usr/local/Cellar/python@2/2.7.17_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 394, in init
errread, errwrite)
File "/usr/local/Cellar/python@2/2.7.17_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1047, in _execute_child
raise child_exception
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128)

python@2 was deleted from homebrew/core in commit 028f11f9e4:
python@2: delete (https://github.com/Homebrew/homebrew-core/issues/49796)
EOL 1 January 2020.
:cry:

Ran into the same issue myself; ended up using Miniconda to create a 2.7 environment. After doing that activated my 2.7 environment and I was able to install OctoPrint without issue.

You guys could try the latest dev rc of octoprint 1.4.0.
It comes with python 3 support :slight_smile:

pyenv is also an option. It’s homebrew-installable and lets you easily manage multiple python versions, which is still useful even in a 3-only world.

I would suggest that "solutions" like pipenv and pyenv are like inviting aliens from another planet to land and make camp. You soon find that they've begun teraforming the planet for their own favorite temperature of 102F rather than just leaving things the way they were before they arrived.

So some instruction might say "run pipenv clean" and then you find that some other project's virtual environment has been burned to the ground, figuratively-speaking.

There is already an accepted mechanism in place for this infrastructure. It's called virtualenv. Info

I was only recommending pyenv as a means of installing a Python version, which is all it does. pyenv doesn't replace virtualenv in this use case, it replaces homebrew's managed versions.

But since OctoPrint now runs on Python 3 just fine there's no reason for that guidance anyway, and the guide needs to be updated to just say to use homebrew for Python 3 as the method of least friction. (Except that in my experience, virtualenvs break when homebrew updates the Python version, since the symlinked python binary no longer exists...)

Actually that's another good reason to use pyenv: once you install a Python version it sticks around until you explicitly remove it.

Thank you for the tutorial! I used it to get my old High Sierra Late 2009 Macbook running OctoPrint on an Ender 3.

A couple issues with the tutorial:

  • You don't need the full Xcode, so that advice need not be followed. You just need to run xcode-select --install and install the xcode tools.
  • Homebrew's ruby installer is deprecated. Instead follow the directions on https://brew.sh.

Driver Installation
macOS needs a driver to communicate with the printer over USB. For the Ender 3 I used TH3D's driver package. I had to reboot after installing the driver.

For Macs running Catalina (or newer):
As of March 4, 2020, OctoPrint supports Python 3, so don't bother installing python@2.

For Macs running Mojave (or older):
Install Python 3 with brew install python. Use python3 when you need to invoke python. If you're unsure what python you're calling, run python --version to see the version info. You want to always use Python3.

For modules like pip and virtualenv, you'll want to run them with Python 3. Use python3 -m pip install virtualenv. This asks Python 3 to run the module pip. Similarly use python3 -m virtualenv venv

Preventing Sleep
I use an app called NoSleep to prevent my Macbook from going to sleep when I close the lid.

Setting up a Webcam using mjpeg_stream_webcam

  1. Run git clone https://github.com/meska/mjpeg_stream_webcam.git
  2. cd mjpeg_stream_webcam
  3. python3 -m virtualenv -p python3 .env
  4. source .env/bin/activate
  5. pip install -r requirements.txt
  6. To start the streamer, run python mjpegsw.py. If you want to access the stream from a networked computer, you must specify an ip such as python mjpegsw.py -i 192.168.1.15. The Stream URL is then http://192.168.1.15:5001/cam.mjpg and the snapshot URL is http://192.168.1.15:5001/snap.jpg
3 Likes

Is there an update for these instructions I am having issues getting this install to work on a Mac running Catalina. It seems like a lot of the steps are deprecated and out of date. I have been running Octoprint on a Pi 4 for a while but I want to create a multi instance Mac install to run my small farm of 10 machines.

I would also make a youtube video on the process to share with the community.

Any help would be greatly appreciated.

@MMajewskiNet confirmed that what's up there now should work. Without access to a Mac myself, that's all I can give you.