If you want to find the default Python 3 version of any Ubuntu release, you can run the command Show
Alternatively, check the package https://packages.ubuntu.com/search?suite=groovy&keywords=python3 For groovy (Ubuntu 20.10), it's Python 3.8.6: IntroductionThe Python programming language is an increasingly popular choice for both beginners and experienced developers. Flexible and versatile, Python has strengths in scripting, automation, data analysis, machine learning, and back-end development. First published in 1991 with a name inspired by the British comedy group Monty Python, the development team wanted to make Python a language that was fun to use. This tutorial will get your Ubuntu 20.04 server set up with a Python 3 programming environment. Programming on a server has many advantages and supports collaboration across development projects. The general principles of this tutorial will apply to any distribution of Debian Linux. PrerequisitesIn order to complete this tutorial, you should have a non-root user with If you’re not already familiar with a terminal environment, you may find the article An Introduction to the Linux Terminal useful for becoming better oriented with the terminal. With your server and user set up, you are ready to begin. Step 1 — Setting Up Python 3Ubuntu 20.04 and other versions of Debian Linux ship with Python 3 pre-installed. To make sure that our versions are up-to-date, update your local package index:
Then upgrade the packages installed on your system to ensure you have the latest versions:
The Once the process is complete, we can check the version of Python 3 that is installed in the system by typing:
You’ll receive output in the terminal window that will let you know the version number. While this number may vary, the output will be similar to this:
To manage software packages for Python, let’s install pip, a tool that will install and manage programming packages we may want to use in our development projects. You can learn more about modules or packages that you can install with pip by reading How To Import Modules in Python 3.
Python packages can be installed by typing:
Here, There are a few more packages and development tools to install to ensure that we have a robust setup for our programming environment:
Once Python is set up, and pip and other tools are installed, we can set up a virtual environment for our development projects. Step 2 — Setting Up a Virtual EnvironmentVirtual environments enable you to have an isolated space on your server for Python projects, ensuring that each of your projects can have its own set of dependencies that won’t disrupt any of your other projects. Setting up a programming environment provides greater control over Python projects and over how different versions of packages are handled. This is especially important when working with third-party packages. You can set up as many Python programming environments as you would like. Each environment is basically a directory or folder on your server that has a few scripts in it to make it act as an environment. While there are a few ways to achieve a programming environment in Python, we’ll be using the venv module here, which is part of the standard Python 3 library. Let’s install venv by typing:
With this installed, we are ready to create environments. Let’s either choose which directory we would like to put our Python programming environments in, or create a new directory with
Then navigate to the directory where you’ll store your programming environments:
Once you are in the directory where you would like the environments to live, you can create an environment by running the following command:
Essentially,
Together, these files work to make sure that your projects are isolated from the broader
context of your server, so that system files and project files don’t mix. This is good practice for version control and to ensure that each of your projects has access to the particular packages that it needs. Python Wheels, a built-package format for Python that can speed up your software production by reducing the number of times you need to compile, will be in the Ubuntu 20.04 To use this environment, you need to activate it, which you can achieve by typing the following command that calls the activate script:
Your command prompt will now be prefixed with the name of your environment, in this case it is called
This prefix lets us know that the environment Note: Within the virtual environment, you can use the command After following these steps, your virtual environment is ready to use. Step 3 — Creating a “Hello, World” ProgramNow that we have our virtual environment set up, let’s create a traditional “Hello, World!” program. This will let us test our environment and provides us with the opportunity to become more familiar with Python if we aren’t already. To do this, we’ll open up a command line text editor such as
Once the text file opens up in the terminal window we’ll type out our program: hello.py
Save the file and exit Once you exit out of the editor and return to your shell, you can run the program:
The
To leave the environment, type the command ConclusionCongratulations! At this point you have a Python 3 programming environment set up on your Ubuntu Linux server and you can now begin a coding project! If you are using a local machine rather than a server, refer to the tutorial that is relevant to your operating system in our How To Install and Set Up a Local Programming Environment for Python 3 series. With your server ready for software development, you can continue to learn more about coding in Python by reading our free How To Code in Python 3 eBook, or consulting our Python tutorials. Does Ubuntu 20.04 have Python installed?Ubuntu 20.04 ships with both Python 3 and Python 2 pre-installed. To make sure that our versions are up-to-date, let's update and upgrade the system with the apt command to work with Ubuntu's Advanced Packaging Tool: sudo apt update.
Is Python preinstalled on Ubuntu?Running Python in Ubuntu
Python comes preinstalled on almost every Linux system and is available on official distribution repositories as well. If you still don't have Python installed on your computer, you can easily download it using Ubuntu's package manager.
What Python version comes with Ubuntu?Ubuntu 22.04 comes with Python 3.10. 4, which is the most current version as of right now and, impressively, was only released a month ago.
Does Ubuntu have Python by default?By default Ubuntu runs python 2 on its system. Even if you install python 3 on Ubuntu, it will still refer to python 2, whenever you call 'python' command. But sometimes you may need to set python 3 as the default version on Ubuntu, in case you have programs that use latest python features.
|