Knowledge Base
Tutorials
Tutorials
  • How to install Joomla 4.2.2 on Ubuntu 20.04?
  • How to set and execute environment and shell variables in Linux?
  • How to employ Docker containers?
  • How to access PostgreSQL Image?
  • How to add and delete users on Ubuntu 20.04?
  • How to add swap space on Ubuntu 20.04?
  • How to back up, restore, and migrate a MongoDB database on Ubuntu 20.04?
  • How to configure additional SSH keys to your public cloud instance?
  • How to configure static IP on Ubuntu?
  • How to create a CLI with Python Fire on Ubuntu 22.04?
  • How to create a new user and manage permissions in MySQL?
  • How to create an instance with Terraform?
  • How to import and export a MongoDB database on Ubuntu 20.04?
  • How to install 7zip on Ubuntu 20.04?
  • How to install AIDE on Ubuntu 22.04?
  • How to install Anaconda on Ubuntu 20.04?
  • How to install and use Docker on Ubuntu 20.04?
  • How to install and use Elinks on Ubuntu 20.04?
  • How to install and use PostgreSQL on Ubuntu 20.04?
  • How to install Android Studio on Ubuntu 22.04?
  • How to install Angular on Ubuntu 20.04?
  • How to install Ansible on Ubuntu 20.04?
  • How to install Apache Kafka on Ubuntu 20.04?
  • How to install Apache Maven on Ubuntu 20.04?
  • How to install Asterisk on Ubuntu 20.04?
  • How to install Atom Text Editor on Ubuntu 20.04?
  • How to install Blender on Ubuntu?
  • How to install CFEngine3 on Ubuntu 20.04?
  • How to install Code::Blocks on Ubuntu 20.04?
  • How to install Composer on Ubuntu 22.04?
  • How to install Curl on Ubuntu 20.04?
  • How to install Desktop GUI on Ubuntu 20.04?
  • How to install Discord on Ubuntu 22.04?
  • How to install Django on Ubuntu 20.04?
  • How to install Docker Compose on Ubuntu 20.04?
  • How to install ELK on Debian 10 or Debian 11?
  • How to install Fail2ban on Debian 10?
  • How to install FFmpeg on Ubuntu 20.04?
  • How to install Flask on Ubuntu 20.04?
  • How to install Fish Shell in Ubuntu 20.04?
  • How to install Gedit on Ubuntu 20.04?
  • How to install Git on Ubuntu 20.04?
  • How to install Gitea on Ubuntu 20.04?
  • How to install Gitlab on Ubuntu 20.04?
  • How to install Go on Ubuntu 20.04?
  • How to install Google Chrome on Ubuntu 20.04?
  • How to install Gradle on Debian 10?
  • How to install Gradle on Ubuntu 20.04?
  • How to install Grafana on Ubuntu 20.04?
  • How to install Hadoop on Ubuntu 20.04?
  • How to install Homebrew on Linux?
  • How to install JAVA with APT on Ubuntu 20.04?
  • How to install Julia on Ubuntu 20.04?
  • How to install Jupyter on an Ubuntu Linux VM?
  • How to install Kdenlive on Ubuntu 20.04?
  • How to install Logwatch on Ubuntu 20.04?
  • How to install MariaDB on Ubuntu 22.04?
  • How to install Memcached on Debian 10?
  • How to install Microsoft Edge Browser on Ubuntu 22.04?
  • How to install MongoDB on CentOS 7?
  • How to install MongoDB on Linux?
  • How to install Mono on Debian 10?
  • How to Install Mono on Ubuntu 20.04?
  • How to install Mozilla Firefox on Ubuntu 20.04?
  • How to install MySQL on Ubuntu 22.04?
  • How to install Nagios on Ubuntu 20.04?
  • How to install Nginx on CentOS 8?
  • How to install Nginx on Ubuntu 22.04?
  • How to install Node.js on Ubuntu 22.04?
  • How to install NVIDIA CUDA on Ubuntu 20.04?
  • How to install Nvidia Optimus Driver on Ubuntu 22.04?
  • How to install OpenCV on Ubuntu 20.04?
  • How to install Perl on Ubuntu on 22.04?
  • How to install Pacman on Ubuntu 20.04?
  • How to install phpMyAdmin on Ubuntu 20.04?
  • How to install PIP on CentOS 8?
  • How to install Plex media server on Ubuntu 20.04?
  • How to install Podman on Ubuntu 20.04?
  • How to install Poetry on Ubuntu 22.04?
  • How to install Postman on Ubuntu 20.04?
  • How to install ProcessWire on Ubuntu 20.04?
  • How to install PyQuery package on Ubuntu 20.04?
  • How to install Python 3 on Ubuntu 22.04 and set up a programming environment?
  • How to install Python on Windows 10 using UI and Windows command prompt?
  • How to install R on Ubuntu 20.04?
  • How to install Ruby on Rails on Ubuntu 20.04?
  • How to install Ruby on Ubuntu 20.04 and setup programming environment?
  • How to install Rust on Ubuntu 22.04?
  • How to install Samba on Ubuntu 20.04?
  • How to install Skype on Ubuntu 20.04?
  • How to install Rancher on Ubuntu 20.04?
  • How to install Slack on Ubuntu 20.04?
  • How to install Springboot on Ubuntu 20.04?
  • How to install Spyder IDE in Ubuntu?
  • How to install Steam on Ubuntu 20.04?
  • How to install Strapi for Production on Ubuntu 20.04?
  • How to install TeamViewer on Ubuntu 20.04?
  • How to install TensorFlow on Ubuntu 20.04?
  • How to install Apache Web Server on Ubuntu 20.04?
  • How to install the Deno JavaScript Runtime on Ubuntu 20.04?
  • How to install Open LiteSpeed Web Server on Ubuntu 22.04?
  • How to install Sublime Text Editor on Ubuntu 20.04?
  • How to install tix package on Ubuntu 20.04?
  • How to install Vagrant on Ubuntu 20.04?
  • How to install Vim on Ubuntu 20.04?
  • How to install VirtualBox on Ubuntu 20.04?
  • How to install VLC Media Player on Ubuntu 20.04?
  • How to install VMware Workstation Player on Ubuntu 20.04?
  • How to install vscode on Ubuntu 20.04?
  • How to install Webmin on Ubuntu 20.04?
  • How to install Wine on Ubuntu 20.04?
  • How to install WordPress on Ubuntu 20.04?
  • How to install Xibo on Ubuntu 20.04?
  • How to install Zoom on Ubuntu 20.04?
  • How to install Yarn on Ubuntu 20.04?
  • How to keep Ubuntu 22.04 servers updated?
  • How to monitor system authentication logs on Ubuntu 20.04?
  • How to perform basic administration tasks for Storage Devices in Linux?
  • How to set up Jenkins on Ubuntu 20.04?
  • How to setup OpenVPN on Ubuntu 20.04?
  • How to setup time synchronization on Ubuntu 20.04?
  • How to setup a UFW on an Ubuntu or Debian Cloud Server?
  • How to setup SSH keys in Ubuntu 20.04?
  • How to SSH terminal through MobaXterm and PuTTY in Windows?
  • How to Use Ansible to Install and Set Up Docker on Ubuntu 20.04?
  • How to view system users on Ubuntu 20.04?
  • How to make OpenStack accessible through CLI?
  • How to make Block Storage available for Linux?
  • Script for automated incremental backups
  • How to configure a Git repository using Linux CLI?
  • How to enable remote access on MySQL?
  • How to Mount a S3 Bucket on Linux Instance?
  • How to access MySQL database credentials?
  • How to create an incremental backup using CLI?
  • How to set up web-based SQL server on OpenStack instance using SQL image?
Powered by GitBook
On this page
  • Overview
  • Prerequisites
  • Get Started
  • Conclusion

Was this helpful?

How to install Python 3 on Ubuntu 22.04 and set up a programming environment?

PreviousHow to install PyQuery package on Ubuntu 20.04?NextHow to install Python on Windows 10 using UI and Windows command prompt?

Last updated 1 year ago

Was this helpful?

Overview

Python is a programming language that is gaining popularity among both novice and experienced programmers. It is one of the most widely used programming languages in the world. Its syntax is easy to learn, and its flexibility and versatility make it suitable for a wide range of applications, from web development and data analysis to artificial intelligence and scientific computing. Python's extensive libraries and frameworks also make it a popular choice among developers as it allows for rapid development and quick prototyping. Overall, Python's ease of use, powerful features, and large community of developers have contributed to its popularity and continued growth.

This tutorial will help you create a Python 3 programming environment on an Ubuntu 22.04 server.

Prerequisites

There are certain prerequisites that need to be met before you begin.

  • Ubuntu 22.04 LTS configured on your system.

  • Non-root sudo user privileges.

Get Started

Step 1: Configuring Python 3

  • Python 3 is already installed in Ubuntu 22.04 by default. To ensure that you have the latest version, you need to update your local package index:

sudo apt update
  • Next, update the software packages present on your system:

sudo apt -y upgrade

Using the -y flag will indicate your consent to install all items, however, additional prompts may need confirmation during system updates and upgrades, which could vary depending on the Linux version you're using.

  • Check Python 3 version:

python3 -V
  • In order to handle programming packages for Python, we can utilize pip, a tool that can install and oversee the various software packages that we may require for our development endeavors:

sudo apt install -y python3-pip
  • You can now install any python package. Here, we have installed numpy using the syntax: 'pip3 install package_name'

Note: The term "package_name" can represent any Python package or library.

pip3 install numpy
  • Install additional packages and development tools to create a reliable programming environment:

sudo apt install -y build-essential libssl-dev libffi-dev python3-dev

After installing Python, pip, and other necessary tools, you can create a virtual environment to work on your development projects.

Step 2: Creating a Virtual Environment

Virtual environments allow for a segregated area on a server for Python projects, guaranteeing that each project has its own distinct set of dependencies that won't interfere with other projects. By creating a programming environment, you can exercise more authority over Python projects and how different package versions are managed, which is particularly significant when working with external packages. It's possible to establish multiple Python programming environments, with each environment being a folder or directory on the server that is equipped with a few scripts to function as an environment.

Utilize the venv module that comes pre-installed in the standard Python 3 library to set up a programming environment using Python.

  • To install venv, execute the following command:

sudo apt install -y python3-venv
  • Now that you have installed the necessary components, you can setup environments. You can either select the directory where you want to store your Python programming environments or use the mkdir command to make a new directory:

mkdir environments
  • Enter into the directory:

cd environments
  • After navigating to the created directory, generate an environment:

python3 -m venv p_env
  • pyvenv creates a new directory that comprises several elements that can be observed using the "ls" command:

ls p_env

The files displayed in the above output collaborate to create a secure environment for your projects by separating them from other files on your server. This helps in version control and guarantees that each project has access to specific packages it requires.

  • To start using this environment, you must activate it by using the following command:

source p_env/bin/activate

Note: The name of the environment is set as "p_env" in this case and will be added as a prefix to the command prompt. The appearance of the prefix may differ, but the name of your environment should be the first thing you see on your command line.

(p_env) ubuntu@testing-1:~/environments$

The prefix indicates that the currently active environment is "p_env", indicating that any programs created here will utilize only the specific settings and packages of this environment.

Once you have completed these procedures, your virtual environment is prepared for utilization.

Step 3: Testing

After configuring our virtual environment, let's proceed with generating a conventional "Hello, World!" program to check the environment's functionality.

  • Launch a command prompt text editor like nano and initiate the creation of a fresh file.

Note: Here 'file.py' is the name of the file with the extension py. You can set the name of the file as per your requirements:

nano file.py
  • Write out the program in the file:

print("Hello, World!")

To finish with nano, press CTRL + X followed by Y, and then ENTER to save the file and exit the program.

  • Execute the program:

python file.py

Conclusion

You have successfully established a Python 3 programming environment and are now ready to initiate a programming project. Also see .

How to install Python on Windows 10 using UI and Windows Command prompt