Archives For python

This simple tutorial shows how to compile and install Python 3.10.0 or other certain Python version in Ubuntu.

For Ubuntu 18.04 and Ubuntu 20.04 LTS, there’s well trusted “deadsnakes” team PPA that maintains all the Python packages. For non-LTS releases, e.g., Ubuntu 21.04 and Ubuntu 21.10, you may build the programming language package manually from the source tarball.

NOTE: Ubuntu 21.04 has Python 3.10 beta1 in universe repository, remove it if installed before doing the steps below. For Ubuntu 21.10, Python 3.10 will be soon made into the universe repository, so you may skip or install a certain version (e.g., 3.8 or 3.7) via this tutorial.

1. Preparation:

Before getting started, you need to install some essential packages for building the computer language package.

Open terminal either by pressing Ctrl+Alt+T on keyboard or by searching from start menu. When it opens, run the command below to install the dependencies:

sudo apt install wget build-essential libreadline-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev

2. Download Python Tarball:

Next, download the source package by running the wget command in terminal:

wget -c https://www.python.org/ftp/python/3.10.0/Python-3.10.0.tar.xz

For other Python version, go and download via web browser in this page.

And uncompress the tarball either by right-click and selecting ‘Extract Here‘ in file manager, or by running command in terminal:

tar -Jxf Python-3.10.0.tar.xz

3. Configure the source:

After extracted the source, go to new generated folder via command:

cd Python-3.10.0/

The command varies depends on which Python version you downloaded. You may right-click on the folder and choose ‘Open in Terminal‘ instead of running cd command.

When you’re in source directory, run command to configure the source with expensive, stable optimizations (PGO, etc.):

./configure --enable-optimizations

4. Build and install Python:

Finally compile and install it into “/usr/local/bin”:

sudo make altinstall -j4

Here -j4 will start 4 threads to speed up the job. Depends on your CPU, you may increase the number or just skip it.

5. Make Python 3.10 default

After installation, verify via python3.10 -V command. You may set it as default by creating symbolic links to /usr/bin/python:

sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.10 1
sudo update-alternatives --install /usr/bin/pip pip /usr/local/bin/pip3.10 1

It’s possible to set Python3.10 as Python3. However, this may cause issues since it points to system default python that is required for some core apps.

Uninstall Python 3.10:

Until you removed the source directory, you may run command to navigate to that folder and do make uninstall to remove Python 3.10:

cd Python-3.10.0 && sudo make uninstall

If you’ve already removed the source, either re-run step 1, 2 & 3 and use the command above to uninstall, or manually remove all installed files via command:

sudo rm -R /usr/bin/python3.10 /usr/lib/python3.10 /etc/python3.10 /usr/local/lib/python3.10

After several alpha, beta and rc tests, the Python programming language finally released version 3.10 today!

Python 3.10 will receive bug-fix updates in next 18 months. After that, it’s supported with 5-year security updates until October 2026.

What’s New in Python 3.10:

  • Pattern matching syntax, inspired by similar syntax found in Scala, Erlang, and other languages.
  • Support using enclosing parentheses for continuation across multiple lines in context managers
  • Allow writing union types as X | Y
  • Add optional length-checking to zip
  • Precise line numbers for debugging and other tools
  • Require OpenSSL 1.1.1 or newer
  • Remove Py_UNICODE encoder APIs
  • Add optional EncodingWarning
  • Explicit Type Aliases
  • Parameter Specification Variables

See the release note for more about Python 3.10.

How to Install Python 3.10 in Ubuntu:

The well trusted “deadsnakes” team PPA has made the packages for Ubuntu 20.04, Ubuntu 18.04, and derivatives, e.g., Linux Mint 20, Elementary OS 6 and Zorin OS 16.

1.) Firstly, open terminal by either searching from overview screen or pressing Ctrl+Alt+T on keyboard. When it opens, run command to add the PPA:

sudo add-apt-repository ppa:deadsnakes/ppa

2.) Then refresh system cache and install the language via command:

sudo apt update && sudo apt install python3.10

Use Python 3.10 as default Python3:

It’s possible to make Python3 in Ubuntu to be Python3.10 via following commands. However, it causes issues, such as Gnome Terminal refuses to launch. Do it at your own risk!

  • Check current Python3 version:
    python3 --version
  • Use update-alternatives to create symbolic links to python3 (replace python3.8 in Ubuntu 16.04 with ):
    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
  • And choose which one to use as Python3 via command:
    sudo update-alternatives --config python3

PyCharm Ubuntu

JetBrains announced the release of PyCharm 2021.2. Features Python 3.10 support, auto-reload for browser HTML preview.

Starting with the new release, users from Asian can enjoy the a fully localized UI in Chinese, Korean, or Japanese. And it’s going to end support for several packages, e.g., mako, buildout, web2py, in next release.

Before Python 3.10 goes stable, the IDE starts working for Python 3.10 support with following features:

  • Adjust to the upcoming Structural Pattern Matching, such as the Unused local symbols and Unreachable code inspections, smart code completion and syntax highlighting for the match and case keywords, and the Complete Current Statement action.
  • Complete match statements and their corresponding case blocks.
  • Supports type inference for isinstance and issubclass arguments with the new syntax type.

And other changes include:

  • Working in the Python console is now supported on both the client and the host side.
  • Code completion for fields and operators in the MongoDB console (Pro only).
  • Context live templates from the data editor with SQL scripts action (Pro only).
  • auto-reload for browser HTML preview (pro).
  • Auto-import for require() (pro).
  • New Onboarding Tour in the IDE Features Trainer plugin.
  • Test runner auto-detection
  • The Test Management plugin includes Python support and available for PyCharm Community.
  • New Test Data plugin to generate random data.

How to Install PyCharm 2021.2 in Ubuntu:

Jetbrains provides official Linux package. They are portable tarballs, available to download at the link below:

To make life easier, you can install the community edition from the unofficial PPA. And it supports for Ubuntu 20.04 and Ubuntu 21.04 so far.

1.) Open terminal from start menu, and run command to add the PPA:

sudo add-apt-repository ppa:xtradeb/apps

2.) Manually refresh system package cache, e.g., for Linux Mint:

sudo apt update

3.) Finally install PyCharm via command:

sudo apt install pycharm-community

Uninstall:

To remove the PPA, either run command in terminal:

sudo add-apt-repository --remove ppa:xtradeb/apps

or open “Software & Updates” and navigate to “Other Software” tab to remove the relevant line.

And remove PyCharm by running command in terminal:

sudo apt remove --autoremove pycharm-community