Nossa base de conhecimento está disponível apenas em inglês atualmente. Estamos em processo de tradução destas páginas e vamos publicá-las assim que estiverem disponíveis.
Base de Conhecimento
Using the Python Selector in cPanel
This article describes how to use the Python Selector in cPanel to create a Python application that uses a specific Python version. Additionally, you can use a virtual environment to develop the application further.
Using the Python Selector
To create a new Python application that uses a specific Python version, follow these steps:
- Log in to cPanel.
If you do not know how to log in to your cPanel account, please see this article
- In the SOFTWARE section of the cPanel home screen, click Setup Python App:
Click CREATE APPLICATION:
The application form appears:
- In the Python version list box, select the Python version you want to use.
- In the Application root text box, type the directory where the application files are located.
- In the Application URL list box, select the domain, and then type a URL for the application.
In the Application startup file text box, you can optionally specify the startup file for the application.
If you do not specify a startup file, cPanel creates a passenger_wsgi.py startup file for you.
In the Application Entry point text box, you can optionally specify the callable object for the application.
If you do not specify the application entry point, cPanel creates a default application object for you.
- In the Passenger log file text box, you can optionally specify a log file for the application.
- Under Environment variables, you can optionally set environment variables for the application. To do this, click , type the variable name and value, and then click .
In the top right corner of the page, click CREATE:
cPanel creates the application and sets up the Python environment.
To work inside the newly created environment, connect to your account using SSH, and then type the following command. Replace username, application, and version with the actual values as shown at the top of the page, next to Enter to the virtual environment. To enter to virtual environment, run the command:
source /home/username/virtualenv/application/version/bin/activate && cd /home/username/application
You can now install modules or use other commands to develop the Python application further. Additionally, you can control the application's running state from cPanel:
- To stop the application, click
- To restart the application, click
- To completely remove the application from cPanel, click
- Activating a Python virtual environment from a script file
There are scenarios where you may need to activate and use a Python virtual environment within a script file, and this article shows you how.
- Connecting to MySQL using Python
There are several ways you can connect to a MySQL database using Python, and this article shows you how.
- Python script basics
What is the path to the Python executable? What are the correct file permissions for my Python scripts? What versions of Python are installed? Get the answers to these essential questions and more here.