Reinstall python on linux

How to uninstall python in ubuntu completely and reinstalling it?

The default python version was 2.7.12 in ubuntu. I installed python2.7.13 using the below commands. Then download using the following command:

version=2.7.13 cd ~/Downloads/ wget https://www.python.org/ftp/python/$version/Python-$version.tgz 
tar -xvf Python-$version.tgz cd Python-$version 

Now, install using the command you just tried, using checkinstall instead to make it easier to uninstall if needed:

./configure sudo make install 

Now there is some issue in pandas(giving no module named pandas when I try to import but if we try to install it shows required already satisfied) so I want to completely remove python 2.7.13 and reinstall python 2.7.12. How can I achieve this?

Don’t try to uninstall default python otherwise chances are many of your components of your ubuntu stop working. Just use virtual environments if you want to use different pythons.

1 Answer 1

My python was corrupted due to some module. So I planned to re-installed or remove the python completely from my Ubuntu 16.04 machine. But sudo apt-get install —reinstall python2.7 command was also failing and was throwing same error. So I finally Did few hacks and cracks. Here are the steps —

Removing all python version manually

 - sudo rm -rf /usr/bin/python2.x as well as python3.x - sudo rm -rf /usr/lib/python2.x as well as python3.x - sudo rm -rf /usr/local/lib/python2.x as well as python 3.x 

In Between if you get this error The package needs to be reinstalled ubuntu Then Run following command

And delete all the lines from above file for the package which was expecting re-install and run sudo apt-get update again.

Now download a python tgz file from https://www.python.org/downloads/ and unzip it and CD into it

./configure make test sudo make install 

Python should be installed now. Check by running python

Источник

How to reinstall or repair python3.8 safely in ubuntu 20.04 and revert all of its files back to default?

I was messing around with python3 and pip, and some packages seem to have corrupted some of the python files, i am getting this error and some others when trying to use pip :

Exception: Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/pip/basecommand.py", line 209, in main status = self.run(options, args) File "/usr/local/lib/python3.8/dist-packages/pip/commands/install.py", line 249, in run with self._build_session(options) as session: File "/usr/local/lib/python3.8/dist-packages/pip/basecommand.py", line 66, in _build_session session = PipSession( File "/usr/local/lib/python3.8/dist-packages/pip/download.py", line 321, in __init__ self.headers["User-Agent"] = user_agent() File "/usr/local/lib/python3.8/dist-packages/pip/download.py", line 93, in user_agent zip(["name", "version", "id"], platform.linux_distribution()), AttributeError: module 'platform' has no attribute 'linux_distribution' Traceback (most recent call last): File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "/usr/lib/python3.8/runpy.py", line 87, in _run_code exec(code, run_globals) File "/usr/local/lib/python3.8/dist-packages/pip/__main__.py", line 19, in sys.exit(pip.main()) File "/usr/local/lib/python3.8/dist-packages/pip/__init__.py", line 217, in main return command.main(cmd_args) File "/usr/local/lib/python3.8/dist-packages/pip/basecommand.py", line 242, in main with self._build_session( File "/usr/local/lib/python3.8/dist-packages/pip/basecommand.py", line 66, in _build_session session = PipSession( File "/usr/local/lib/python3.8/dist-packages/pip/download.py", line 321, in __init__ self.headers["User-Agent"] = user_agent() File "/usr/local/lib/python3.8/dist-packages/pip/download.py", line 93, in user_agent zip(["name", "version", "id"], platform.linux_distribution()), AttributeError: module 'platform' has no attribute 'linux_distribution' 

I tried hours using the suggested methods on related questions but non of them helped based on some threads, you should not remove python3.8 because many system resources use it, so how can i repair all of it files and reinstall it? i want it to basically revert back to default and remove all the installed packages, how can i do it?

Читайте также:  Камера ноутбука линукс минт

Источник

How to Install Python on Ubuntu 22.04?

Python is a versatile programming language widely used for various purposes, i.e., scientific computing, data analysis, and web development. It is often considered one of the best programming languages for beginners, but also widely used by experienced developers due to its vast array of libraries and frameworks. Python is a primary scripting language for Ubuntu and many other Linux distributions, which makes it a catalyst for various operations on Ubuntu.

This article will discuss:

    • How to Check if Python is Installed?
    • How to Check if Python3 is Installed?
    • How to Install python-is-python3?
    • How to Uninstall Python From Ubuntu 22.04?
    • How to Reinstall Python on Ubuntu 22.04 if it was Uninstalled?
    • How to Install a Different Version of Python From Source?

    How to Check if Python is Installed?

    In Ubuntu, Python, and Python3 refer to different versions of the Python programming language. The code written in Python3 may not work with Python2 and vice versa. Therefore, it is necessary to check the version of installed Python before using it:

    The output displays that “python” is not installed in the system.

    How to Check if Python3 is Installed?

    Python3 comes by default with Ubuntu 22.04. To check the installed version of “python3”, run the following command:

    The output returns that “Python 3.10.6” is currently installed in the system.

    How to Install python-is-python3?

    The “python-is-python3” package redirects Python to Python3 by creating a symbolic link of Python3 for Python. This utility is available on the default repository of Ubuntu and can be installed using the command:

    After installing the “python-is-python3” package, the “python” command will show the Python3 (as per the interpreter “/usr/bin/python3”):

    The output displays the current version of Python as “Python 3.10.6”.

    How to Uninstall Python From Ubuntu 22.04?

    Many applications and system packages rely on the default version of Python. If you remove the default Python, the packages and system utilities associated with Python will stop functioning, and the system will crash.

    Let us show you the important utilities that will be removed with the default Python version:

    Look at the above screenshots. Various system utilities, such as Ubuntu Desktop, Ubuntu-minimal, gdm3 (GNOME Display Manager), and other GNOME-based packages, will be removed with the command.

    How to Reinstall Python on Ubuntu 22.04 if it was Uninstalled?

    As discussed earlier, the default version of Python on Ubuntu 22.04 is harmful to uninstall. However, if you have removed it accidentally then it can be fixed by following the steps mentioned in this section.

    Once Python is uninstalled, you will get the following interface, which is tty1:

    Now, all the fixing will be carried out using this tty1 support. If you are unable to get the tty support, you can use the shortcuts “CTRL+ALT+F1 or CTRL+ALT+F3” to invoke it.

    Now, let’s move towards the steps.

    Step 1: Fix the Internet Issue

    Before proceeding, enable internet access on your Ubuntu system using the command which will allow the client to connect to the DHCP server:

    Then, configure the network with the DHCP server via the command:

    Step 2: Fix the Missing Dependencies

    Now, use the command to locate and install the missing dependencies:

    Step 3: Install “ubuntu-Desktop”

    After that, run the following command to install the Ubuntu-Desktop package to have the GUI and the CLI support on your Ubuntu 22.04:

    As soon the installation is completed, the login screen will appear automatically:

    Step 4: Verify the Default Python

    Log in to the system and run the following command to verify the availability of the default Python3:

    The output confirms that with the installation of Ubuntu-Desktop, the Python is restored.

    It is suggested to reinstall the package “python-is-python3” to map the Python3 on Python:

    Now, check the Python version:

    Python has now the same version as Python3.

    Note: The uninstallation of default Python is not recommended as there are a lot of utilities that are dependent on default python.

    How to Install a Different Version of Python From Source?

    The source packages of Python can be obtained from its official website. These source files include the latest stable version and Python prerelease. This section will describe the steps to installing a specific Python version from source files.

    Prerequisite Step: Install Dependencies

    The following dependencies are recommended to be installed before proceeding with the Python’s installation:

    $ sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev libbz2-dev

    Step 1: Download the Source Files

    First, download the source files of the specific version that you want to install as we did here for “Python3.11.1”:

    Note: Navigate to the link to choose the Python version.

    Step 2: Extract the Python Source Files

    Navigate to the directory (in our case, it is the current directory) where the source files are downloaded and extract it using the “-xvf” flag of the “tar” command:

    Step 3: Configure Python

    Switch to the directory of the extracted files and then run the configure script with the “–enable-optimizations” option for the best performance of the Python environment:

    Step 4: Compile the Source Files

    Now, compile the source files using the “make” utility to build an executable (binaries that are recognized by the machine) for the Python package:

    Step 5: Install Python

    Once the files are compiled, you can use the following command to install Python from the binaries:

    After the successful execution, run the following command to verify the installation:

    The output shows that the Python 3.11.1 version has been installed.

    Conclusion

    To install Python on Ubuntu 22.04, you can use an apt package manager and compile/build the source files. By using APT, execute the “sudo apt install python ” command. While the source files are obtained from the official website and are processed by compiling them. This post has presented the methods to install Python on Ubuntu 22.04 and demonstrated the method to recover Ubuntu 22.04 if the default Python is removed accidentally.

    About the author

    Syed Minhal Abbas

    I hold a master’s degree in computer science and work as an academic researcher. I am eager to read about new technologies and share them with the rest of the world.

    Источник

Оцените статью
Adblock
detector