OctoPrint Service Fails to Start

What is the problem?
I've been printing successfully for a few months now, but this week I've run into an issue with the OctoPrint service failing to start. It is run using a Raspberry Pi 3 B+ and an OctoPi image (more details in the setup section below). Note all of this is done using ssh to access the Pi as it's headless.

What did you already try to solve it?
The first thing I attempted was simply applying software updates. I used

apt-get update && apt-get upgrade

to update everything. I ran into issues with the system update failing to complete. I tried running again but this time I started with

sudo apt-get update --fix-missing

and some additional updates were downloaded. These still failed to install. It looked like most of the updates were distribution updates, so I decided I'd try

sudo apt-get dist-upgrade

and low and behold, everything updated successfully. I rebooted, ran an additional update and upgrade sequence to confirm nothing else came up (it didn't), and then tried to launch OctoPrint with the following.

oprint/bin/octoprint serve

I received numerous errors that seemed to be tied to plugins, so I decided to try launching it in safe mode.

oprint/bin/octoprint serve --safe

All the errors were identical. I copied the output to a file, and I've attached it along with the latest log file. I don't really know how to peruse the log file yet, so please forgive me if there's an easily spotted solution. It sounds like I have a problem with Python, but I'm not totally sure how to proceed. Any help will be greatly appreciated!
serve_start_error.log (13.2 KB)

Note since I'm a new user I can only include one attachment. I felt the errors I get at attempted service start might be more helpful. I'll post the log file as a reply if needed (and the forum lets me :grin:).

Additional information about your setup
Raspberry Pi 3 Model B+ running OctoPi
OctoPrint version 1.3.9
OctoiPi version 0.15.1
Anet A8 running Marlin 1.1.9 (I successfully printed with the original firmware, successfully flashed and printed with Marlin 1.1.8, and successfully flashed and printed with Marlin 1.1.9. I have the most print time on 1.1.9)

Thanks in advance!

And here's the log file...
octoprint.log (24.1 KB)

If you installed with the OctoPi image, then try simply...

  1. rebooting (it should bring up OctoPrint in the correct way)
  2. if it doesn't automatically start OctoPrint doing this, then look at the /var/log/syslog to see if it includes errors
  3. you would normally stop OctoPrint by running sudo service octoprint stop and similarly you'd start it with the start verb instead

Thanks for the quick reply. I've tried rebooting numerous times with no success, and I also tried using

sudo service octoprint start

without success. I confirmed it wasn't running afterward with

ps -ef | grep -i octoprint | grep -i python

and nothing was returned. That's why I started experimenting with the other method. A quick scan of the syslog showed me there are several instances where voltage drops but recovers. I'll test a new power supply when I can find one, but if there's a culprit on the power side I'm guessing it's my micro USB cable. I'm using +5VSB from a new PSU that's rated for 3A and to date I've had no other issues with power. I'm assuming it's something else I've done. I didn't note anything else from the syslog out of the ordinary, but again I'm a novice when it comes to the inner workings of Linux.

Yeah, that's problematic but it'll just run slower.

I see errors with some slightly order versions of python; what does python2 --version return?

Doing "upgrade" and then "dist-upgrade" is just compounding whatever problems you had; certainly one suggested solution is to start from a fresh SD card.

I'm currently on 2.7.13.

I thought about just starting fresh, but I wanted to try and learn more so I can help myself more effectively in the future. I did backup my .octoprint just in case though!

That error was (supposedly) fixed before 2.7.4 was released. It might be the same error from somewhere else, or it might be inside the virtualenv.

It's definitely something inside virtualenv. I attempted to just check the version and received this...

Traceback (most recent call last):
  File "/usr/bin/virtualenv", line 4, in <module>
    import re
  File "/usr/lib/python3.5/re.py", line 123, in <module>
    import sre_compile
  File "/usr/lib/python3.5/sre_compile.py", line 14, in <module>
    import sre_parse
  File "/usr/lib/python3.5/sre_parse.py", line 15, in <module>
    from sre_constants import *
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 669, in exec_module
  File "<frozen importlib._bootstrap_external>", line 773, in get_code
  File "<frozen importlib._bootstrap_external>", line 484, in _compile_bytecode
ValueError: bad marshal data (unknown type code)

I figured that I'd try removing it then reinstalling it. I read some of the installation instructions which suggested using pip 1.3 or greater. When I attempted to check it's version, I received a command not found error. I read pip is baked into Python 2.7.9 or higher, so now I am thinking I should backtrack and do the following...

  1. Remove python2
  2. Reinstall python2
  3. Hopefully pip works, so then I'd remove virtualenv with it
  4. Use pip to reinstall virtualenv

Does that seem like a decent plan? I figured the worst that'll happen is I have to start with a fresh image!

ignore pip- the real problem is that the virtualenv is trying to run python3, which is not supported by Octoprint (yet).

Well, I fiddled with python a little more and gave up. A quick SD card burn, moved backup back in, and I'm off and running again. I just started the update from OctoPrint 1.3.8 to 1.3.9, do you guys still suggest doing updates with apt-get from time to time? I want to make sure that's not how I got into this mess in the first place!

The whole point of the virtual environment should be to protect you from the global version of python getting upgraded (and potentially causing problems).

The likeliest cause of your problems was the interrupted apt-get upgrade, I'd guess.

Personally, I don't worry about upgrading Raspbian if it works fine on mine. And if I did think about doing that, I'd:

  1. shutdown and yank the microSD
  2. use ApplePi-Baker to clone the image
  3. put it back into the printer and update/upgrade

Worst-case scenario, I'd then burn another copy of the pre-upgrade microSD image and drive on.