Upgrade your OctoPrint install to Python 3!

@simpat1zq can you run /home/Hass/OctoPrint/venv/bin/python --version and see what python version it says? Is it possible you have more than one virtual environment somewhere?

In the octoprint.log it will tell you where your virtual environment is, in case something has been messed up along the way.

Hey @TheSaint

The plugin repository is currently at nearly 70% compatibly, which is improving nearly every week.

Exclude Region plugin is the most popular of those you list (~5k confirmed) that is not Py3 compatible, I have reached out to the author to see if I can help out, but so far have not got a response back.

The rest I believe are below 1k installs, but either way I am looking at adopting some to get them to Python 3 compatibility

1 Like

Below is the output of that command and the line from the log which seems to indicate that I'm using the correct venv. I have no clue why that script would say this.

hass@HassOpti:~$ /home/hass/OctoPrint/venv/bin/python --version
Python 2.7.15+
hass@HassOpti:~$

And from the log:

2020-09-17 12:45:03,544 - octoprint.plugin.core - INFO - 62 plugin(s) registered with the system:
|  Action Command Notification Support (bundled) = /home/hass/OctoPrint/venv/lib/python2.7/site-packages/octoprint/plugins/action_command_notification
|  Action Command Prompt Support (bundled) = /home/hass/OctoPrint/venv/lib/python2.7/site-packages/octoprint/plugins/action_command_prompt

raises fist at sky

Where has the + come from in this version string :face_with_monocle:
I'm not blaming you (unless you did put it there), but with the plus on the end it is not a valid version number. As you can see from the regex demo (regex101.com) I put together, it is not picked up, so the script assumes it is invalid.

So there are two things here: (a) the script should not say you are python 3, if it can't read it. That was more a failsafe to prevent things going wrong (corrupt installs etc.) but I guess it gave the wrong message. And (b) the little + sign.....

So I will try and strip/ignore that + from the end, unless anyone can tell me that is a bad idea. Will ping you here once I have it updated.

Debian bug, I strip it in OctoPrint too:

Sorry for forgetting about that and not giving you a heads-up before.

Cheers, will look into it

@simpat1zq should be fixed now, with @foosel's pointer. You will need to re-download the script, and verify the version number printed at the top is 2.1.5. There may be some caching issues, so if it doesn't work straight away (it should do) then try again in an hour or so.

Cool. Thanks for the quick fix. I'm actually glad it happened. When I ran the script, I forgot about the print I had running, which probably would have failed if OP restarts. I'll test this out soon.

You may want to download it again... My commit with the above fix in it was broken, so please redownload & check for v2.1.6. :man_facepalming:

So I may have had the bad script, and I got this error message:

Path: /home/hass/OctoPrint/venv
Traceback (most recent call last):
  File "upgrade.py", line 598, in <module>
    path_to_venv, commands, config_dir = get_env_config(octopi_valid)
  File "upgrade.py", line 305, in get_env_config
    valid = check_venv_python(path)
  File "upgrade.py", line 344, in check_venv_python
    if version_str.endswith("+"):
AttributeError: 'list' object has no attribute 'endswith'

I downloaded again, and I'm getting that same error from earlier saying it's on Python3.

Check it is version 2.1.6, since that stack has changed to fix the bug (version_str to line). It is awful naming by me really, since version str is actually a list....

EDIT I just re read the final line of your reply. One moment....

@simpat1zq Could you open a bug report on the repository please, I'm going to have to investigate further, and the comments aren't the best place for discussing this. We'll hopefully get it sorted.

OctoPrint Upgrade To Python 3 | New Issue

I submitted one(Link is below). I think I figured it out. The version must have had some whitespace at the end. When I used 'strip()' on the version, the script proceeds past that point. It looks like that should be the fix, but let me know if it's not. I'll wait to hear from you on it before I continue running the script.

Also, @foosel, Since he is using the same code that you are using in OP, does that need to be added there as well? Or are you 2 getting your version numbers in different ways? I'm guessing that's the case, since I have no issues with OP.

Edit: I ran the script just now and it is A LOT faster. The little spinning thing would go about 3/4 of the way around before OP would load, not it doesn't even go 1/4 of the way around. The settings screen loads instantly vs taking about 2 seconds. This is nice.

I'm trying to move to Python 3 by using the commands listed in the post, but I'm facing similar issues like some posts before.
When I run "python3 upgrade.py" I got message to enter the venv and confing directories and when I place the path to venv I'm getting a message: "Virtual environment is already Python 3, are you sure you need an upgrade? Please try again".

I cannot continue the script because of that.
Does it means that I'm already running OctoPrint with Python 3? If yes, why OctoPrint shows: Python 2.7.17rc1?


Octoprint web GUI shows: OctoPrint 1.4.2 and Python 2.7.17rc1
I'm running manual install of OctoPrint on Ubuntu.
Linux usrpi4 5.4.0-1018-raspi #20-Ubuntu SMP Sun Sep 6 05:11:16 UTC 2020 aarch64 aarch64 aarch64 GNU/Linux

Terminal:
hnt@usrpi4:~$ python3 upgrade.py
OctoPrint Upgrade to Py 3 (v2.1.7)

Hello!
This script will move your existing OctoPrint configuration from Python 2 to Python 3
This script requires an internet connection and it will disrupt any ongoing print jobs.

It will install the latest version of OctoPrint (1.4.2) and all plugins.
No configuration or other files will be overwritten

Press [enter] to continue or ctrl-c to quit

Detecting system info...
Please provide the path to your virtual environment and the config directory of OctoPrint
On OctoPi, this would be /home/pi/oprint (venv), /home/pi/.octoprint (config)
and service commands commands sudo service octoprint stop/start
Path: /home/hnt/OctoPrint/venv
Virtual environment is already Python 3, are you sure you need an upgrade?
Please try again
Path: /home/hnt/OctoPrint/venv
Virtual environment is already Python 3, are you sure you need an upgrade?
Please try again
Path:
......

I'll sort that. I thought the regex I used to grab the version number was reliable, but it needs a dash before the RC, seems to choke there. Will fix this evening and let you know.

1 Like

Hey @fhnt - this should now be fixed by my latest commit.

You will need to redownload the script, and make sure it displays V2.1.8 at the start, if not you may have to wait for some caching to sort out. Its never taken more than 10 mins for me, but you never know. Anyway, if you run that and there are still problems, let me know.

ETA link to commit

Hi Charlie_Powell,
Version 2.1.8 solved the issue. Unfortunately I'm stuck on another one.

Creating new Python 3 environment...
/usr/bin/python: No module named virtualenv
ERROR: Failed to create Python 3 venv
Could not create new venv

Cleaning up...
Fatal Error: Exiting

Terminal:
venv.log (2.2 KB)

Looks like you'll need to install virtualenv to your system. On OctoPi, it is preinstalled, it seems to be for most other people but I guess for you it is not.

Run sudo apt install virtualenv and you should then be able to run the script.

Make sure your old environment is moved back to where it should have been, so the script finds it in the right place. (it is likely named something like venv.bak you can just move it back to venv)

I was thinking about that and tried a couple of things today, but it still stops with the same error.

The terminal log below is right after I restored my system from a backup and ran the command you suggested.
venv error.log (4.5 KB)

if you were to run python3 -m virtualenv what is it telling you? Hopefully not still module not found.... It seems it may have installed to Python 3 rather than 2, in which case the script would need to run it as such, from the install log you provided.