So I'm trying to use the django 1.1 template engine with the google app engine web app framework, from here. This is on Ubuntu Jaunty, I've made sure that the PYTHONPATH contains the location of Django-1.1.1 yet I'm getting this 'ImportError: No module named django' error when it tries to execute the use_library() line below. Again, could somebody help me? I'm stumped.
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from google.appengine.dist import use_library
use_library('django', '1.1')
Came up with the following solution:
Get django 1.1 and put it under your project root.
Add an empty file "non_gae_indicator" to your project root folder.
Add django and non_gae_indicator to your app.yaml skip_files element:
skip_files:
- ^(.*/)?app\.yaml
- ^(.*/)?app\.yml
- ^(.*/)?index\.yaml
- ^(.*/)?index\.yml
- ^(.*/)?#.*#
- ^(.*/)?.*~
- ^(.*/)?.*\.py[co]
- ^(.*/)?.*/RCS/.*
- ^(.*/)?\..*
- ^(.*/)?.*\.bak$
- ^django
- ^non_gae_indicator
Now we have a way to tell whether we are running under the GAE-sdk or live - since non_gae_indicator won't be available when we are live.
So in main.py you can do:
if not os.path.exists(os.path.abspath(os.path.dirname(__file__)) + '/non_gae_indicator'):
# GAE
from google.appengine.dist import use_library
use_library('django', '1.1')
else:
# Not GAE - Add our django package to the path
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)) + '/django')
You should run your local SDK server with the --allow_skipped_files flag (or else the skipped files will appear to not be exist when checking them - the server console gives a warning about it).
#stallarida - The problem is that .96 is shipped as default with the SDK. What I did in the end, which is a dirty hack but works, is to update the version of django in the appengine directory to 1.1. Worked fine, needed a bit of tweaking between dev and production.
Specifically I had to comment out use_library('django', '1.1') when running locally but include it when uploading my app.
I'm sure there's a better solution and I'll work it out when my linux experience improves.
Related
Deploying my django website with S3 as storage which runs fine locally to pythonanywhere gives a strange error I can't google a solution for:
"TypeError: a bytes-like object is required, not 'str'"
What I'm doing wrong?
I've tried to put my environment variables out of settings.env (aws keys, secret_key, etc) ad set them directly in my settings.py app. + every suggestion I could find but it's still the same :(
here's my /var/www/username_pythonanywhere_com_wsgi.py:
# +++++++++++ DJANGO +++++++++++
# To use your own Django app use code like this:
import os
import sys
from dotenv import load_dotenv
project_folder = os.path.expanduser('~/portfolio_pa/WEB') # adjust as appropriate
load_dotenv(os.path.join(project_folder, 'settings.env'))
# assuming your Django settings file is at '/home/myusername/mysite/mysite/settings.py'
path = '/home/corebots/portfolio_pa'
if path not in sys.path:
sys.path.insert(0, path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'WEB.settings'
## Uncomment the lines below depending on your Django version
###### then, for Django >=1.5:
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
###### or, for older Django <=1.4
#import django.core.handlers.wsgi
#application = django.core.handlers.wsgi.WSGIHandler()
I'd expect the website to run fine just like it does locally.
Boto library doesn't have a good Python3 support. This particular issue is known in the boto bugtracker: https://github.com/boto/boto/issues/3837
The best way of fixing this is to use boto3 which has decent Python3 support and is a generally most supported AWS SDK for Python.
The reason why it works on your local machine and doesn't work on production is that pythonanywhere setup seems to be using proxy which triggers this incompatible boto code. See the actual calling code: https://github.com/boto/boto/blob/master/boto/connection.py#L747
Your error traceback confirms this.
Unfortunately, I'm not familliar with the django-photologue, but a brief look doesn't suggest that it strongly depends on boto3. Maybe I'm wrong.
I still think that the best way is to go with boto3. As a backup strat you can fork boto with a fix for this issue and install that instead of the official one from PyPI: https://github.com/boto/boto/pull/3699
I'm using pycharm to develop appengine. Now i'm trying to use endpoints and I've put
libraries:
- name: pycrypto
version: latest
- name: endpoints
version: 1.0
and then in main.py
import endpoints
But it gives me error
No module named endpoints
I can see the endpoints folder inside the GAE library. Anyone can help?
*EDIT: it is just a matter of IDE (pycharm) cant locate endpoints. The app runs fine and okay both in dev server or cloud server. There is a picture just to make it a bit clearer:
Thanks
You need to add {GAE_SDK}/lib/endpoints-1.0, not just the SDK itself. The reason you can import google is because it is directly under {GAE_SDK}. The libraries you specify in app.yaml are laid out differently due to supporting multiple versions. I believe you also need to add {GAE_SDK}/lib/protorpc-1.0/, it's just not showing because there's already an import error.
I'm using the new version of PyCharm Community and I got to config too. You need to set the Source option on each folder like endpoints in File - Setting - Project:
I've run across the following code somewhere which fixes it for me in a client script. I'm not able to say how much of it may be unnecessary. You'd need to edit the google_appengine path for your SDK installation:
sdk_path = os.path.expanduser('~/work/google-cloud-sdk/platform/google_appengine')
try:
import google
google.__path__.append("{0}/google".format(sdk_path))
except ImportError:
pass
try:
import protorpc
protorpc.__path__.append("{0}/lib/protorpc-1.0/protorpc".format(sdk_path))
except ImportError:
pass
sys.path.append("{0}/lib/endpoints-1.0".format(sdk_path))
I use django-haystack 2.0.0 to index my site, and it has been working great until I upgraded to Django 1.5 and started using the WSGI interface. If I just use the django_gunicorn command it works great, but the Django documentation "highly recommends" I use the gunicorn command.
When I start my site with the gunicorn command, Haystack throws the following error on any page load:
ImportError: cannot import name signals
I have no problems importing signals from the Django or Python shells. I use virtualenv and install all packages locally inside that environment. My wsgi.py file looks just like the default one in the django admin, except that I add the local path to the python path as such:
path = os.sep.join(os.path.abspath(__file__).split(os.sep)[:-2])
if path not in sys.path:
sys.path.append(path)`
Any help you could provide would be very appreciated, thank you!
I don't use gunicorn, but I had the same problem when I used the HAYSTACK_SIGNAL_PROCESSOR setting to point to a custom class that I wrote. That class imported one of my models, which eventually propagated up the import chain, to import my settings module, thus causing a circular import.
When using a setting such as HAYSTACK_SIGNAL_PROCESSOR that points to a class, make sure that class standsalone, and doesn't import either directly or indirectly the Django settings file.
I have created a Django 1.3 application on Openshift.
I wanted to upgrade to Django 1.5. So I updated setup.py to install Django 1.5
#!/usr/bin/env python
from setuptools import setup
setup(
name='<Application name>',
version='1.0',
description='',
author='',
author_email='',
url='http://www.python.org/sigs/distutils-sig/',
install_requires=['Django>=1.5'],
)
The server returns http 500.
If setup.py has install_requires=['Django<=1.4'] it works fine.
How can I install Django 1.5 on Openshift?
Update: I can see a github commit where in the install_requires for Django is changed from >=1.3 to <=1.4 for the handling this same issue. But I still cannot figure out what caused that server 500 and how can we install Django 1.5 on openshift
It might come from your code, did you check the backwards incompatibilities mentioned in the release notes (mainly ALLOWED_HOSTS required in your settings.py)
It could also come from the {% url %} tag syntax change, see here.
When i installed Django app on OpenShift, Django version was 1.5.1. I think OpenShift install last version Django, because the condition Django >= 1.4, that is no lower this version.
That is screenshot, when i installed app
I had the same issue : from your screenshot you're using python2.6 ?
Try to use python2.7 with this configurations put on the application file:
#!/usr/bin/env python
import os
import sys
sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR']))
os.environ['DJANGO_SETTINGS_MODULE'] = 'mywebsite.settings'
virtenv = os.environ['OPENSHIFT_HOMEDIR'] + 'python/virtenv/'
os.environ['PYTHON_EGG_CACHE'] = os.path.join(virtenv, 'lib/python2.7/site-packages')
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
pass
#
# IMPORTANT: Put any additional includes below this line. If placed above this
# line, it's possible required libraries won't be in your searchable path
#
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
And as refered by #Charles L try to set the settings using allowed host
Has anyone been able to get Google App Engine/Django working in Pydev/Eclipse? I tried this but had difficulty getting Pydev to recognize all of the externally linked folders (django plugins) that I was referencing. I ended up copying all of those folders into the project en masse, rather than referencing them, resulting in a massively bloated project folder - it was really an unworkable solution that eventually made me give up the whole project. So, I'm wondering if anyone has tried this or has any idea what I might have been doing wrong. (Keep in mind this was my first attempt at using Pydev, Django, App Engine and Python!!)
I haven't personally set it up but i did see this tutorial on how to do it:
http://code.google.com/appengine/articles/eclipse.html
Pydev 1.4.6 (still only available in the nightly builds) has some special support to easy in the configuration. See: http://pydev.blogspot.com/2009/05/testing-on-pydev-146-google-app-engine.html
This tutorial shows how to configure Aptana (with PyDev installed) to be your coding and debugging platform for AppEngine. Similarly you can add Django libraries to Aptana too.
http://www.alishabdar.com/2009/05/06/develop-google-appengine-with-aptana-studio/
This question hasn't been replied to for some time and things have changed, so I thought I would provide and update.
PyDev now includes a Google App Engine configuration out of the box and you can debug and run GAE projects out of the box, this includes Django.
Just install GAE and the latest Eclipse/PyDev on your machine then create a GAE project and point PyDev at your versions of Python and Google App Engine.
appengine 1.31
Django 1.1
pydev 1.5.4
OS Ubuntu 9.10
eclipse .pydevproject file:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?>
<pydev_project>
<pydev_variables_property name="org.python.pydev.PROJECT_VARIABLE_SUBSTITUTION">
<key>GOOGLE_APP_ENGINE</key>
<value>/home/elvis/google_appengine</value>
</pydev_variables_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/pythonleggo</path>
</pydev_pathproperty>
<pydev_pathproperty name="org.python.pydev.PROJECT_EXTERNAL_SOURCE_PATH">
<path>${GOOGLE_APP_ENGINE}</path>
<path>${GOOGLE_APP_ENGINE}/lib/webob</path>
<path>${GOOGLE_APP_ENGINE}/lib/yaml/lib</path>
</pydev_pathproperty>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.6</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
</pydev_project>
Files:
eclipse project folder
- app.yaml
- index.yaml
- init.py
- main.py
- manage.py
- .project
- .pydevproject
- settings.py (unable to load)
- urls.py
main.py:
from google.appengine.dist import use_library
use_library('django', '1.1')
from django.conf import settings
settings.configure(
DEBUG=True,
TEMPLATE_DEBUG=True,
ROOT_URLCONF = 'urls',
PROJECT_NAME = 'pythonleggo',
SETTINGS_MODULE = '.settings',
ADMINS = ('elvis', 'elvis#gmail.com'),
LANGUAGE_CODE = 'en-us',
SITE_ID = 1,
USE_I18N = True,
MEDIA_ROOT = '',
MEDIA_URL = '',
ADMIN_MEDIA_PREFIX = '/media/',
SECRET_KEY = 'shhh',
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.load_template_source',
'django.template.loaders.app_directories.load_template_source'),
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware'),
TEMPLATE_DIRS=('/home/jmurphy/workspace/pythonleggo/templates'),
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites')
)
#os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
import django.core.handlers.wsgi
from google.appengine.ext.webapp import util
def main():
# Run Django via WSGI.
application = django.core.handlers.wsgi.WSGIHandler()
util.run_wsgi_app(application)
if __name__ == ' __main__':
main()
eclipse run:
/usr/bin/python2.6 -u /home/elvis/google_appengine/dev_appserver.py
The PYTHONPATH that will be used is:
/home/elvis/.eclipse/org.eclipse.platform_3.5.0_155965261/plugins/org.python.pydev_1.5.4.2010011921/PySrc/pydev_sitecustomize:/home/elvis/workspace/pythonleggo:/home/elvis/google_appengine:/home/elvis/google_appengine/lib/webob:/home/elvis/google_appengine/lib/yaml/lib:/usr/lib/pymodules/python2.6:/usr/lib/pymodules/python2.6/gtk-2.0:/usr/lib/python2.6:/usr/lib/python2.6/dist-packages:/usr/lib/python2.6/dist-packages/PIL:/usr/lib/python2.6/dist-packages/gst-0.10:/usr/lib/python2.6/dist-packages/gtk-2.0:/usr/lib/python2.6/lib-dynload:/usr/lib/python2.6/lib-old:/usr/lib/python2.6/lib-tk:/usr/lib/python2.6/plat-linux2:/usr/local/lib/python2.6/dist-packages
I could not get the settings file to load using os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' . It appeared to be stripped from the environ that django received. I used settings.configure which appeared to work correctly. At this point I only have the default django page loading in appspot.
I originally linked to this tutorial. Pydev now has Django support so this is probably less relevant. It may still be useful for figuring out how to make them all work together though. You could also try looking at this blog post.
I've just started with Python and the Google App Engine today. I think we both banged our heads against the same wall with external referencing.
I've tried deploying the google-app-engine-django project for my app. I've extracted everything and I have under my root the /appengine_django and /django folder.
I've added them as source folders, and I've added the /google_appengine/google folder as an external reference.
Normally, this all made sense to me. Each contained the __ init __.py module. Still, when I tried to ctr+click on any of the import statements it couldn't resolve the path to the modules.
Strikingly, you do not import the immediate folder that contains an __ init __.py. To properly reference packages you import the parent folder that contains the package duh! That also means that, since I didn't want to use a /src folder, the actual project folder should be added as a source reference to get the /appengine_django and /django to be recognized as source folders.
With that done, everything is running smoothly. I guess it's to show I have more reading up to do on Py.
Here is an other tutorial that might help.
The eclispe version might be a bit old but it should get you
far enough to get a working project.
http://django-appengine.com/contents
It has complete eclipse set up
http://django-appengine.com/post/37462709481/
http://www.mkyong.com/google-app-engine/google-app-engine-python-hello-world-example-using-eclipse/
It has complete gae set up
http://django-appengine.com/post/37615321945/
It has complete django set up
http://django-appengine.com/post/37628665099/
And then explains how to combine those two projects
into one gae project.
http://django-appengine.com/post/37778427717/
I hope this helps others who are just starting out