Difference between revisions of "WebArea/Compat/Python"

From TuxFamilyFAQ
Jump to navigationJump to search
(Start writing "Dealing with CGI".)
m (→‎Dealing with CGI: Formatting.)
Line 49: Line 49:
 
To make your Python application run on TuxFamily, you have to be 100% aware of what CGI is and how it differs from FastCGI, WSGI and other variants. You also need to take into account that TuxFamily runs Apache with suphp (which handles more than just .php files).
 
To make your Python application run on TuxFamily, you have to be 100% aware of what CGI is and how it differs from FastCGI, WSGI and other variants. You also need to take into account that TuxFamily runs Apache with suphp (which handles more than just .php files).
 
For instance, assuming you want to set up Trac, the following resources should make sense to you:
 
For instance, assuming you want to set up Trac, the following resources should make sense to you:
* https://faq.tuxfamily.org/WebArea/En#How_to_play_with_types_and_handlers
+
* https://faq.tuxfamily.org/WebArea/En#How_to_play_with_types_and_handlers
* https://trac.edgewall.org/wiki/TracCgi
+
* https://trac.edgewall.org/wiki/TracCgi
* https://trac.edgewall.org/wiki/ApacheSuexec
+
* https://trac.edgewall.org/wiki/ApacheSuexec

Revision as of 10:53, 14 July 2018

Python on TuxFamily

TuxFamily enables you to run Python applications, but not exactly the way you would expect it. Since TuxFamily does not provide VPS (Virtual Private Servers), you cannot set up your own Python-based, HTTP-or-FastCGI listening daemon as described by 99% of Python-related howtos. Instead, TuxFamily is a heavily mutualised hoster that leverages CGI to run almost anything.

Creating your own virtualenv

If asked nicely, the TuxFamily team can install Python packages as provided by Debian stable or oldstable; however, these packages may be too old for your brand new Python application and in most cases, you will choose to spawn your own virtualenv. The trade-off is rather simple: Debian packages are older than what is available through pip, but they benefit from Debian's security upgrades, which are regularly applied by the TuxFamily team. Whatever will be pulled by pip into your virtualenv is under your responsibility.

There are various ways you can create your own virtualenv.

Variant #1: using virtualenv directly

# Leverage the "php-include" directory; despite its name, it is the best
# location for what you need to do:
cd ~/project/webarea.tuxfamily.org-web/php-include

# Invoke virtualenv directly:
virtualenv env
source venv/bin/activate

# Ensure "activate" worked properly:
env | grep venv
which pip

# Do whatever you want: install modules, read a requirements file, etc.
pip install requests

Variant #2: using only pip

# Leverage the "php-include" directory; despite its name, it is the best
# location for what you need to do:
cd ~/project/webarea.tuxfamily.org-web/php-include

# Leverage the target option to get your own virtualenv module:
mkdir python-stuff
pip install --target=python-stuff virtualenv

# You can now create a virtualenv and activate it:
PYTHONPATH=$(readlink -f python-stuff) python -m virtualenv venv
source venv/bin/activate

# Ensure "activate" worked properly:
env | grep venv
which pip

# Do whatever you want: install modules, read a requirements file, etc.
pip install requests

Dealing with CGI

To make your Python application run on TuxFamily, you have to be 100% aware of what CGI is and how it differs from FastCGI, WSGI and other variants. You also need to take into account that TuxFamily runs Apache with suphp (which handles more than just .php files). For instance, assuming you want to set up Trac, the following resources should make sense to you: