Advance

Install Python 3 and Set Up a Programming Environment on Debian 10

Install Python 3 and Set Up a Programming Environment on Debian 10
1
(1)

Python is a programming language that is really general-purpose, flexible, and popular for data science. If your target is to harvest insights from your data and gain a competitive edge, this tool is suitable. The first of its publish is for the year 1991 which was inspired by the name of the British comedy group Monty Python. You would learn how to store and manipulate data and if you are a beginner it is a good idea to continue on this tutorial. Before all, have a look at Linux VPS plans and catch your own.

To let this tutorial work better, please consider the below Prerequisites:

a non-root user with sudo privileges.
To set up, follow our Initial Setup with Debian 10

 

Recommended Article: Tutorial WordPress installation with Nginx in Ubuntu 20.04

Install Python 3 and Set Up a Programming Environment on Debian 10

Let’s walk through the steps of this tutorial to get your Debian 10 server set up with a Python 3 programming environment. Programming on a server has many advantages and supports collaboration across development projects.

 

Step 1: Setting Up Python 3

While the Debian Linux ships with both Python 3 and Python 2 pre-installed, you can ensure that your versions are up-to-date. see the below command to update and upgrade the system to work with the Advanced Packaging Tool:

sudo apt update  sudo apt -y upgrade

To confirm that you are agreeing for all items to be installed, you will use -y flag.

Once the process is complete, you can check the version of Python 3 that is installed in the system by typing:

python3 -V

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:

Output
Python 3.7.3  

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.

sudo apt install -y python3-pip

Python packages can be installed by typing:

pip3 install package_name

Here, package_name can refer to any Python package or library, such as Django for web development or NumPy for scientific computing. So if you would like to install NumPy, you can do so with the command pip3 install numpy.

There are a few more packages and development tools to install to ensure that you have a robust set-up for our programming environment:

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

Once Python is set up, and pip and other tools are installed, you can set up a virtual environment for our development projects.

 

Step 2: Setting Up a Virtual Environment

Virtual 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 you with greater control over your 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 want. 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, you will be using the venv module here, which is part of the standard Python 3 library. Let’s install venv by typing:

sudo apt install -y python3-venv

With this installed, you are ready to create environments. Let’s either choose which directory you would like to put our Python programming environments in, or create a new directory with mkdir, as in:

mkdir environments  cd 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:

python3.7 -m venv my_env

Essentially, pyvenv sets up a new directory that contains a few items which you can view with the ls command:

ls my_env
Output
bin include lib lib64 pyvenv.cfg share  

 

Together, these files work to make sure that your projects are isolated from the broader context of your local machine. 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 18.04 share directory.

To use this environment, you need to activate it. Which you can achieve by typing the following command that calls the activate script:

source my_env/bin/activate

Your command prompt will now be prefixed with the name of your environment, in this case, it is called my_env. Depending on what version of Debian Linux you are running, your prefix may appear somewhat differently. But the name of your environment in parentheses should be the first thing you see on your line:

(my_env) noodi@ubuntu:~/environments$

This prefix lets us know that the environment my_env is currently active, meaning that when you create programs here they will use only this particular environment’s settings and packages.

Note: Within the virtual environment, you can use the command python instead of python3, and pip instead of pip3 if you would prefer. If you use Python 3 on your machine outside of an environment, you will need to use the python3 and pip3 commands exclusively.

After following these steps, your virtual environment is ready to use.

Step 3: Creating a “Hello, World” Program

Now that we have our virtual environment set up, let’s create a traditional “Hello, World!” program. This will let you test your environment. It provides you with the opportunity to become more familiar with Python if we aren’t already.

To do this, you open up a command-line text editor such as nano and create a new file:

(my_env) noodi@ubuntu:~/environments$ nano hello.py

Once the text file opens up in the terminal window you will type out our program:

print("Hello, World!")

Exit nano by typing the CTRL and X keys, and when prompted to save the file press y.

Once you exit out of nano and return to your shell, let’s run the program:

python hello.py

The hello.py program that you just created should cause your terminal to produce the following output:

Output
Hello, World!  

To leave the environment, simply type the command deactivate and you will return to your original directory.

 

Recommended Article: What is Mariadb and how it works

Conclusion

In this article, you have a Python 3 programming environment set up on your Debian 10 Linux server. From now on you can begin the coding project! I case you need to learn this subject on another OS, read more on our article Tutorial Install Python 3.8 on Centos/RHEL 8 Linux AND How to install Python 3 on Ubuntu 20.04. But if you work with windows, this guide could be suitable.

How useful was this post?

Click on a star to rate it!

Average rating 1 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

View More Posts
Tom Veitch
Eldernode Writer
We Are Waiting for your valuable comments and you can be sure that it will be answered in the shortest possible time.

10 thoughts on “Install Python 3 and Set Up a Programming Environment on Debian 10

    1. – If you trace the below path, you will see the installation location.
      Public Python 3 modules must be installed in the system Python 3 modules directory, /usr/lib/python3/dist-packages
      Also,
      Public Python 2 modules must be installed in the system Python 2 modules directory /usr/lib/python2.

    1. You need to go through the below path:
      • To stop a python script just press Ctrl + C .
      • Inside a script with exit() , you can do it.
      • You can do it in an interactive script with just exit.
      • You can use pkill -f name-of-the-python-script.

    1. It provides at least two versions of Python, As Python is an important part of the Debian ecosystem, It also provides additional versions.

Leave a Reply

Your email address will not be published. Required fields are marked *

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way

+8595670151

7 days a week, 24 hours a day