Skip to content

Instantly share code, notes, and snippets.

@fmarkos
Forked from ersingencturk/setup python.md
Created January 6, 2024 16:26
Show Gist options
  • Save fmarkos/46b249af2de219c562e2c8cdb6228039 to your computer and use it in GitHub Desktop.
Save fmarkos/46b249af2de219c562e2c8cdb6228039 to your computer and use it in GitHub Desktop.
Installing Python 3.11 & Rust on Raspberry Pi

Installing Python 3.11 & Rust on Raspberry Pi

Python 3.11 is not available as apt package on debian raspbian bullseye so installing from source needed

updatepython2v11.sh can be used to compile python 3.11 on raspberry pi

installing packages like bcrypt and cryptography needs rust compiling so rust compiler needed if you don't do that you will get error liek this:

Building wheels for collected packages: bcrypt
  Building wheel for bcrypt (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for bcrypt (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [59 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-aarch64-cpython-311
      creating build/lib.linux-aarch64-cpython-311/bcrypt
      copying src/bcrypt/__init__.py -> build/lib.linux-aarch64-cpython-311/bcrypt
      copying src/bcrypt/__about__.py -> build/lib.linux-aarch64-cpython-311/bcrypt
      running egg_info
      writing src/bcrypt.egg-info/PKG-INFO
      writing dependency_links to src/bcrypt.egg-info/dependency_links.txt
      writing requirements to src/bcrypt.egg-info/requires.txt
      writing top-level names to src/bcrypt.egg-info/top_level.txt
      reading manifest file 'src/bcrypt.egg-info/SOURCES.txt'
      reading manifest template 'MANIFEST.in'
      warning: no previously-included files found matching 'requirements.txt'
      warning: no previously-included files found matching 'release.py'
      warning: no previously-included files found matching 'mypy.ini'
      warning: no previously-included files matching '*' found under directory '.github'
      warning: no previously-included files matching '*' found under directory '.circleci'
      warning: no previously-included files found matching 'src/_bcrypt/target'
      warning: no previously-included files matching '*' found under directory 'src/_bcrypt/target'
      adding license file 'LICENSE'
      writing manifest file 'src/bcrypt.egg-info/SOURCES.txt'
      copying src/bcrypt/_bcrypt.pyi -> build/lib.linux-aarch64-cpython-311/bcrypt
      copying src/bcrypt/py.typed -> build/lib.linux-aarch64-cpython-311/bcrypt
      running build_ext
      running build_rust
      error: command failed: 'rustc': No such file or directory (os error 2)
      
          =============================DEBUG ASSISTANCE=============================
          If you are seeing a compilation error please try the following steps to
          successfully install bcrypt:
          1) Upgrade to the latest pip and try again. This will fix errors for most
             users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
          2) Ensure you have a recent Rust toolchain installed. bcrypt requires
             rustc >= 1.56.0.
      
          Python: 3.11.1
          platform: Linux-6.1.19-v8+-aarch64-with-glibc2.31
          pip: n/a
          setuptools: 67.6.0
          setuptools_rust: 1.5.2
          rustc: n/a
          =============================DEBUG ASSISTANCE=============================
      
      error: can't find Rust compiler
      

apt-get install rustc won't work because it is an old version too. it needs versions higher than 1.56 therefore rust can be installed like this:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

problem with rust installer is it's default is arm64 but raspberry pi works 32 bit so the architecture is detected wrong , so the default settings don't work

if you end up with default settings when your run rust compiler like:

rustc -V

you will get an error like:

error: command failed: 'rustc': No such file or directory (os error 2)

to fix and properly install you need to select option 2 (2) Customize installation) and default host triple must be armv7-unknown-linux-gnueabihf

#!/bin/bash
if [ true ]; then
# get a current python3
sudo apt-get install wget build-essential libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev liblzma-dev -y
VERSION=3.11.1
VERSION_SHORT=3.11
mkdir -p tmp
cd tmp
if [ ! -f Python-${VERSION}.tgz ]; then
wget -O Python-${VERSION}.tgz https://www.python.org/ftp/python/${VERSION}/Python-${VERSION}.tgz
fi
tar xzf Python-${VERSION}.tgz
cd Python-${VERSION}
if [ ! -f python ]; then
./configure --enable-optimizations
fi
echo "### make altinstall"
sudo make altinstall
sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python${VERSION_SHORT} 1
echo "### install pip"
/usr/local/bin/python${VERSION_SHORT} -m pip install --upgrade pip
sudo update-alternatives --install /usr/bin/pip pip /usr/local/bin/pip${VERSION_SHORT} 1
cd ..
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment