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

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

Related

how to update python in raspberry pi

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

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.

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

install python 3.5.2 into ubuntu 16.04 [duplicate]

This question already has answers here:
How to download and use python on ubuntu? [closed]
(4 answers)
Closed 2 years ago.
I want to change the python version from 3.6 to 3.5.
I installed python3.5 on ubuntu 16.04. but it is not in usr/bin
I executed update-alternatives --display python3
python3 - auto mode
link best version is /usr/bin/python3.6
link currently points to /usr/bin/python3.6
link python3 is /usr/bin/python3
/usr/bin/python3.6 - priority 3
/usr/local/lib/python3.5 - priority 1
/usr/local/lib/python3.6 - priority 2
But I execute python3 -V
Python 3.5.2
When I try to install some packages using pip
pip install pymysql
-bash: /home/ubuntu/.local/bin/pip: /usr/bin/python3: bad interpreter: Permission denied
I want to correctly install python 3.5.2 on the computer and set it as the default version.
1) Install pre-requiste
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
2) Move to src folder and get the tar of python3.5.2
cd /usr/src
sudo wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
3) Now extract the downloaded archive on your system.
sudo tar xzf Python-3.5.2.tgz
4) Compile the source using alInstall
cd Python-3.5.2
sudo ./configure --enable-optimizations
sudo make altinstall
5) Check the install
python3.5 -V

Python 3.3 source code setup: modules were not found: _lzma _sqlite3 _tkinter

I am trying to set up the compiled version of CPython, on Ubuntu 12.04, by following the python developer guide.
Even after installing the dependent packages lzma and sqlite3, build fails indicating that the dependent modules were not found.
Exact Error:
*Python build finished, but the necessary bits to build these modules were not found:
_lzma _sqlite3 _tkinter
To find the necessary bits, look in setup.py in detect_modules() for the module's name.*
I could not locate the package tkinter. Appreciate any help.
I was able to build Python 3.3 without modifying setup.py after installing the following packages on my Ubuntu Precise box.
build-essential
zlib1g-dev
libbz2-dev
libncurses5-dev
libreadline6-dev
libsqlite3-dev
libssl-dev
libgdbm-dev
liblzma-dev
tk8.5-dev
In general, see Python Developer's Guide for dependencies. There it says:
"If you want to build all optional modules, install the following packages and their dependencies":
sudo apt-get install build-essential gdb lcov pkg-config \
libbz2-dev libffi-dev libgdbm-dev libgdbm-compat-dev liblzma-dev \
libncurses5-dev libreadline6-dev libsqlite3-dev libssl-dev \
lzma lzma-dev tk-dev uuid-dev zlib1g-dev
The lack of finding lzma and sqlite3 may be because your paths (LD_LIBRARY_PATH in particular) were incorrect. How did you install those two packages; did you use the package manager? If you installed manually, where did you install them? Also, did you install the development versions, if you used the package manager to install lzma and sqlite3? When installing from source, you'll need the development versions, so Python's source can find the necessary include files.
Further, you may have to edit setup.py to indicate where these packages can be found.
As for tkinter: this relies on tcl/tk, so check that you have the development versions of these packages installed if you're installing python/tkinter from source.
This works for me (Python 3.4, Ubuntu 13.04) meaning "make" completes cleanly:
sudo apt-get install build-essential python-dev libncurses*-dev \
liblzma-dev libgdbm-dev libsqlite3-dev \
libbz2-dev tk-dev
Install:
cd python3.4
make clean && ./configure && make && sudo make install
I used the instructions here:
python-on-debian-wheezy
But I also had to install tk-dev which wasn't listed there.
Struggled a bit with this on Ubuntu 20.04 in 2021 (in case anyone lands here looking for a newer set of instructions). Found this article that was very useful:
https://linoxide.com/ubuntu-how-to/install-python-3-9-on-ubuntu-20-04-lts/
On Ubuntu you can install the dependencies with apt so it's just a matter of knowing which. The build commands I used were the following:
# Update repo, very important on fresh server install
apt update
# Install dependencies
apt install gcc build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev
# Configure with optimizations
./configure --enable-optimizations
make -j 4 # 4 cores
make test # Shows you anything you missed
# https://docs.python.org/3/using/unix.html#building-python
make altinstall
I chose not to install sqlite or tkinter because I didn't need them, but the process is the same. Just include those dependencies found in #simp76's answer.
I just ran through this process on a fresh install of Ubuntu 20.04 on a DO droplet and it worked flawlessly.

Categories