I wanted to install python 3x version in a new ubuntu machine which had 20.04.
I am facing the below issues:
Can't fix "zipimport.ZipImportError: can't decompress data; zlib not available
Python3: ImportError: No module named '_ctypes'
ModuleNotFoundError: No module named 'pip._vendor.six'
Can anyone help me to fix the above issue
CodePudding user response:
The below is tried and tested in 5 ec2 ubuntu instances:
The below is an example for python 3.9.0 and it can be replicated for the same:
Navigate to :
https://www.python.org/downloads/release/python-390/
Download the Gzipped source tarball:
https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz
Copy the above downloaded file to your required machine or directly download in that machine
Next, execute the below commands:
sudo apt-get update
Required for zlib:
sudo apt install -y zlib1g-dev zlibc
To resolve the below kind of errors:
Can't fix "zipimport.ZipImportError: can't decompress data; zlib not available
sudo apt install -y libssl-dev
sudo apt install -y libssl1.1 || sudo apt install -y libssl1.0
To resolve below error:
Python3: ImportError: No module named '_ctypes'
sudo apt-get install libffi-dev
Now, all the pre-requisites are done, let's get in to the python installation
extract the downloaded .tgz file using below command:
tar -xf Python-3.x.x.tgz
Before you install the software, make sure you test the system and optimize Python.
The ./configure command evaluates and prepares Python to install on your system. Using the --optimization option speeds code execution by 10-20%.
Enter the following command:
cd python-3.x.x
./configure --enable-optimizations
The above step can take upto 30 minutes
To create a second installation of Python 3.835, in addition to your current Python installation, enter the following:
sudo make altinstall
It is recommended that you use the altinstall method. Your Ubuntu system may have software packages dependent on Python 2.x.
(Option) Overwrite Default Python Installation
To install Python 3.8.3 over the top of your existing Python, enter the following:
sudo make install
(I have overwritten the existing python which I had in my systems i.e., python 3.8.10)
After above steps, the python installation is completed, the next step would be to download the pip, enter the following command:
python3 -m ensurepip --upgrade
To upgrade the pip:
python3 -m pip install --upgrade pip
##############################################################
Replace the above x.x with your required version number where the same has been used
CodePudding user response:
See Suggested build environment
To build python from source you need to install the required package:
sudo apt-get update; sudo apt-get install make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev