سؤال

I am unable to import reportlab properly under google app engine. According to the following guide (and several other places on the web):

"All you have to do is download it and copy the 'reportab' directory into the root directory of your app. "

When I do so (I download the reportlab-3.0.zip from here) and extract it into the root directory of my application, as I try to import reportlab using following lines:

from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import A4

I get an import error

ImportError: No module named reportlab.pdfgen

I tried googling but to no avail. Any help on this would be greatly appreciated as I am not sure what else I could try. Many thanks!


One other thing I tried was copying what's in the src directory of the downloaded zip under the root directory of my application but that didn't work either. The error I get using this is:

ImportError: Cannot re-init internal module __main__

Seems version 2.7 imports okay, only issues with 3.0

هل كانت مفيدة؟

المحلول

If you just unzip the reportlab zip in your root directory of your application, then it won't work, as the reportlab zip is intended for a local setup using setup.py, which you don't use in appengine.

You should look inside the zip to the src directory and inside that is a reportlab directory - in my case the zip file contents will be reportlab-3.0/src/reportlab copy/move this reportlab directory to the root level of your application.

You should probably also read up on how import and modules work oin python. If you where familiar with this you could work it out for yourself looking at the structure of the zip contents.

ALso pay attention to the prerequesites if you want to work with images. If you do you will need to install PIL locally, and enable it in app.yaml however you don't deploy the PIL code. You can read more about this in the appengine 3rd part libraries docs.

نصائح أخرى

Checking the destination path of reportlab installation after the command pip install reportlab and then make a link to reportlab at the root of the python project ln -s /usr/lib/python2.7/dist-packages/reportlab

You need to move to the lib's parent directory. Then you can install reportlab using this command:

pip install -t lib reportlab
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top