how to update python in raspberry pi - python

I need python newest version in raspberry pi.
I tried apt install python3 3.8 apt install python3 but this didnot work.
And I also needed to update my raspberry pi python IDLE

First update the Raspbian.
sudo apt-get update
Then install the prerequisites that will make any further installation of Python and/or packages much smoother.
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
And then install Python, maybe by downloading a compressed file?
example 1 :
wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
Extract the folder :
sudo tar zxf Python-3.8.0.tgz
Move into the folder :
cd Python-3.8.0
Initial configuration :
sudo ./configure --enable-optimizations
Run the makefile inside the folder with the mentioned parameters :
sudo make -j 4
Run again the makefile this time installing directly the package :
sudo make altinstall
Maybe You already did it but You don't know how to setup the new version as a default version of the system?
Check first that it has been installed :
python3.8 -V
Send a strong command to .bashrc telling him who (which version) is in charge of Python
echo "alias python=/usr/local/bin/python3.8" >> ~/.bashrc
Again! Tell him because .bashrc has to understand! I am joking - You have to source the file so the changes can be applied immediately :
source ~/.bashrc
And then check that Your system changed the default version of Python to Python 3.8
python -V
The failure depends on many factors : what dependencies are installed, what are the packages added to the source_list.d, some inconvenient coming up during the installation. All may give you more information than you think, just read carefully.
Hope it helped.

To all of you who got problem with freezing RPi 3 in step:
sudo make -j 4
just change it to:
sudo make -j 2
or simply:
sudo make
Best regards

Follow below commands to install the version which you want:
tar xf Python-3.x.x.tar.xz
cd Python-3.x.x
./configure --enable-optimizations
make
sudo make install
once completed run python -V

Related

How to copy python from one stage to another during a multi-stage docker build

I'm using nvidia/cudagl:11.4.2-base-ubuntu20.04, which does not include python. This is ok for me, since I need a very specific python version (3.9.9) anyhow. One way should be to compile python myself (e.g. according to https://askubuntu.com/a/890959). However, I thought maybe I could use a multi-stage build and just copy the required python executables from python:3.9.9-slim, so that I don't have to deal with the compilation and its remnants.
Is that a feasible idea? And what exactly would need to be copied over?
It's not really feasible to copy installed binaries from one image to another. If you know the application is only a static binary, or you know it has very controlled library dependencies, it could work, but Python installs things in many different directories and includes its own library tree. You'll be much better off using the distribution package manager to install the specific version of Python you need.
Since your base image is based on Ubuntu, there's an add-on Ubuntu repository that contains many different Python versions; also see Python 3.7 on Ubuntu 20.04. Translating that answer to Dockerfile format, you'd get something like:
FROM nvidia/cudagl:11.4.2-base-ubuntu20.04
...
# USER root (if you're not already root)
RUN apt-add-repository ppa:deadsnakes/ppa \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get install --no-install-recommends --assume-yes \
python3.9
As of this writing that includes Python 3.9.10 rather than 3.9.9, but this shouldn't be a significant difference for you.
As David Maze pointed out, it is apparently not a good idea to copy over a Python install. Unfortunately, the popular deadsnakes repository that he suggested, does not supply patch versions of Python, i.e. only the latest patch of Python 3.9 (at the time of writing 3.9.10) and not previous versions like 3.9.9.
I found that pyenv is a pretty convenient way to install a specific Python version (originally posted here):
FROM ubuntu:16.04
ENV PYTHON_VERSION 2.7.10
#Set of all dependencies needed for pyenv to work on Ubuntu systems
RUN apt-get update \
&& apt-get install -y --no-install-recommends make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget ca-certificates curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev mecab-ipadic-utf8 git
# Set-up necessary Env vars for PyEnv
ENV PYENV_ROOT /root/.pyenv
ENV PATH $PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH
# Install pyenv
RUN set -ex \
&& curl https://pyenv.run | bash \
&& pyenv update \
&& pyenv install $PYTHON_VERSION \
&& pyenv global $PYTHON_VERSION \
&& pyenv rehash
# Optional : Checks Pyenv version on container start-up
ENTRYPOINT [ "pyenv","version" ]

python3.7 No module named pip

i had a problem with installing packages to new upgraded python to version 3.7
When i type:
python3.7 -m pip install pip -d
/usr/local/bin/python3.7: No module named pip
I make easy_install like this: sudo easy_install pip what solve previous problems, but now it create pip3.7 in a weird way. Whem i calling for pip3.8 version, this returns me a message:
pip3.7 -V
pip 19.2.3 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)
Someone know what i am doing wrong? I tried many things to resolve it. Reinstall, purge, install with symbolic link from python2 etc.
There is a script which i used to install python3.7 (i had also a problem with zlib):
sudo cd /home
sudo wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
sudo tar xf Python-3.7.3.tar.xz
sudo cd ./Python-3.7.3/
sudo ./configure
sudo make
sudo make install
sudo update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3 10
python3 --version
Where is a mistake?
Answer finally i find myself. There: https://linuxize.com/post/how-to-install-python-3-7-on-debian-9/
There with similar errors you can recompile it, even without removal (on secound machine i checked without removal) failed installation before.
If someone want to good upgrade with everywith working on debian 9. I recommend that script:
NOW_DIR=$(pwd)
apt update
apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
mkdir ~/python_upgrade
cd ~/python_upgrade
curl -O https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
tar -xf Python-3.7.3.tar.xz
cd Python-3.7.3
./configure --enable-optimizations
make -j $(nproc)
make altinstall
python3.7 --version
cd $NOW_DIR
rm -rf ~/python_upgrade
There are minor changes from that commands in tutorial. Run above file.sh as root.
It can take some times, on my virtual machine with 2 cores during another job it takes 40 minutes. I hope someone find there good answer, not totally green comments like 'apt install' which is first try action before looking to web.

How to build Python 3 from source on Ubuntu [duplicate]

This question already has answers here:
How would I build python myself from source code on Ubuntu?
(5 answers)
Closed 3 years ago.
When I tried to build Python 3 on Ubuntu 18.04.2 LTS, it shows me the next error.
When type:
./configure
make
make test
3 tests failed again:
test_urllib test_urllib2 test_urllib2net
Makefile:958: recipe for target 'test' failed
make: *** [test] Error 1
Someone help me
First, make sure your system is fully updated:
sudo apt update
sudo apt upgrade
Next, install the default GCC toolchain with:
sudo apt install build-essential
Next, we need to install a few prerequisites for building Python:
sudo apt install libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev
sudo apt install libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev libffi-dev
At the time of this writing, the latest stable version of Python is 3.7.1, if you want to use a newer version change the next instructions accordingly:
wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz
tar xf Python-3.7.1.tar.xz
cd Python-3.7.1
./configure --enable-optimizations
make -j 8
sudo make altinstall
It seems like the ssl lib's not installed in your system. Try to fix it. Actually, you can give us much more information, if you run make test in a verbose mode: it will show you, what lines cause the problem

Install PyQt5 on Raspberry for Python3.6

Since I found no answer for my question, neither in older posts nor in other forums, I want to ask the stackoverflow community for advice.
I am using a raspberry pi 3B+, version 9.4 (lite) with kernel version 4.14.71-v7.
I use python3.6. I installed it as follows:
sudo apt-get install build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
cd /usr/src
sudo wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
sudo tar xzf Python-3.6.0.tgz
sudo -s
cd Python-3.6.0
bash configure
make altinstall
exit
Installation was without any trouble and everything works perfectly.
Now I wanted to install the PyQt5 modul for python3.6. I usually use
sudo python3.6 -m pip install ...
for installing a modul for python3.6. Trying
sudo python3.6 -m pip install pyqt5
gave me the error message
Could not find a version that satisfies the requirement PyQt5 (from versions: )
No matching distribution found for PyQt5
So I tried
sudo apt-get update
sudo apt-get install qt5-default pyqt5-dev pyqt5-dev-tools
But it installed PyQt5 for python3.5 (which is preinstalled) on the raspberry.
So does anybody know how to use or install PyQt5 for the subsequently installed
python3.6?
Edit 08.03.2019:
Thanks FlyingTeller. I started to build from source. I followed the steps from
your link.
sudo apt-get update
cd /usr/src
sudo wget https://www.riverbankcomputing.com/static/Downloads/sip/sip-4.19.14.tar.gz
sudo tar xzf sip-4.19.14.tar.gz
cd sip-4.19.14
sudo -s
python3.6 configure.py --sip-module=PyQt5.sip
make
make install
cd /usr/src
sudo wget https://www.riverbankcomputing.com/static/Downloads/PyQt5/PyQt5_gpl-5.12.tar.gz
sudo tar xzf PyQt5_gpl-5.12.tar.gz
cd PyQt5_gpl-5.12
python3.6 configure.py
Then I received the following error
Error: Use the --qmake argument to explicitly specify a working Qt qmake.
I think I am on the right way, but I do not understand what qmake is or what it
means.
Edit 10.03.2019:
I could solve the last error message. I installed
sudo apt-get install qt5-default
Then I did the same procedure as already mentioned. Now I get the error
fatal error: sip.h: File or directory not found
#include <sip.h>
PyQt5 config.py is in: /usr/src/PyQt5_gpl-5.12
SIP sip.h is in: /usr/src/sip-4.19.14
Anybody an idea? Thanks guys.
Today I found the solution. The steps below worked for me, without any error. The whole process took almost two hours.
sudo apt-get update
sudo apt-get install qt5-default
sudo apt-get install sip-dev
cd /usr/src
sudo wget https://www.riverbankcomputing.com/static/Downloads/sip/sip-4.19.14.tar.gz
sudo tar xzf sip-4.19.14.tar.gz
cd sip-4.19.14
sudo python3.6 configure.py --sip-module PyQt5.sip
sudo make
sudo make install
cd /usr/src
sudo wget https://www.riverbankcomputing.com/static/Downloads/PyQt5/PyQt5_gpl-5.12.tar.gz
sudo tar xzf PyQt5_gpl-5.12.tar.gz
cd PyQt5_gpl-5.12
sudo python3.6 configure.py
sudo make
sudo make install
Seems like they moved some things around. This seems to work, as far as getting things, and compiling them. It takes a long time to build.
For the associated designer, look at:
QtDesigner for Raspberry Pi
sudo apt-get update
sudo apt-get install qt5-default
sudo apt-get install sip-dev
cd /usr/src
sudo wget https://www.riverbankcomputing.com/static/Downloads/sip/4.19.23/sip-4.19.23.tar.gz
sudo tar xzf sip-4.19.23.tar.gz
cd sip-4.19.23
sudo python3 configure.py --sip-module PyQt5.sip
sudo make
sudo make install
cd /usr/src
sudo wget https://www.riverbankcomputing.com/static/Downloads/PyQt5/5.13.2/PyQt5-5.13.2.tar.gz
sudo tar xzf PyQt5-5.13.2.tar.gz
cd PyQt5-5.13.2
sudo python3 configure.py
sudo make
sudo make install
In my case it helped to update pip from verion 18 to the newest, in my case 20.2 (python -m pip install --upgrade pip) and then do a pip install PyQt5.
The instructions used in the accepted answer did not work for me. I think it's simply because they are outdated. I wanted to post the list of commands that did work for me. I'm running a Pi 400 with the latest version of Raspbian as of 12/20/2020. I used the default python3 rather than python3.6.
Here is the modified list of commands that worked for me:
sudo apt-get install qt5-default
sudo apt-get install sip-dev
cd /usr/src
sudo wget https://www.riverbankcomputing.com/static/Downloads/sip/sip-5.5.1.dev2011271026.tar.gz
sudo tar xzf sip-5.5.1.dev2011271026.tar.gz
cd sip-5.5.1.dev2011271026
sudo python3 setup.py build
sudo python3 setup.py install
sudo wget https://files.pythonhosted.org/packages/28/6c/640e3f5c734c296a7193079a86842a789edb7988dca39eab44579088a1d1/PyQt5-5.15.2.tar.gz
sudo tar xzf PyQt5-5.15.2.tar.gz
cd PyQt5-5.15.2
sudo python3 configure.py
sudo make
sudo make install
Can't comment due to reputation but I would add to Christ Troutner's useful updated answer, that in case users get a No module named 'PyQt5.sip' error, try --sip-module PyQt5.sip during configure, per the docs:
Note
When building PyQt5 v5.11 or later you must configure SIP to create a
private copy of the sip module using a command line similar to the
following:
python configure.py --sip-module PyQt5.sip
If you already have SIP installed and you just want to build and
install the private copy of the module then add the --no-tools option.
The accepted answers did not work for me, below is the code that worked for me.
sudo apt-get update
sudo apt-get install qt5-default
sudo apt-get install qtcreator
This code not only installs Qtcreator but also installs Qt5 Assistant, Qt5 Designer, and Qt5 Linguist

How do you update to the latest python 3.5.1 version on a raspberry pi?

I got my Raspberry Pi yesterday and I am already trying to code with it. I have a program that I was planning to run on it but it is only compatible with Python versions 3.5.0 or 3.5.1 and everything I find on the internet seems to either be outdated, to do with Python 2 or doesn't relate to my problem as I haven't seen anything else that 100% requires Python 3.5 and can cope with 3.4(currently pre-installed). .exe files don't work on Linux. I am new to the Raspberry Pi and with Linux as I have always been a Windows user. Any help is appreciated. Many Thanks - Robert
cd ~
wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz
tar -zxvf Python-3.5.1.tgz
cd Python-3.5.1
./configure && make && sudo make install
I would compile it myself (and indeed, have a few times). I'm assuming that you're running Ubuntu or Raspbian. You should be able to install the dependencies:
$ sudo apt-get install build-essential \
libncursesw5-dev \
libreadline5-dev \
libssl-dev \
libgdbm-dev \
libc6-dev \
libsqlite3-dev tk-dev \
libbz2-dev
Then go download the source and extract it, and then install it:
$ tar -xzvf https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz
$ cd Python-3.5.1
$ ./configure && make && sudo make install
If you're missing a dependency it will probably die at the ./configure step. But if everything works, you'll have a brand new Python 3.5 install on your Raspberry Pi. Congrats!

Categories