Im making a webpage through google app engine that querys based on the person needs from an existing SQL database located on a local server. Im having trouble importing third party python libraries because most of them are not written in native python code (google app engine only supports fully python code). I have searched everywere for a way to connect to this database but I cant find a way around this issue.
You can use the MySQLdb library, which is a built-in library for App Engine. See the set up instructions in the docs for details.
Specify the MySQLdb library in the app.yaml libraries element:
libraries:
- name: MySQLdb
version: "latest"
What #BrettJ said, some of the common third-party libs for python are not pure python, and thus cannot be imported into the project unless google whitelists them end enables them to be imported in a safe manner, basically, what you need to do is to have MySQLdb library set in the app.yaml file.
libraries:
- name: MySQLdb
version: "latest"
I highly suggest you go through several tutorials, this is basic stuff and will be cleared to you in minimum time.
Related
I am new to Google Cloud Platform and in my whole I have been working on Python 3. I am trying to find out which version of Python is more complete for Google App Engine: Python 2.7 or Python 3.
As I'm starting to work with Google App Engine I have realised that continuing using Python 3 seems too painful as basic tools like dev_appserver.py are written for Python 2 only. Now I am hitting the opposite problem: cloudstorage module seems to exist only for python3. Again, when I install it, seems the only way I can test read/write to google bucket locally is by authenticating with google.appengine.ext, which in turn only works within dev_appserver.py or remotely. This leaves me confused which environment to chose.
What is a general agreement / what is the focus of Google App Engine: Python 2 or Python 3?
In App Engine, you have to options: the Standard environment and the Flexible environment.
Python 2.7 is available in both Standard and Flexible, while Python 3.6 is only available in Flexible.
Also, the choice between Standard and Flexible depends on what you want to do/what libraries you need:
There are some third-party libraries already built-in in the Standard Environment, and you can include other libraries, but, those libraries can't include C extensions, they must be written in pure Python. If you need libraries with C extensions, you will have to move to Flexible.
In Standard, you can use propietary libraries (like google.appengine.ext, as you mentioned) to do tasks like accessing databases, while in Flexible you can use other libraries (like the client you mentioned).
There are also another important differences, like pricing, scaling, etc. The choice will depend, as I said, in your needs for your application.
EDIT
dev_appserver.py is only used when developing in Standard. There is a tutorial in here, with Flask. If you are in Flexible, you can test the app locally as if you were running as usual a python file, like in this other example.
You can use buckets in both Standard and Flexible
The python3-only cloudstorage support assumption based on the SO post you referenced is not correct:
the import appears to be done in a regular python shell or as a standalone script, not from a standard environment GAE app - different things, see import cloudstorage, ImportError: No module named google.appengine.api.
it is not specified where that library comes from
GCS is definitely supported in the standard env GAE (i.e. on python 2), you just need to follow the steps from the official documentation: Setting Up Google Cloud Storage and Reading and Writing to Google Cloud Storage.
Both were good. But the question is what kind of environment do you want? Standard environment or Flexible environment.
Find your answer in this document: https://cloud.google.com/appengine/docs/python/
It kind of depends on what you're using it for. If you're doing data science, for example, I'm seeing a few notices of Python libraries that are (finally) dropping support for Python 2. numpy is one that is dropping support.
Generally speaking, I would recommend Python 3 over Python 2. Why spend time developing in an aging version when its replacement has matured nicely and is more consistent?
I'm trying to transfer an Openshift-hosted Django website to Google App Engine. I wanted to connect it to an existing PostgreSQL database. However, I found this in Google's documentation:
A small percentage of native C python modules, and subsets of native C python modules are not available with Google App Engine. The disabled modules fall in to the following categories: (...)
Please keep in mind that third party packages which use any of the above features will not function with Google App Engine (packages such as PostgreSQL, etc).
My local GAE server produced the following error:
ImproperlyConfigured: Error loading psycopg2 module: No module named psycopg2._psycopg
Further research seems to indicate that this error was raised due to the limitations of GAE, rather than due to a configuration error. Surely there must be some reasonable way to connect my Django website with the externally hosted PostgreSQL server. What are my options?
Edit: so to clarify, I think I need a pure-Python replacement for psycopg2 that works with Django. In other words, it should also implement a Django database backend I can use.
You might be able to use pg8000.
I am deploying a Django app on Google App Engine, but I get an error when importing django-widget-tweaks:
appcfg.py: error: Error parsing ./app.yaml: the library "django-widget-tweaks" is not supported
Is there any way to fix this, apart from not using the library?
You can install third-party libraries yourself. Since this is not one of the runtime-provided third-party libraries you have to fulfill the following criteria:
The library must be implemented as pure Python code (no C extensions).
The code is uploaded to App Engine with your application code, and
counts toward file quotas.
Use pip to install the library and the
vendor module to enable importing packages from the third-party
library directory
From what I can tell the module you want to use is fully implemented in Python, so this should be straight forward. Consult the docs on vendoring for more information on how to do this.
I have a written a very small web-based survey using cgi with python(This is my first web app. ).The questions are extracted from a MySQL database table and the results are supposed to be saved in the same database. I have created the database along with its table locally. My app works fine on my local computer(localhost). To create db,table and other transaction with the MySQL i had to do import MySQLdb in my code.
Now I want to upload everything on my personal hosting. As far as I know my hosting supports Python,CGI and has MySQL database. And I know that I have to change some parameters in the connection string in my code, so I can connect to the database, but I have two problems:
I remember that I installed MySQLdb as an extra to my Python, and in my code i am using it, how would I know that my hosting's python interpretor has this installed, or do I even need it, do I have to use another library?
How do I upload my database onto my hosting?
Thanks
If you have shell access, you can fire up the python interpreter by running python and type import MySQLdb at the >>> prompt. If you get no errors in return, then its installed.
Likewise, if you have shell access, this page will help you with importing and exporting using the mysql command. I found it by googleing "import export mysql".
You can write a simple script like
import MySQLdb and catch any errors
to see if the required package is
installed. If this fails you can ask
the hosting provider to install your
package, typically via a ticket
The hosting providers typically also provide URL's to connect to the MySQL tables they provision for you, and some tools like phpmyadmin to load database dumps into the hosted MySQL instance
To check if MySQLdb library is installed on your hosting, simply open a python shell and type: import MySQLdb. If everthing goes ok, you're readt to go. If you get: ImportError: No module named MySQLdb, that means the the library is not installed and you nedd to install it.
You need that library or some library that provides similar support, because Python does not support native access to MySQL databases.
To transfer you database to your hosting check mysqldump.
How to check available Python libraries on Google App Engine & add more?
Is SQLite available or we must use GQL with their database system only?
Thank you in advance.
SQLite is there (but since you cannot write to files, you must use it in a read-only way, or on a :memory: database).
App engine docs do a good job at documenting what's there. You can add any other pure-python library, typically as a zipfile of .py (NOT .pyc) files to upload in the main directory of your app (you can directly import from inside the zipfile, of course).
A few more pure-Python third-party libraries included with app engine are listed and documented here -- the paragraph on zipimport at this URL has a bit more details on the ways and limitations of using zipfiles to add more third-party pure-Python libs to your app.
Afaik, you can only use the GAE specific database.