How to fix the broken package manager? - python-3.x

OS :debian8.
debian8#hwy:~$ sudo apt-get install python3
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3 is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 27 not upgraded.
Package manager tells python3 had been installed.
debian8#hwy:~$ python3
bash: python3: command not found
debian8#hwy:~$ sudo find / -name 'python3*'
Nothing output,how to fix the broken package manager?

The first command will show you if the package is installed
~$ dpkg -l python3
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-===================-==============-==============-============================================
ii python3 3.5.1-3 amd64 interactive high-level object-oriented langu
this command will show you the location of python3 program if is installed.
~$ which python3
/usr/bin/python3
re install the package you removed check I have 'ii' and you have 'ri'
apt install --reinstall python3

wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tar.xz
tar -xf Python-3.6.0.tar.xz
cd ./Python-3.6.0
sudo ./configure --prefix=/usr/local/python3.6 --with-ensurepip=install
sudo make
sudo make install
sudo ln -s /usr/local/python3.6/bin/python3.6 /usr/bin/python3.6
sudo ln -s /usr/local/python3.6/bin/pip3.6 /usr/bin/pip3.6
All issues solved.

Related

jenkins installation on wsl ubuntu issue

wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt update
sudo apt install jenkins
these commands are not working fine when I'm running this im getting:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package jenkins is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'jenkins' has no installation candidate
How can i install jenkins in wsl ubuntu
Follow the below steps.
First install certificates for WSL environment.
sudo apt install ca-certificates
Then Install Jenkins.
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo tee \
/usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins
Note: If you have docker running it's better to start Jenkins as a Docker container.

No module named 'distutils.util'

I'm working on ubuntu 16.0.4 LTS and While creating a virtual environment in python 3.8 I'm getting No module named 'distutils.util'
I'm using the repository: sudo add-apt-repository ppa:deadsnakes/ppa
I have tried the following but didn't work
sudo apt install python3-distutils
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python-distutils
I have tried the solution from this link
sudo apt install python3.8-distutils
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python3.8-distutils
E: Couldn't find any package by glob 'python3.8-distutils'
E: Couldn't find any package by regex 'python3.8-distutils'
Make sure to replace 3.10 which is version of python with appropriate version.
Installing Python3.10
Update system
$ sudo apt-get update -y && sudo apt-get full-upgrade -y
Helps to add ppa repositories
$ sudo apt install software-properties-common -y
Adding deadsnake repository
$ sudo apt-add-repository ppa:deadsnakes/ppa
Installing python
$ sudo apt-get install python3.10
$ sudo apt-get install python3.10-dev
$ sudo apt-get install python3.10-tk
Add Python 3.8 & Python 3.10 to update-alternatives
$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 2
Update Python 3 for point to Python 3.10
$ sudo update-alternatives --config python3
Installing distutils.util
$ sudo apt-get install python3.10-distutils
Still using python3.10 -m pip some_command might result in error to fix it use
$ curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10

Cannot connect to EC2 ubuntu 18.04 instance after upgrading to Python3.9

I am using EC2 Ubuntu 18.04 VM.
Due to CVE-2021-3177, Python needs to be upgraded to the latest version of Python3.9 which would be 3.9.9 currently.
I did that using the deadsnakes option as per the steps mentioned below:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install python3.9
sudo apt-get update
sudo apt upgrade -y
The above ensures that Python3.9.9 is now available. But now python3.6 & python3.9 is available. So next we will use the update-alternatives command to make python3.9 as the default version.
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
Now that alternatives are defined, we will switch to Option 2 as the default option i.e. Python3.9
sudo update-alternatives --config python3
Once done, the following command would point to the latest version.
sudo python3 -V
However, if you use the sudo apt update command, you will see an error stating that
Traceback (most recent call last):
File "/usr/lib/cnf-update-db", line 8, in <module>
from CommandNotFound.db.creator import DbCreator
File "/usr/lib/python3/dist-packages/CommandNotFound/db/creator.py", line 11, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Reading package lists... Done
E: Problem executing scripts APT::Update::Post-Invoke-Success 'if /usr/bin/test -w /var/lib/command-not-found/ -a -e /usr/lib/cnf-update-db; then /usr/lib/cnf-update-db > /dev/null; fi'
E: Sub-process returned an error code
To fix this we will have to add a link using the following command
cd /usr/lib/python3/dist-packages/
sudo ln -s apt-pkg.cpython-{36m,39m}-x86_64-linux-gnu.so
Also below is optional, I tried with and without the following commands
apt purge python3-apt
apt install python3-apt
sudo apt install python3.9-distutils python3.9-dev
Once done following command will now not result in any errors
sudo apt update
This means that the issue is fixed.
But for some reason, I cannot connect with the machine afterwards or if I create an AMI using this I cannot connect to the launched instance using PUTTY or SCP.
The same issue persists with Ubuntu-20.x too.
Appreciate your help.
After upgrading Python, there are issues with the following Python modules that cloud-init depends on, which in turn prevents EC2 from being able to correctly configure your newly booted EC2 instance using cloud-init, and which is why it is inaccessible:
setuptools
urllib3
requests
jinja2
netifaces
You can debug this issue by going to your EC2 instance in the AWS Web Console and clicking:
Actions -> Monitor and troubleshoot -> Get system log
Sometimes it takes a while to update, so click the refresh button until your logs appear. It is easier to read the logs if you download them. This is what helped me solve the issues that I was having.
The following steps resolved the issue for me on Ubuntu 18.04 LTS:
For Ubuntu 20.04 LTS, change the 36m in the symbolic links to 38.
# Add deadsnakes ppa repository
sudo add-apt-repository ppa:deadsnakes/ppa
# Install new python version
sudo apt update
sudo apt install python3.10
# Fix broken apt_inst after python upgrade
sudo ln -s /usr/lib/python3/dist-packages/apt_inst.cpython-36m-x86_64-linux-gnu.so /usr/lib/python3/dist-packages/apt_inst.so
# Fix broken apt_pkg after python upgrade
sudo ln -s /usr/lib/python3/dist-packages/apt_pkg.cpython-36m-x86_64-linux-gnu.so /usr/lib/python3/dist-packages/apt_pkg.so
# Make installed python version an alternative with a priority of 2
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2
# Make upgraded python version an alternative with a priority of 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1
# Reinstall python3-apt
sudo apt remove --purge python3-apt
sudo apt autoclean
sudo apt install python3-apt
# Install required packages
sudo apt install \
build-essential \
python3.10-distutils \
python3.10-venv \
libpython3.10-dev
# Install latest pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python3.10 get-pip.py
# Upgrade outdated python libraries that break cloud-init
sudo -i
pip3 install --upgrade setuptools
pip3 install --upgrade urllib3
pip3 install --upgrade requests
pip3 install --upgrade jinja2
pip3 install --upgrade netifaces
pip3 install --upgrade --ignore-installed pyyaml
exit
# Upgrade cloud-init to latest version
sudo apt install --only-upgrade cloud-init
If you use Ansible, it is also affected by the upgrade.
Ansible can be fixed as follows:
Edit /usr/lib/python3/dist-packages/apt/package.py and change the following line:
from collections import Mapping, Sequence
to:
from collections.abc import Mapping, Sequence
It would be useful if the deadsnakes repository could provide an update for python3-apt (eg. python3.10-apt) to solve this issue.
Reference:
https://cloudbytes.dev/snippets/upgrade-python-to-latest-version-on-ubuntu-linux

gnome-terminal not opening after library installation. ERROR: FT_Get_Var_Design_Coordinates

I am using Ubuntu 20.04 and tried to install the Python version of Tecplot (Pytecplot), after which I'm unable to open the terminal anymore.
$ gnome-terminal
/usr/bin/gnome-terminal.real: symbol lookup error: /lib/x86_64-linux-gnu/libcairo.so.2: undefined symbol: FT_Get_Var_Design_Coordinates
My Bash_history shows following commands:
python3 setup.py install
sudo python3 setup.py install
sudo apt-get install libjpeg62:i386
sudo apt update sudo apt install libpng12-0
sudo cp libjpeg.so.62 ../
sudo cp libjpeg.so.62 ../../local/lib/
sudo dpkg -i libpng12-0_1.2.54-1ubuntu1.1_amd64.deb
I made a backup of usr/local/lib before starting, but restoring that backup did not solve the problem.
Can someone help me in solving the above issue?

lsb_release: command not found in latest Ubuntu Docker container

I just wanted to test something out real quick. So I ran a docker container and I wanted to check which version I was running:
$ docker run -it ubuntu
root#471bdb08b11a:/# lsb_release -a
bash: lsb_release: command not found
root#471bdb08b11a:/#
So I tried installing it (as suggested here):
root#471bdb08b11a:/# apt install lsb_release
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package lsb_release
root#471bdb08b11a:/#
Anybody any idea why this isn't working?
It seems lsb_release is not installed.
you can install it via
apt-get update && apt-get install -y lsb-release && apt-get clean all
This error can happen due to uninstalling or upgrading the default python3 program version in ubuntu 16.04
The way to correct this is by reinstalling the original python3 version which comes with ubuntu and relinking again. (in ubuntu 16.04 - the default python3 version is python 3.5
sudo rm /usr/bin/python3
sudo ln -s /usr/bin/python3.5 /usr/bin/python3
Just use cat /etc/os-release and that should display the OS details.
Screenshot from debian.
Screenshot from ubuntu.
Screenshot from fedora.
lsb_release.py lives in /usr/share/pyshared which to me doesn't look like python3.6 and above is referencing.
I found the following will create a link back from a later Python install to this /usr/share script:
sudo ln -s /usr/share/pyshared/lsb_release.py /usr/lib/python3.9/site-packages/lsb_release.py
In case one is trying to deal with lsb_release: command not found on fedora or redhat, the package to install is redhat-lsb-core , so sudo dnf install redhat-lsb-core
While writing Dockerfile we can add lsb-release package - like this
RUN apt-get update -y \
&& apt-get upgrade -y \
&& apt-get install lsb-release -y \
&& apt-get clean all
Assuming OS is Ubuntu.

Resources