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.11 (El Capitan) requires Xcode 7. Specifically, this is to ensure that locally compiled components of Python libraries (such as pyobjc) can be installed successfully.

Install Xcode's Command Line Tools

  • 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/myusername does not contain an Xcode project.

  • If you have more than one version of Xcode installed (unlikely -- you will know if you do) then ...

    sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

Install Homebrew and use it to install Python

A version of Python 3 is already installed within OS X; however, OcoPrint requires Python 2.7, which can be installed with Homebrew as follows:

  • ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • 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

  • git clone https://github.com/foosel/OctoPrint.git
  • cd OctoPrint
  • virtualenv venv
  • source venv/bin/activate (assumes you're using the default BASH shell. active.csh is also available.)
  • pip install -U pyobjc
  • python setup.py install

Running OctoPrint

  • cd OctoPrint – the folder created from the above git clone
  • source venv/bin/activate
  • octoprint serve

or

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

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

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