2

Is it possible to install Jinja2 and create a WSGI web app on a managed server that I can only access with cpanel?

I created a simple CGI Python page and tried with from jinja2 import Template, but I got the error No module named jinja2.

I tried using [this shell][1] to run the command easy_install Jinja2. The shell works, the easy_install runs, but it says can't create or remove files in install directory (as expected).

As for WSGI I don't even know where to start. Any reference to the installation and configuration that I found would only work on my own server, not on a managed one.

stenci
  • 7,245
  • 11
  • 54
  • 89

1 Answers1

0

Here is what I found out after some research.

It is impossible to install anything that interferes with Apache on a managed server. For example it is impossible to install Mod_python or CherryPy because it requires modifying the configuration of Apache.

It is also impossible to install Python packages like Jinja using pip or easy_install.

But it is possible to install Jinja by copying the source files in any folder the user has access to and tell Python to import from that folder.

Installing with pip or easy_install would take care of the dependencies, manually copying the files doesn't. So all the dependencies must be manually copied as well.

The last problem that I found was that Jinja requires the module pkg_resources, which is installed with easy_install, which can't be used (see above). The solution was to create a custom loader. I copied the one from the documentation that worked well.

Here are the steps that I followed:

  1. Create a folder called lib
  2. Download Jinja and copy it in the lib/jinja2 folder
  3. Download MarkupSafe and copy it in the lib/markupsafe folder
  4. Add the lib folder to the import path: sys.path.insert(0, "lib")
  5. Import Jinja as usual: import jinja2
  6. Create a custom loader as suggested here

Then I password protected the lib folder with cPanel and installed Peewee and other packages.

I would really like to use CherryPy, but for my little low traffic this will do.

Community
  • 1
  • 1
stenci
  • 7,245
  • 11
  • 54
  • 89
  • 1
    This is why you don't use cheap web hosting services setup only to handle PHP sites. You should consider looking at the free tiers of services such as Heroku or OpenShift. – Graham Dumpleton Aug 19 '14 at 06:54
  • @GrahamDumpleton I agree. It was written every were "don't do it, that's only good for PHP, ..." but I had to learn the hard way. Now that I spent enough hours in this useless crusade I will start exploring other options. I already tried with GAE, Heroku will come soon. – stenci Aug 19 '14 at 15:11