Update Python to the new version 3.9

Hello, I have a home assistant on raspbian and I have read that now in the next versions Python 3.7 will no longer be valid and we have to use the new version. 3.9 (it is possible to update)

Can someone explain to me how to update my version of Python to the latest version, so that I can continue the same with my HA server thanks!I leave you a screenshot of my installation.

Thank you!!

2 Likes

Did you read the release notes perhaps it may help

Add far as I know, you need to build your own python version and then recreate your environment to use the new executable. Be careful, some guides will overwrite the base python3 version to 3.9 (or whatever you are building)

Check out https://github.com/pyenv/pyenv too.

If you can’t handle this, Id recommend using one of the methods of installation that handles this for you as mentioned in the release notes

Ok, that’s the problem that right now I can’t do a clean installation, and I wanted to update the version I have now with some easy manual, why don’t I have too much knowledge

I don’t know if it is possible to find a guide to do this version update.

Thanks for your answer.

Check out, but obviously use 3.9 if you want.

https://docs.python.org/3/using/unix.html#building-python

1 Like
2 Likes

Nice tutorial. You may want to update to use make altinstall instead of make install as recommended by the Python installation guide. My understanding is that altinstall does not change the default python3 version which could be important if other services depend on this.

1 Like

Thanks for the answer I think it is what I needed, evident adjusting the version to the latest available … I will try it. I have the installation as it is described and with the same directories.

So I understand that it is to follow the commands step by step.

I see that what we do is install the whole system again from 0 and what is done is a backup copy of the folder where the HA server is installed that is then restored, correct?

Thanks for all the help!!

Basically yeah, you download and install the new python version, backup your homeassistant configuration, delete your old venv, create a new venv based on the new python version, install homeassistant in the new venv and restore your backed up configuration. Takes about 10 minutes :+1:

Perfect, I’ll try it tomorrow, thanks a lot for the help!

I’d hold off on the 3.9 upgrade:

We are currently working on ensuring Python 3.9 is fully supported and tested.

Upgrade to Python 3.8.6, sure, but Python 3.9 may result in stuff not working. Based on the 3.8 transition, I’d upgrade that may to a will, but nobody has confirmed this yet :wink:

This is how I upgrade my Python and create a new venv. I don’t blow away the old one, so that if things go wrong a rollback is easy. I’ve also written a script to do all the hard work. You pass in the version of Python and it’ll build and (alt)install that Python version, with all the right settings. Then it creates a new venv, installs the pre-requisites that HA doesn’t handle, and runs a check to speed up first startup slightly.

5 Likes

I would agree to hold off for at least the next version of HA before upgrading. The deprecation cycle is brutally fast in HA, we shouldn’t deprecate something before it’s replacement can at least be recommended.

Python has also announced starting 12 month releases, so upgrading one version at a time means repeating this cycle every year. I wouldn’t recommend upgrading to 3.8.x unless for some reason you had to do it now rather than in 2 or 3 weeks.

1 Like

To be honest, upgrading Python (if you’re not on a Pi) is pretty painless, and it usually takes a lot longer than a few weeks for the new Python version to be validated. I’ve been running 3.7.3 until the deprecation notice was released, having upgraded to that only when 3.6 was deprecated.

At best, I’d follow the Docker containers, upgrading only when they update. Updating once a year is easy enough, and if it’s not then it’s probably time to switch to Docker :stuck_out_tongue:

I have installed HA using the Manual installation on a Raspberry PI 4. Can someone point me to a upgrade procedure to Python 3.8 for my system?

Did you read the links that were posted?

1 Like

I followed http://blog.ceard.tech/2017/12/upgrading-python-virtual-environment.html
and did this on mij HA Core and on a newley prepared SD with Rapsberry OS Lite (2020-08-20 build)

After

sudo apt update && apt upgrade

sudo apt install build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libudev-dev libc-dev libffi-dev libbluetooth-dev libtirpc-dev libjemalloc-dev 

cd /home/pi
wget https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tgz
tar -zxvf Python-3.8.6.tgz
cd Python-3.8.6
./configure --enable-optimizations --enable-shared --with-lto --with-system-expat --with-system-ffi --without-ensurepip
make -j$(cat /proc/cpuinfo|egrep -c "^processor") LDFLAGS="-Wl,--strip-all" CFLAGS="-fno-semantic-interposition -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free -ljemalloc" EXTRA_CFLAGS="-DTHREAD_STACK_SIZE=0x100000"

i get:

*** WARNING: renaming "_struct" since importing it failed: /usr/lib/arm-linux-gnueabihf/libjemalloc.so.2: cannot allocate memory in static TLS block
Segmentation fault
make[3]: *** [Makefile:614: sharedmods] Error 139
make[3]: Leaving directory '/home/pi/Python-3.8.6'
make[2]: *** [Makefile:507: build_all_generate_profile] Error 2
make[2]: Leaving directory '/home/pi/Python-3.8.6'
make[1]: *** [Makefile:483: profile-gen-stamp] Error 2
make[1]: Leaving directory '/home/pi/Python-3.8.6'
make: *** [Makefile:495: profile-run-stamp] Error 2

What is going wrong here?

When I do “sudo make altinstall” despite the errors I get:

if test "no-framework" = "no-framework" ; then \
        /usr/bin/install -c python /usr/local/bin/python3.8; \
else \
        /usr/bin/install -c -s Mac/pythonw /usr/local/bin/python3.8; \
fi
if test "3.8" != "3.8"; then \
        if test -f /usr/local/bin/python3.8 -o -h /usr/local/bin/python3.8; \
        then rm -f /usr/local/bin/python3.8; \
        fi; \
        (cd /usr/local/bin; ln python3.8 python3.8); \
fi
if test -f libpython3.8.so && test "no-framework" = "no-framework" ; then \
        if test -n "" ; then \
                /usr/bin/install -c -m 755  /usr/local/bin; \
        else \
                /usr/bin/install -c -m 755 libpython3.8.so /usr/local/lib/libpython3.8.so.1.0; \
                if test libpython3.8.so != libpython3.8.so.1.0; then \
                        (cd /usr/local/lib; ln -sf libpython3.8.so.1.0 libpython3.8.so) \
                fi \
        fi; \
        if test -n "libpython3.so"; then \
                /usr/bin/install -c -m 755 libpython3.so /usr/local/lib/libpython3.so; \
        fi; \
else    true; \
fi
if test "x" != "x" ; then \
        rm -f /usr/local/binpython3.8-32; \
        lipo  \
                -output /usr/local/bin/python3.8-32 \
                /usr/local/bin/python3.8; \
fi
LD_LIBRARY_PATH=/home/pi/Python-3.8.6 CC='gcc -pthread' LDSHARED='gcc -pthread -shared   -flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none -g ' OPT='-DNDEBUG -g -fwrapv -O3 -Wall'   _TCLTK_INCLUDES='' _TCLTK_LIBS=''       ./python -E ./setup.py  build
Segmentation fault
make: *** [Makefile:614: sharedmods] Error 139

Probably try without jemalloc, or just switch to Docker :wink:

Oke very convincing strategy :shushing_face:. I have a spare rpi so I will try docker. :fist:

I’m having exactly the same issue. Is there any way to avoid moving to docker and still compile python 3.8 with jemalloc on a Pi 4?

Probably, but I’ve not invested the time in working it out. If it matters that much, switch to Docker since the Docker builds use it.