nordvpn

How to install Python 3.8 on Raspberry Pi (Raspbian)

Install Python 3.8 on Raspberry Pi

In this tutorial, I will show you how to install Python 3.8.0 on Raspberry Pi running raspbian on it.


I have updated the post please comment below if it doesn't work.

1. Update the Raspbian

Update the Raspbian before installing python.

sudo apt-get update

Read Also: How to install python 3.7 on Ubuntu 16.04 / 18.04

2. Prerequisites

Before installing Python 3.8 there are some dependencies that we need to install. Use the following command to install the required dependencies.

sudo apt-get install -y build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev tar wget vim

3. Download Python

You can download Python from the official website or use the following command.

wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz

Read Also: How to install postgresql 11 on Debian 8 / 9

4. Install Python 3.8

Now we will extract and install Python from the source.
sudo tar zxf Python-3.8.0.tgz
cd Python-3.8.0
sudo ./configure --enable-optimizations
sudo make -j 4
sudo make altinstall

https://installvirtual.com/how-to-connect-raspberry-pi-to-wifi-without-a-monitor/

5. Check Python version

Now Python is installed you can check the version using the following command.

python3.8 -V

6. Make Python 3.8 as the default version

If you want to use python 3.8 as a default version you can create an alias.echo "alias python=/usr/local/bin/python3.8" >> ~/.bashrc

Then source the .bashrc file.

source ~/.bashrc

7. Check Python Version

After creating an alias check the python version again.

python -V
Python 3.8.0

Now you have successfully installed Python 3.8 on Raspberry Pi.

8. Clean up

Now you can clean up using the archive

sudo rm -rf Python-3.8.0.tgz
sudo rm -rf Python-3.8.0

Buy me a coffeeBuy me a coffee

Video Tutorial:

55 Comments Posted

  1. The “sudo make -j 4” step failed with …
    Segmentation fault
    Makefile:614: recipe for target ‘sharedmods’ failed
    make[3]: *** [sharedmods] Error 139
    make[3]: Leaving directory ‘/home/pi/Python-3.8.0’
    Makefile:507: recipe for target ‘build_all_generate_profile’ failed
    make[2]: *** [build_all_generate_profile] Error 2
    make[2]: Leaving directory ‘/home/pi/Python-3.8.0’
    Makefile:481: recipe for target ‘profile-gen-stamp’ failed
    make[1]: *** [profile-gen-stamp] Error 2
    make[1]: Leaving directory ‘/home/pi/Python-3.8.0’
    Makefile:492: recipe for target ‘profile-run-stamp’ failed
    make: *** [profile-run-stamp] Error 2

    any idea what caused this?

    Thanks,
    Graeme

      • I have this same segfault problem on a ZeroW
        Tried “`./configure CC=clang CXX=clang++“`
        But then get:

        checking build system type… armv6l-unknown-linux-gnueabihf
        checking host system type… armv6l-unknown-linux-gnueabihf
        checking for python3.8… no
        checking for python3… python3
        checking for –enable-universalsdk… no
        checking for –with-universal-archs… no
        checking MACHDEP… “linux”
        checking for gcc… clang
        checking whether the C compiler works… no
        configure: error: in `/home/pi/Python-3.8.2′:
        configure: error: C compiler cannot create executables
        See `config.log’ for more details

        Any ideas?

  2. I cannot for the life of me get the bashrc to not have a syntax error of unexpected end of file on the last line where i add the alias on my Raspberry Pi4. I don’t know if it is something I’m doing wrong in VIM or something else but I’m down to that point with the installation and I’m stuck. Everything has worked fine up to this point. Thanks

  3. Hey, thanks for the instruction. It worked well so far, but does anybody have an idea, why now, when I open a new LXTerminal, it starts automatically in “python mode”. I have to type in quit() everytime to get the “standard mode”. Would be great if someone can help me to fix this.
    Thanks in advance!

  4. So I followed the prompts, but ran into an issue at Step 6. Now when I launch the Terminal window, I go directly into Python 3.8.1 … instead of the classic LXTerminal (i.e. used to show pi@raspberrypi:~ $” Linux prompt. Now boots up Python 3.8 and a “>>>” prompt)

    Can you help me to direct the terminal prompt back to LXTerminal? I use Linux commands quite a bit. Thanks

  5. When I ran it as is bashrc filled up with crap because of the echo. Once I removed the echo’s “alias python=python3.8” was added instead and that solved all my problems.

    Thank you for this post!

  6. Just for you to know: sudo make altinstall is the only command needing sudo. Thanks for making me discover –enable-optimizations.

  7. I followed all the steps and entered ~/.bashrc and it opened the editor. I exited without saving and tried to open the ~/.bashrc again and this time I cannot edit and it shows “~/.bashrc” 113L, 3523C at the bottom. How do I get it to allow me to edit?

  8. I followed the steps, installed Python 3.8.2, confirmed version. Trying to set it as default and entered ~/.bashrc How to enter into edit mode? and where to add the two echo lines? Thanks.

    • Hey John,

      Just execute echo command on your terminal. It will automatically add an entry into .bashrc file.
      echo "/usr/local/bin/python3.8" >> .bashrc
      echo "alias python='/usr/local/bin/python3.8'" >> .bashrc

      Thanks

  9. I think the vim in step 6 isn’t necessary if you’re going to execute the 2 following echo commands. Or, you could use vim to add the alias commands to the end of the bashrc file, then don’t do the echo commands. But you wouldn’t want to do both.

    Or, perhaps I’m confused?

    • Hey John,

      Thanks for noticing. I have removed it now. I have done so many revisions of this post so I forgot to remove it.
      Anyways thank you so much!

  10. When it all finishes (a l–o–n–g time on the Pi Zero), the python executes but does not find any of the import libraries, e.g. gpiozero. Should I move the 3.8 files from /usr/local/bin to /usr/bin? Do I need to reconfigure the 3.8 version to be used as the default python? Thanks.

    • Hey Derek,

      Thanks for reaching out. I am not getting any errors I just tried it again.
      Can you please show me your ~/.bashrc file?

      • # ~/.bashrc: executed by bash(1) for non-login shells.
        # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
        # for examples

        # If not running interactively, don’t do anything
        case $- in
        *i*) ;;
        *) return;;
        esac

        # don’t put duplicate lines or lines starting with space in the history.
        # See bash(1) for more options
        HISTCONTROL=ignoreboth

        # append to the history file, don’t overwrite it
        shopt -s histappend

        # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
        HISTSIZE=1000
        HISTFILESIZE=2000

        # check the window size after each command and, if necessary,
        # update the values of LINES and COLUMNS.
        shopt -s checkwinsize

        # If set, the pattern “**” used in a pathname expansion context will
        # match all files and zero or more directories and subdirectories.
        #shopt -s globstar

        # make less more friendly for non-text input files, see lesspipe(1)
        #[ -x /usr/bin/lesspipe ] && eval “$(SHELL=/bin/sh lesspipe)”

        # set variable identifying the chroot you work in (used in the prompt below)
        if [ -z “${debian_chroot:-}” ] && [ -r /etc/debian_chroot ]; then
        debian_chroot=$(cat /etc/debian_chroot)
        fi

        # set a fancy prompt (non-color, unless we know we “want” color)
        case “$TERM” in
        xterm-color|*-256color) color_prompt=yes;;
        esac

        # uncomment for a colored prompt, if the terminal has the capability; turned
        # off by default to not distract the user: the focus in a terminal window
        # should be on the output of commands, not on the prompt
        force_color_prompt=yes

        if [ -n “$force_color_prompt” ]; then
        if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
        # We have color support; assume it’s compliant with Ecma-48
        # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
        # a case would tend to support setf rather than setaf.)
        color_prompt=yes
        else
        color_prompt=
        fi
        fi

        if [ “$color_prompt” = yes ]; then
        PS1=’${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w \$\[\033[00m\] ‘
        else
        PS1=’${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ‘
        fi
        unset color_prompt force_color_prompt

        # If this is an xterm set the title to user@host:dir
        case “$TERM” in
        xterm*|rxvt*)
        PS1=”\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1″
        ;;
        *)
        ;;
        esac

        # enable color support of ls and also add handy aliases
        if [ -x /usr/bin/dircolors ]; then
        test -r ~/.dircolors && eval “$(dircolors -b ~/.dircolors)” || eval “$(dircolors -b)”
        alias ls=’ls –color=auto’
        #alias dir=’dir –color=auto’
        #alias vdir=’vdir –color=auto’

        alias grep=’grep –color=auto’
        alias fgrep=’fgrep –color=auto’
        alias egrep=’egrep –color=auto’
        fi

        # colored GCC warnings and errors
        #export GCC_COLORS=’error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01′

        # some more ls aliases
        #alias ll=’ls -l’
        #alias la=’ls -A’
        #alias l=’ls -CF’

        # Alias definitions.
        # You may want to put all your additions into a separate file like
        # ~/.bash_aliases, instead of adding them here directly.
        # See /usr/share/doc/bash-doc/examples in the bash-doc package.

        if [ -f ~/.bash_aliases ]; then
        . ~/.bash_aliases
        fi

        # enable programmable completion features (you don’t need to enable
        # this, if it’s already enabled in /etc/bash.bashrc and /etc/profile
        # sources /etc/bash.bashrc).
        if ! shopt -oq posix; then
        if [ -f /usr/share/bash-completion/bash_completion ]; then
        . /usr/share/bash-completion/bash_completion
        elif [ -f /etc/bash_completion ]; then
        . /etc/bash_completion
        fi
        fialias python=/usr/local/bin/python3.8
        alias python=’/usr/local/bin/python3.8’alias python=/usr/local/bin/python3.8
        alias python=’/usr/local/bin/python3.8′
        alias python=/usr/local/bin/python3.8
        alias python=’/usr/local/bin/python3.8′

        • # ~/.bashrc: executed by bash(1) for non-login shells.
          # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
          # for examples

          # If not running interactively, don’t do anything
          case $- in
          *i*) ;;
          *) return;;
          esac

          # don’t put duplicate lines or lines starting with space in the history.
          # See bash(1) for more options
          HISTCONTROL=ignoreboth

          # append to the history file, don’t overwrite it
          shopt -s histappend

          # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
          HISTSIZE=1000
          HISTFILESIZE=2000

          # check the window size after each command and, if necessary,
          # update the values of LINES and COLUMNS.
          shopt -s checkwinsize

          # If set, the pattern “**” used in a pathname expansion context will
          # match all files and zero or more directories and subdirectories.
          #shopt -s globstar

          # make less more friendly for non-text input files, see lesspipe(1)
          #[ -x /usr/bin/lesspipe ] && eval “$(SHELL=/bin/sh lesspipe)”

          # set variable identifying the chroot you work in (used in the prompt below)
          if [ -z “${debian_chroot:-}” ] && [ -r /etc/debian_chroot ]; then
          debian_chroot=$(cat /etc/debian_chroot)
          fi

          # set a fancy prompt (non-color, unless we know we “want” color)
          case “$TERM” in
          xterm-color|*-256color) color_prompt=yes;;
          esac

          # uncomment for a colored prompt, if the terminal has the capability; turned
          # off by default to not distract the user: the focus in a terminal window
          # should be on the output of commands, not on the prompt
          force_color_prompt=yes

          if [ -n “$force_color_prompt” ]; then
          if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
          # We have color support; assume it’s compliant with Ecma-48
          # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
          # a case would tend to support setf rather than setaf.)
          color_prompt=yes
          else
          color_prompt=
          fi
          fi

          if [ “$color_prompt” = yes ]; then
          PS1=’${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w \$\[\033[00m\] ‘
          else
          PS1=’${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ‘
          fi
          unset color_prompt force_color_prompt

          # If this is an xterm set the title to user@host:dir
          case “$TERM” in
          xterm*|rxvt*)
          PS1=”\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1″
          ;;
          *)
          ;;
          esac

          # enable color support of ls and also add handy aliases
          if [ -x /usr/bin/dircolors ]; then
          test -r ~/.dircolors && eval “$(dircolors -b ~/.dircolors)” || eval “$(dircolors -b)”
          alias ls=’ls –color=auto’
          #alias dir=’dir –color=auto’
          #alias vdir=’vdir –color=auto’

          alias grep=’grep –color=auto’
          alias fgrep=’fgrep –color=auto’
          alias egrep=’egrep –color=auto’
          fi

          # colored GCC warnings and errors
          #export GCC_COLORS=’error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01′

          # some more ls aliases
          #alias ll=’ls -l’
          #alias la=’ls -A’
          #alias l=’ls -CF’

          # Alias definitions.
          # You may want to put all your additions into a separate file like
          # ~/.bash_aliases, instead of adding them here directly.
          # See /usr/share/doc/bash-doc/examples in the bash-doc package.

          if [ -f ~/.bash_aliases ]; then
          . ~/.bash_aliases
          fi

          # enable programmable completion features (you don’t need to enable
          # this, if it’s already enabled in /etc/bash.bashrc and /etc/profile
          # sources /etc/bash.bashrc).
          if ! shopt -oq posix; then
          if [ -f /usr/share/bash-completion/bash_completion ]; then
          . /usr/share/bash-completion/bash_completion
          elif [ -f /etc/bash_completion ]; then
          . /etc/bash_completion
          fi
          fi
          alias python=/usr/local/bin/python3.8

  11. bash: ‘: command not found
    bash: “LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:: command not found
    bash: export: `LS_COLORS”’: not a valid identifier

  12. This all worked exactly as described. The only issue I have at the moment is that if I try : sudo pip3 svgwrite I am told that it can´t install because the running version is 3.5.3 (my old version)

    Any Ideas?

  13. Hello together,

    I have a raspberry pi 3b+ and installed it like you explained it in your discribtion.
    Now I can find under usr/bin a folder with Python-3.6.0 and here my question:

    How I can start Python3?
    Where I can find the exe?

  14. perhaps alternate method of defaulting python to the debian os family way:
    sudo update-alternatives –install /usr/bin/python python /usr/local/bin/python3.8 1

    python –version

    worked on pi4:
    $ lsb_release -a
    No LSB modules are available.
    Distributor ID: Raspbian
    Description: Raspbian GNU/Linux 10 (buster)
    Release: 10
    Codename: buster

  15. I can not get to the last steps either and have tried the variations above.no message if I do the echo …..
    but when I enter the source ~/.bashrc
    I get
    bash: ¨alias: command not found.

    my cursor is at
    pi@raspberrypi:~/Python-3.8.0 $

    any ideas or is there a typo somewhere in the instructions?
    Thanks

    • Hey,

      I think you have a typo in bash_profile
      echo "alias python=/usr/local/bin/python3.8" >> ~/.bashrc

      Just execute these command on terminal.

      Thanks

    • Hey,

      I tried it just now. It works perfectly fine for me on fresh installation of raspbian OS.
      May I know the error that you are getting?

  16. Thanks for these instructions, helped me update Python on Raspbian to 3.8.2 a while back. If I now wanted to update to 3.8.5 how do I go about that? Do I do all of these same steps above? Or is there a simpler way to upgrade Python?

  17. Thank you for the excellent set of instructions! I adapted them to install 3.8.5, and it all worked flawlessly on a RPI4. Thanks again!

Leave a Reply

Your email address will not be published.


*



The reCAPTCHA verification period has expired. Please reload the page.

48-Hour Flash Sale! Courses from just $10.99