Python is a high-level object-oriented programming language. It is used for back-end and software development, data science, writing system scripts (automation), and not only.
Python is powerful, fast, friendly, and easy to learn. It is also known for its simplicity and readability. Python is used for a wide range of purposes, including data analysis, machine learning, software development, scientific computing, text processing, natural Language Processing (NLP), and many more.
Python's extensive standard library and a vast ecosystem of third-party libraries and packages make it a versatile choice for a wide range of programming tasks, making it one of the most popular programming languages in the world.
This tutorial will cover the “Setup Python App” functionality in cPanel and how you can use it to deploy virtual environments for your Python applications.
To use the Python App Selector you should have logged into your cPanel account. For your convenience, we provide you with a direct link to the How to access the cPanel service.
Please use the “Search Tools” bar at the top right corner and type in "Setup Python App." Doing so will filter all options and display the functionality under the “Software” category. Please click on it to open the feature. Alternatively, through the main cPanel page, you can find the "Setup Python App" feature under the "Software" category group.
Please click on the "Setup Python App" feature, and you will be redirected to a new page. Here, you can view a list of existing Python applications for your personal account or create a brand-new one.
If no Python web applications have been created yet, you will see the “NO APPLICATIONS FOUNDS” message in the middle of the screen. To create a new one, please click on the “CREATE APPLICATION” button at the top right side of the page.
This action will then redirect you to a new page where you can configure your new Python application. To create a new Python application, you must fill out the settings for your Python application.
Let’s explain the use of these configurations:
Once ready, please select the “CREATE” button in the top right corner to finalize the process.
Once the application is created, the page will refresh, and at the top of the page, you will be provided with a command that can be used to access the virtual environment on the Terminal via SSH.
What is a Virtual Environment, and why do you need to access it?
Every cPanel Web Hosting Account exists as an encapsulated entity on the Web Hosting server. As such, every cPanel Web Hosting Account has access to global services like SSH, MySQL, email, and so on by using its binaries. In other words, the server's binaries are globally accessible by every user account. Python is also a binary called "python".
As such, there can only be one binary with that name. However, as we have mentioned, you might need multiple Python versions, which the single "python" binary cannot provide. In fact, the "python" binary can only support one Python version - the one that is globally available on the server.
Knowing this, we have found a way to provide support for multiple Python versions using the same "python" binary. This is achieved thanks to the Virtual Environment feature. A Virtual Environment is a method of encapsulation, however, not on the user account level but on an application level. This means that cPanel will create a new virtual environment for every Python application you create.
Within every Virtual Environment, cPanel will provide you with a separate "python" binary, meaning that every Virtual Environment utilizes the chosen "python" binary version. Additionally, every virtual environment utilizes different environment variables that you can set.
Typically, to access the binaries of the Web Hosting Server, you will have to log in via the SSH protocol. Accessing the Virtual Environment is no different - you will still have to be logged via the SSH protocol, and you will have to execute a command in order to access the Virtual Environment for the concrete Python application you are managing. The command is different for each Node.js application, and you can obtain it via the application screen in the "Setup Python App" feature of cPanel.
If you are not familiar with how to use SSH to connect your account with HostArmada via Terminal, please take a look at our tutorials:
How to Manage the SSH access keys for your cPanel web hosting account
How to use SSH keys to connect to your hosting account on Linux and MacOS
How to use SSH keys to connect to your hosting account on Windows 10
Once you enter the virtual environment, you can proceed with further configuration of the application by using the pip command (pip is a package-management system written in Python and is used to install and manage software packages in Python programming language).
The screenshot above shows how to enter the newly created virtual environment and the pip command's "help" and "list" parameters.
Naturally, the “Setup Python App” functionality will not only allow you to deploy Python apps but also enable you to manage them. This is done by setting up actions that are available within the interface itself.
Let’s go over them one by one.
You can use your existing Python applications' “Stop,” “Restart,” “Edit,” and “Delete” functionalities through the familiar "Setup Python App" interface under the “Software” section in cPanel.
The aforementioned options are incredibly intuitive and straightforward to use.
The current status of your application can be found under the “Status” section in the “Web Applications” table section, which includes all your existing Python app installations.
Please press the “Play” button under the “Actions” column to start a stopped application and vice versa.
If you want to restart your Python application, please press the “Back twisted arrow” icon under the “Actions” column.
Please note the “Restart” option is not available for stopped applications, and your Python application can only be restarted if it is in “started” status.
This section can be accessed via the “Pencil” icon under the “Actions” column. An additional “Configuration files” section will appear with already configured virtual environments, and you can execute the pip install command. Alternatively, you can do so through the Terminal window as described above. You can also add the file from this section with “Environmental variables” (in case one is available).
When you finish editing your application, please press the “SAVE” button at the top right corner. All changes will be automatically applied.
This is a really straightforward process, and, as the name suggests, it will delete the application. Please click on the “Trash bin” icon under the “Actions” column to permanently delete the installation from the corresponding Python application. Please remember to completely delete an application only through this interface instead of manually through the installation directory.
The Python virtual environment is also related to other root folders in the home directory of your account, and removing files manually can damage the virtual environment and affect the following use of the same domain.
That's it. Configuring and using a Python virtual environment through cPanel is not complicated. However, don't forget that our support team is always at your disposal, and you can open a support ticket with us through your account so that we can attempt to assist you if you encounter any difficulties.
Nikola is an accomplished tech-savvy extraordinaire with over six years of experience in the web hosting field. He started as a customer care representative and quickly rose the ranks to become a support supervisor and, eventually - the head of the technical department in HostArmada. His deep understanding of the client's needs, combined with his technical knowledge, makes him the perfect man to create the ideal harmony between client satisfaction and professional problem-solving. You will often find him creating helpful tutorials, articles, and blog posts that help existing customers get around.