Keep These Portable Python Builds for Linux Always With You

29/12/2020
Most Linux distributions come with pre-installed Python packages. These packages are deeply integrated into the OS and they depend on shared libraries. If you want to keep Python projects isolated, using virtual environments is an excellent option. Another realistic option would be to use Python installed on an external drive as a portable package that you can carry it at your convenience (useful for teaching for example).

Unfortunately, as far as portability of Python is concerned, Linux users don’t have much choice. While compiling Python with shared libraries is easy, building Python with statically linked libraries takes more than a few tweaks, patches and changing lines in source code.

This article will list the few portable Python options available for Linux. Note that any of the methods mentioned below will work on external drives formatted in NTFS or EXT3/EXT4 file systems only. FAT32 file system doesn’t support symlinks which is a requirement for these packages to work.

Python Standalone Builds

Python Standalone Builds is a project that builds and distributes portable Python versions. These builds can be stored on external media like USB sticks and they include a full featured Python installation along with all of its standard libraries.

Various Python builds are available for Windows, macOS, and Linux on its releases page. These builds are compiled with a huge focus on static libraries instead of shared ones (OpenSSL is statically linked for example).

You can download builds from here. These builds have “CPython” in their filename which is the same official version of Python that you can download from the official Python website. To extract the downloaded file, you will have to run the commands below:

$ sudo apt install zstd
$ unzstd your/path/to/downloaded_file.tar.zst

Using the command above, you will get a tar file that can be extracted using your file or archive manager. After extracting, you can find Python executable located in “/path/to/extracted/folder/python/install/bin/” directory.

To execute a Python file using this version of Python, you have to run:

$ /path/to/extracted/folder/python/install/bin/python3 file.py

Note that you will have to specify the full path of the Python executable or use “dot slash (./)” from a terminal opened in the directory of the executable.

Portable PyPy for Linux

Portable PyPy, as the name suggests, provides portable PyPy builds for various Linux distributions. PyPy is an alternative implementation of the Python language that focuses on speed with its “Just-in-Time” compiler. In many scenarios, its performance is comparable to Java and C.

Using these builds is as easy as downloading a portable PyPy archive, uncompressing it and then running the Python binary instantly without installing any extra libraries. These builds are tested to be working on various DEB and RPM based distributions that include RHEL/Centos 6 and later, Fedora, SuSE Linux, Ubuntu and Debian stable. PyPy binaries should run on any distribution that includes glibc 2.17.

You can download the latest build from here. Downloaded tar.bz2 file can be extracted using your file or archive manager.

After extracting, you can find Python executable located in “/path/to/extracted/folder/bin/” directory.

To execute a Python file using this version of Python, you have to run:

$ /path/to/extracted/folder/bin/python3 file.py

As stated earlier, you will have to specify the full path of the Python executable or use “dot slash (./)” from a terminal opened in the directory of the executable.

Anaconda

Anaconda is a free and open-source distribution of the Python for scientific computing (data science, machine learning etc.). It has its own package manager “conda” that aims to simplify package management and deployment, though you can also use pip package manager with it after some tinkering.

Anaconda provides a command line installer for Linux and it can be installed anywhere, even directly on external drives. You can find the installer here.

After downloading, run the .sh installer file and follow the on screen instructions. You can directly specify path to external USB drive or later copy the installation folder.

Once the installation has finished, you can find Python executable located in “/path/to/installation/folder/bin/” directory.

To execute a Python file using this version of Python, you have to run:

$ /path/to/installation/folder/bin/python3 file.py

Note that you will have to specify full path of the Python executable or use “dot slash (./)” from a terminal opened in the directory of the executable.

These are the only three options available today that provides precompiled, portable binaries of Python for Linux. If you are storing them on an external drive, consider keeping them in compressed archive format and then extract them on the host OS where USB drive is plugged in. Usually internal drives have superior read and write speeds and Python binaries running from these internal drives will give you better performance than those running in external media. Of course, you always have a choice to run Python directly from an extracted folder stored in an external drive, if you prefer that.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

How to Calculate Matrices in Python Without NumPy

For many applications, you need mathematics. In Python there is the maths module which handles the basics such as rounding,...
29/12/2020

How to Create and Manage Python Virtual Environments

It is pretty common to see Python developers installing and upgrading packages from standard and non-standard sources to...
29/12/2020

Scheduling tasks Using Python

Some tasks in our life are really time taking and we get bored doing those tasks repeatedly. In order to avoid those boring...
29/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

SỰ KHÁC BIỆT GIỮA RESIDENTIAL PROXY VÀ PROXY DATACENTER
17/02/2024

Mua Proxy v6 US Private chạy PRE, Face, Insta, Gmail
07/01/2024

Mua shadowsocks và hướng dẫn sữ dụng trên window
05/01/2024

Tại sao Proxy Socks lại được ưa chuộng hơn Proxy HTTP?
04/01/2024

Mua thuê proxy v4 nuôi zalo chất lượng cao, kinh nghiệm tránh quét tài khoản zalo
02/01/2024