Skip to content

Python

  • Python * is a high-level programming language. On Serv00.com servers it is possible to run pages and applications based on this language.

Versions available

The default version of * Python * on Serv00.com servers is version 3.8 - invoking the commandpython will start the interactive language interpreter in this version. In addition, the following commands are also available: python2.7,python3.6, python3.7,python3.8, python3.9 andpython3.10 to run the given version of * Python *.

Virtualenv

Virtualenv is a tool for creating isolated * Python * environments. Using Virtualenv solves the basic problem with different versions of additional language libraries and permissions - virtual environments are created entirely in the user's home directory, which (together with the tools provided byvirtualenv as standard) allows full, independent management of installed modules .

Before installation, please enable the use of your own software - Binexec.

Information

In this tutorial, the / usr / home / LOGIN / .virtualenvs directory has been created and used to collect all user-createdvirtual environments. A new directory can be created with the command mkdir / usr / home / LOGIN / .virtualenvs.

Creating a virtual environment

A virtual environment can be created by running the command virtualenv in a selected directory, specifyingenvironment name as a parameter:

$ cd /usr/home/LOGIN/.virtualenvs
$ virtualenv environment_name
New python executable in envname / bin / python3.8
Also creating executable in enviroment / bin / python
Installing setuptools, pip ... done.

Such command invocation creates a new virtual environment using thesystem default python version. You can use the -p flag to indicateother executable, which consequently creates a virtual environment using a different version of * Python *:

$ cd /usr/home/LOGIN/.virtualenvs
$ virtualenv environment_name -p /usr/local/bin/python2.7
Running virtualenv with interpreter /usr/local/bin/python2.7
Using base prefix '/ usr / local'
New python executable in envname / bin / python2.7
Also creating executable in enviroment / bin / python
Installing setuptools, pip ... done.

Activating the virtual environment

To run the script with the interpreter, it is enough to specify the path to the new executable python (/ usr / home / LOGIN / .virtualenvs / environment_name / bin / python), however to facilitate the use of virtualenv, thescript bin / activate, the loading of which will modify the user environment in such a way as to facilitate the use of the new environment.

$ source /usr/home/LOGIN/.virtualenvs/ environment_name/bin/activate
(environment_name) $
After loading the activation script, you can see that your prompt has changed. At the beginning, the name of the virtual environment in which the user is currently located is given. In this state, it is not necessary to enter the full path to the interpreter, the commands python,pip and easy_install will be executed using the currently selected virtual environment.

You can leave a given environment by issuing the command deactivate.

Website

When adding a WWW page python type, you must specify the executable/ usr / home / LOGIN / .virtualenvs / environment_name / bin / python so that the virtualenv environment is used to support the page.

Troubleshooting

Some packages installed with the pip command require additional variables for the compilation to be successful. Before running pip install package, do:

export CFLAGS = "- I / usr / local / include"
export CXXFLAGS = "- I / usr / local / include"
Some packages are compiled only under GCC, so to select it, execute the following commands:

export CC = gcc
export CXX = g ++

Another available version of GCC may also be indicated.

If you exceed the limit of system processes when installing packages using pip, you should issue the following commands:

export MAX_CONCURRENCY = 1
export CPUCOUNT = 1
export MAKEFLAGS = "- j1"

And try the installation again.

Restart the application

Restart of the Python application can be done using our service management panel in the [WWW] tab (/ Strona_WWW/), or using the command Devil account management system:` devil www DOMAIN restart.

Process limit for Phusion Passenger

Possibility to set the number of processes for python pages. Command syntax: devil www options DOMAIN processes <Quantity>

Where: - * DOMAIN * stands for the python type WWW domain - * QUANTITY * - number of processes in the range from 1 to 80% of system processes of the hosting account

The option is also available in the DevilWEB panel: WWW pagesDetailsProcess limit ➡ enter a new value and save the changes with theSave changes button.

Static files

All files under /usr/home/LOGIN/domains/DOMAIN/public_python/public are handled as static files. It is best to put all pictures, scripts, styles, etc. in this directory. Requests to files in this directory will not be processed by Python processes and will not burden the interpreter. For example, the file /usr/home/LOGIN/domains/DOMAIN/public_python/public/robots.txt will be available at http://DOMAIN/robots.txt.

Variables

Setting a variable from the SSH level with visibility for the application launched by Passenger is possible by adding variables to the ~/.bash_profile file (e.g. export TESTENV = 1).

Warning

Variables will not be used from ~/.bashrc or ~/.shrc files

Logs

Warning

Do not delete the logs directory, it may cause problems with Node.js, Ruby, Python pages.

The error logs are saved to the error.log file in the /usr/home/LOGIN/domains/DOMAIN/logs/ directory.

App lifetime

If there are no requests to the site for 24 hours, the application is automatically shut down and started again automatically on the first next visit. In the event of a change in the website configuration, the application is also automatically shut down and launched the next time the website is accessed for the first time.

External references