Library not supported - python

I am writing my first app using Python, DJANGO, and the Google Appengine. The basic flow is the user enters data into the db and the creates a report form that gets exported as a PDF.. I have all of it working except the last piece and I am having an issue that I can't find anything on. I have the latest version of the Appengine Launcher, Python 2.7, DJANGO 1.4 and XHTML2PDF 0.0.4. I have it bundled with my application but when I launch my application i get an error on the page and in the log that says:
Fatal error when loading application configuration:
Invalid object:
the library "xhtml2pdf" is not supported
in "/Users/username/project/app.yaml", line 31, column 1
Is there something additional that I need to do or configure or is the a version issue?
Thanks for any help you can give a newbie,

What does line 31 of your app.yaml say?
xhtml2pdf isn't in the list of third-party libraries that App Engine 2.7 supports. (These are libraries that include C extensions, which require extra scrutiny to support. Pure Python libraries are typically O.K.)

The easiest way to include xhtml2pdf is to drag and drop the xhtml2pdf src folder into the main directory and
from xhtml2pdf import pisa
You also need reportlab, drag and drop works for it too. I had to use a modified version of it from http://ruudhelderman.appspot.com/testpdf but other's have gotten the non-modified version to work.

The xhtml2pdf library is not included in the app engine run time. You can include it yourself, though. The python27 runtime supports the lxml library, which html5lib requires (which is required by xhtml2pdf). However, there is a much simpler solution: use the conversion api, which supports HTML -> PDF conversion, and will be much easier to use.

Related

Google Translate not working with Buildozer for android kivy app

Essentially I had to import not only the libraries I use, but also the dependencies inside those libraries. httpcore is a dependency used by Google Translate library.
logcat before app crashes:
module 'httpcore' has no attribute 'SyncHTTPTransport'
At first I thought it was an issue with the version of httpcore, but specifying the version that gets downloaded normally with a pycharm terminal doesn't work either. Essentially code in Google Translate crashes when using httpcore because a specific httpcore function doesn't exist which Google Translate is using...
Why is this happening? I can't even get the libraries I download to work now either.
Edit: Based on Reddit Commenter, seems like I need to add what's called "recipes" which is a template of code added inside the python code.
Seems to be templates you need to add inside the python code: https://python-for-android.readthedocs.io/en/latest/recipes/
YouTuber NeuralNine seems to have a detailed tutorial for this, I've seen other stuff he's done and he's good. I'll give it a go after work: https://www.youtube.com/watch?v=6gNpSuE01qE

Do you need python to run a python gtk/pyQt application?

I am considering porting what is a small application from a JavaScript bookmarklet for work to a python GTK application. However, while people can run my bookmarklet on either Chrome or Firefox, I don't want to proceed to use Python GTK or PyQT if they need to have python installed. Is there a way to distribute the application with requisite files to avoid needing everyone to install Python on their workstations?
If there are other solutions which offer ability to send async http requests with competent libraries for html dom traversing/parsing (not c#/HAP), I am willing to compromise.
Also take a look at PyInstaller. The support for python3 is still experimental, but I have never had any problems so far. I prefer it over py2exe and py2app because of its ease of use.
You should have a look on py2exe or py2app, which can build python applications that contain all needed libraries.

Including pygame in google app engine

I'm trying to include a PyGame library in my Google App Engine aplication:
> import pygame
But I've got an import error:
> from pygame.base import *
ImportError: No module named base
How can I import it?
You can't. GAE has a very restrictive set of libraries you can use. Here's a list:
https://developers.google.com/appengine/docs/python/tools/libraries27
A bit of clarification: Joe's link is a list of 3rd party libraries that Google already has installed and available for you to use, but that's probably not why pygame doesn't work for you. For example, I use SendGrid and Flask in most of my App Engine projects and they works perfectly fine despite not being on that list (I just have to include them manually in every project I add)
As for pygame:
Libraries that rely on ctags or hook into other C libraries, are incompatible with how GAE does their thing. It's quite possible that some portion of pygame relies on third-party libraries (perhaps modules that load sound files that might use C libraries for playback). This will block pygame from being imported properly.
(update: Another post about a user having trouble running pygame on their Mac shows that pycame requires a library called pyobjc which very likely is not compatible with how GAE works, per my notes above)
I ran into this myself with a heavy math-related python package of which I only needed a small portion. It relies on a C library for maintaining precision with heavy variable typing. I ended up rewriting the small portions in pure Python using lots of int() and float() calls, and it worked perfectly.

how to import a python package to GAE

Sorry if it is a stupid question.
Normally when I need a package, I import filename.py.
How is about this https://github.com/simplegeo/python-oauth2 ? How can I import this package since I cannot find oauth2.py file.
Do I copy this oauth2 folder to project root and then do import oauth2?
I am just a beginner so can you give me detail instruction?
Thanks for your time
Read this first.
Now if you check out oauth2/__init__.py, you will see oauth already do import httplib2 so you don't have to import it yourself. (Unless you also are using httplib2, of course.)
In essence, you are correct. If you want to use a python package in a GAE app you have to have a copy of it it in the applications root directory where it can be accessed by your application as a normal import. It will then be uploaded along with your applications code and be usable when deployed too.
There are exceptions where you don't have to do this as the library is provided for you, you can read about those here: Supported 3rd Party Libraries
For those you need to edit your app.yaml.
For oauth2 you should look at google specific implementations. I don't know what you've linked to there, all I know is the endless stream of oauth/gae questions usually end up here: https://developers.google.com/appengine/docs/python/oauth/overview

Distributing a Python library (single file)

For my project I would be using the argparse library. My question is, how do I distribute it with my project. I am asking this because of the technicalities and legalities involved.
Do I just:
Put the argparse.py file along with
my project. That is, in the tar file for my project.
Create a package for it for my
distro?
Tell the user to install it himself?
What's your target Python version? It appears that argparse is included from version 2.7.
If you're building a small library with minimal dependencies, I would consider removing the dependency on an external module and only use facilities offered by the standard Python library. You can access command line parameters with sys.argv and parse them yourself, it's usually not that hard to do. Your users will definitely appreciate not having to install yet another third party module just to use your code.
It would be best for the user to install it so that only one copy is present on the system and so that it can be updated if there are any issues, but including it with your project is a viable option if you abide by all requirements specified in the license.
Try to import it from the public location, and if that fails then resort to using the included module.
You could go with Ignacio's suggestion.
But... For what it is worth, there's another library for argument parsing built into Python, which is quite powerful. Have you tried optparse? It belongs to the base Python distribution and has been there for a while...
Good luck!

Categories