简体   繁体   中英

I rm python3.9 can i get it back ,

I am new on linux and i tried to change the Symbolic link of python3 in /usr/bin/, and i accidentally remove the python3.9 file. But i know i didn't delete it completely Because there is still a lot of file called python3.9: After that 'apt' didn't work anymore and i got this error :

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'

Now, I only have version 2.7 of python and i can't install another because apt don't work !!

This is the result ofls /usr/bin/python*:

So I hope someone can help me and I wish you a good afternoon

Edit: As you've lost apt command meaning you can't install or remove anything using apt command.

The possible way to fix this is by reinstalling respective apt-package of your architecture and then do the below python installation.

To install apt-package again download the .deb file from the “/etc/apt/sources.list” file. Lots of links for installation and upgrades for packages will be in this file.

Now find the downloading source using $cat /etc/apt/sources.list command.

Find /pool/main/a/apt/ directory under downloading source and then download the .deb file which matches your architecture and download it.

Thereafter install this using dpkg command like this

sudo dpkg -i PackageName.deb

Replace the PackageName with your file name (eg- apt_1.6.13_arm64/apt_1.9.3_i386).

Restart the PC and then check the /usr/bin/ directory to ensure if it had properly installed. If you get nothing there then run locate apt-get command to locate it. If you can't get it then there is no other way than reinstalling the OS itself.

If you have reinstalled apt then use the following commands to freshly install Python.

Note that all the commands below will be for Python3 as you're concerned with version 3.9.

    # To uninstall the Python only
sudo apt-get remove python3.9

   # To uninstall the Python with all the packages also
sudo apt-get remove --auto-remove python3.9

   # To remove all the dependencies and configuration files 
sudo apt-get purge --auto-remove python3.9

Now to install the Python3. The following command will install the latest version of python3. which to this date is python3.9.

sudo apt-get install python3

You can use pip to manage the python packages also. To install pip use the following command

sudo apt install python3-pip

Now to manage the python packages using pip

# To install package; replace PackageName with the name of package(like flask)
sudo pip install PackageName

# To uninstall package
sudo pip uninstall PackageName

If you get trouble with pip get list of all the commands pip uses with

sudo pip help

You can list all the Python version installed (on default location) ls /usr/bin/python*

Hope this will help in resolving the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM