Pip update python linux

Upgrade Python to latest version (3.10) on Ubuntu Linux

Linux systems come with Python install by default, but, they are usually not the latest. Python also cannot be updated by a typical apt upgrade command as well.

To check the version of Python installed on your system run

python keyword is used for Python 2.x versions which has been deprecated

  1. Update Python to the latest version
  2. Fix pip & other Python related issues
  3. While doing the above two, ensure your Ubuntu which is heavily dependent on Python does not break

Updating Python to the latest version

Ubuntu’s default repositories do not contain the latest version of Python, but an open source repository named deadsnakes does.

Python3.10 is not officially available on Ubuntu 20.04, ensure you backup your system before upgrading.

Step 1: Check if Python3.10 is available for install

sudo add-apt-repository ppa:deadsnakes/ppa sudo apt update 

Check if Python 3.10 is available by running

Читайте также:  Php digit to word

This will produce the below result, if you see python3.10 it means you can install it

Step 2: Install Python 3.10

Now you can install Python 3.10 by running

sudo apt install python3.10 

Now though Python 3.10 is installed, if you check the version of your python by running python3 —version you will still see an older version. This is because you have two versions of Python installed and you need to choose Python 3.10 as the default.

Step 3: Set Python 3.10 as default

Steps beyond here are tested on Ubuntu 20.04 in VM & WSL2, but are experimental , proceed at your own risk.

Changing the default alternatives for Python will break your Gnome terminal. To avoid this, you need to edit the gnome-terminal configuration file.

Open the terminal and run:

sudo nano /usr/bin/gnome-terminal 

In first line, change #!/usr/bin/python3 to #!/usr/bin/python3.8 . Press Ctrl +X followed by enter to save and exit.

Then save and close the file.

Next, update the default Python by adding both versions to an alternatives by running the below

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 Now run
sudo update-alternatives --config python3 

Choose the selection corresponding to Python3.10 (if not selected by default).

Now run python3 —version again and you should see the latest Python as the output.

Fix pip and disutils errors

Installing the new version of Python will break pip as the distutils for Python3.10 is not installed yet.

Fix Python3-apt

Running pip in terminal will not work, as the current pip is not compatible with Python3.10 and python3-apt will be broken, that will generate an error like

Traceback (most recent call last): File "/usr/lib/command-not-found", line 28, in <module> from CommandNotFound import CommandNotFound File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 19, in <module> from CommandNotFound.db.db import SqliteDatabase File "/usr/lib/python3/dist-packages/CommandNotFound/db/db.py", line 5, in <module> import apt_pkg ModuleNotFoundError: No module named 'apt_pkg' 

To fix this first remove the current version of python3-apt by running

sudo apt remove --purge python3-apt 

DO NOT RUN sudo apt autoremove as it will remove several packages that are required. This may break your system if you’re using GUI, if you’re on WSL2 you can proceed.

Finally, reinstall python3-apt by running

sudo apt install python3-apt 

Install pip & distutils

Running pip will still throw an error pip: command not found . We need to install the latest version of pip compatible with Python 3.10.

Also, if try to manually install the latest version of pip, it will throw an error like

ImportError: cannot import name 'sysconfig' from 'distutils' (/usr/lib/python3.10/distutils/__init__.py) 

Or you might also see an error stating No module named ‘distutils.util’ . This is because the distutils module is not installed yet, to install run the below command

sudo apt install python3.10-distutils 

Now you can install pip by running

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py sudo python3.10 get-pip.py 

If you get an error like bash: curl: command not found then you need to install curl first by running sudo apt install curl

Now you can run pip and you should see the output of pip —version

Fix pip-env errors when using venv

When you try to create a new virtual environment using python -m venv env , you may into the following error.

Error: Command -Imensurepip--upgrade--default-pipYou can fix this by reinstalling venv by running
sudo apt install python3.10-venv 

All should be done now. It is complicated, but this is how you update Python to latest version.

Extra

If you have oh-my-zsh installed, you can avoid typing out python3 by running

Now you can run your files with py or python .

Источник

How to upgrade your pip package to the latest version

Pip is a useful tool for managing and installing python packages. Here’s how to upgrade it on various operating systems.

BitLaunch

BitLaunch

How to upgrade your pip package to the latest version

Pip is the defacto tool for managing and installing your Python packages. It lets you install third-party software packages that are listed in the Python Package Index (PyPi), extending functionality for developers and allowing regular users to install certain applications written in Python.

Pip is usually bundled with Python and updates automatically, but you might want to manually upgrade and manage it. This is what we’ll be teaching you today. This process should work whether you’re using pip on Linux, Windows, or macOS.

Checking your pip version

The first thing you’ll probably want to do is check which pip version you have in the first place. You can then compare that to the latest published version to see whether you should upgrade. The command for this is thankfully very simple:

Your output should look something like this:

pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8) 

You can check what the latest pip version is here and decide whether to update accordingly. At the time of writing, the latest pip version is 22.0.4. Our server is on 20.0.2, so an upgrade is definitely in order.

How to upgrade pip

Upgrading pip is again very easy process. Just run the following:

python -m pip install --upgrade pip 

Bear in mind that this command will try to uninstall the current version and replace it with the new one.

Upgrading pip on Ubuntu

If you see the message Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr , it’s because you’re using Ubuntu. The Ubuntu version of pip has been modified to disallow upgrades via this method. Instead, you must use the Ubuntu packaging system.

sudo apt update sudo apt install pip 

Note the Ubuntu package probably won’t be up to date. If you do need the latest version, you can download get-pip.py and run it. However, it’s worth noting that running pip as the root user can cause broken permissions and conflicting behavior with the system package manager. You are generally better off using a virtual environment.

Here are the commands you need:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python3 get-pip.py 

How to downgrade pip

If you do find that you need to rollback your pip version due to bugs, incompatibilities, or any other reason, find the version number you want to roll back to and then run this command:

python -m pip install pip==your.version.number 

How to update Python packages with pip

Pip also allows you to manually update individual Python packages. We can use matplotlib as an example:

pip3 install --upgrade matplotlib 

That about covers it. Pip is a versatile and useful tool and know you should now understand it a little better.

If you like to do your development in the cloud, feel free to check out our high-speed, anonymous VPS servers.

How to add SSL to Nginx

How to add SSL to Nginx

SSL keeps your user’s information secure and helps your website rank on search engines. Here’s how to set it up on Nginx.

Introducing: Fast SSL setup with the BitLaunch LEMP app

Introducing: Fast SSL setup with the BitLaunch LEMP app

Add SSL to your Nginx server with a single command via the BitLaunch LEMP app.

Источник

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