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.
Related
I was hoping for some advice.
My company has python version 3.5 IDLE.
My company is NOT a software company, i have started using it to automate some of my tasks.
The issue is that modules such as pandas or numpy is not installed and these modules will never be installed (no specific reason was given).
However i have discovered that .py files that are not installed or party of the standard library can be included using the following code:-
import sys
sys.path.append("C:\Users\Joe\Test")
Test is a folder that contains various .py files.
I have pandas installed on my personal computer so I wanted to copy the pandas.py file from my personal computer into my work computer and put it in the Test folder shown above but i cannot seem to find pandas.py or numpy.py
My work computer is heavily restricted, i cannot access the c drive hence why i am trying to find an alternative method.
Any ideas?
Thank you.
I saw youtube video https://www.youtube.com/watch?v=CqvZ3vGoGs0&t=638s
I was trying to do interfacing between GoLang & Python. I have been a long time fan of Python and love using it. But Over Time I have udnerstood it is really bad for doing computations etc. Especially when there may be large data sets involved.
I have started learning golang mainly because of its speed, and was thinking of using it in my Application as a library. Writing Intensive Code in GoLang and then use methods in the libraries in Python for writing Beautiful High Level Application code in Python.
After doing the first prototype I deployed my code in GAE.
Unfortunately I hit this
from ctypes import *
File "/base/alloc/tmpfs/dynamic_runtimes/python27g/7679791231c143f9/python27/python27_dist/lib/python2.7/ctypes/__init__.py", line 7,
in <module> from _ctypes import Union, Structure, Array
ImportError: No module named _ctypes
I have read that GAE doesnt support ctypes out of the box for Python Instances. But is there a way I can circumvent this and use my Go Binaries and use them on GAE?
I followed this for my implementation and interfacing Go with Python https://medium.com/learning-the-go-programming-language/calling-go-functions-from-other-languages-4c7d8bcc69bf
You didn't specify, but I'm guessing you're using the Python 2.7 runtime, which is heavily sandboxed. Using the Python 3.7 runtime (which is more idiomatic) should allow you to use ctypes.
I'm developing a C++ library, which has python embedded. What I would like to do is to statically link Python library, so that there won't be configuration issues, when I switch to production server. So far, I'm able to link libpython3.5m.a statically (I had to build Python from sources though, because it seems, that packaged libraries aren't compiled with -fPIC flag). However, I came to a problem, that it seems, there's no Numpy: When I run application, which uses my library, it prompts me with an error:
ImportError: numpy.core.multiarray failed to import
And this error is caused by import_array1() macro, that (AFAIK) is used to import the numpy routines to C++. I tried linking libnpymath.a as well as libnpysort.a, which I found in numpy build dir, but to no avail. Do you happen to know, if such static linking is possible and how to do it? I guess it should be possible, since numpy is written in C...
What I would like to do is to statically link Python library, so that there won't be configuration issues, when I switch to production server.
This would only be the Python core, it would exclude all of the Python libraries. You still need to ship all of the Python code.
...since numpy is written in C...
This is incorrect. NumPy is written about half in C and half in Python. It looks like the C part is the part that's not loading here, since numpy.core.multiarray is written in C, and you wouldn't normally import that yourself, it would normally be imported by the Python part of NumPy.
Linking in the C code is not enough anyway, you need to load initialize the associated Python modules exported by the C code. Without static linking, Python would just find the multiarray.so file in the right place and load it. When you build Python statically, you would would normally edit the Modules/Setup.local file with the modules you want statically compiled into Python. However, this is not designed to work with arbitrary third-party modules like NumPy. See: Compile the Python interpreter statically?
Honestly, if you are just trying to make sure that the same version of Python runs on both development and production systems, there are vastly easier ways to do this, like virtualenv. CPython is simply not designed to be statically linked.
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.
I'm testing different languages to developp a desktop application for Mac&Windows.
I thought that Python+Wx worth a try so I wrote a simple hello world.
Then, I tried the py2app to package my application as a Mac application.
What a surprise to find that my hellworld.app weight as much as 75 MB !! (then I have an error at runtime but that's not the question)
Here is my question : is there a way to distribute a standalone wxPython application that weight less than a few MB ? (for instance, an adress book app).
(a Swing HelloWorld is around 3KB, plus around 20MB for the JRE)
Thank you
I would highly remmoend you using PyINstaller, which can be found here: link
it works like a chamr for me so far and it support most of the major libraries:
wxpython pyqt and even django (although i dont really understand the whole django support thing ;-) )
PyInstaller is a program that converts (packages) Python programs into stand-alone executables, under Windows, Linux, and Mac OS X. Its main advantages over similar tools are that PyInstaller works with any version of Python since 2.2, it builds smaller executables thanks to transparent compression, it is fully multi-platform, and use the OS support to load the dynamic libraries, thus ensuring full compatibility.
The main goal of PyInstaller is to be compatible with 3rd-party packages out-of-the-box. This means that, with PyInstaller, all the required tricks to make external packages work are already integrated within PyInstaller itself so that there is no user intervention required. You'll never be required to look for tricks in wikis and apply custom modification to your files or your setup scripts. As an example, libraries like PyQt, Django or matplotlib are fully supported, without having to handle plugins or external data files manually. Check our compatibility list of SupportedPackages.
i hope this helps, good luck and tell if you need anymore help