Installing gdata Python package on Heroku - python

First, a disclaimer that I am new to Python (I come from Ruby). I'm trying to integrate Google Contacts API into my Heroku Python app. Seem to having a hard time figuring out how to push the gdata package (https://code.google.com/p/gdata-python-client/) to Heroku. This is the Heroku error msg:
Traceback (most recent call last):
2014-07-03T09:03:58.205264+00:00 app[web.1]: File "message.py", line 16, in <module>
2014-07-03T09:03:58.205327+00:00 app[web.1]: import atom.data
2014-07-03T09:03:58.205364+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/atom/data.py", line 24, in <module>
2014-07-03T09:03:58.205429+00:00 app[web.1]: import atom.core
2014-07-03T09:03:58.205516+00:00 app[web.1]: ImportError: No module named core
2014-07-03T09:03:59.454062+00:00 heroku[web.1]: State changed from starting to crashed
My first thought was to include gdata and atom in my requirements.txt (it looks like gdata depends on atom)
I tried adding this to my requirements.txt: gdata==2.0.18 atom==0.3.7. However I don't think I'm going about this the right away. The gdata-python-client I downloaded came with a setup.py file that I think I'm supposed to use when pushing to heroku, but I can't seem to get to work either (always get the same error above).
Help is much appreciated :)

I seemed to have gotten around it, but the only way I could fix this error was by removing gdata from requirements.txt and including the /build and /atom folder from https://code.google.com/p/gdata-python-client/ in my root directory.

Related

No module named warnings when starting GAE inside virtualenv locally

I am trying to run my GAE app locally inside a virtual environment.
I've followed these two articles [1], [2] as reference to setup, but when I source evn/bin/activate and then dev_appserver.py ., it keeps raising the error of ImportError: No module named warnings (more trace below)
Surprisingly, if I start it without activating virtual env by just running dev_appserver.py . inside root of project it runs without any issue.
Is there any solution or workaround for this problem?
INFO 2017-08-31 14:09:36,293 devappserver2.py:116] Skipping SDK update check.
INFO 2017-08-31 14:09:36,354 api_server.py:313] Starting API server at: http://localhost:52608
INFO 2017-08-31 14:09:36,357 dispatcher.py:226] Starting module "default" running at: http://localhost:8080
INFO 2017-08-31 14:09:36,359 admin_server.py:116] Starting admin server at: http://localhost:8000
Traceback (most recent call last):
File "/usr/local/share/google/google-cloud-sdk/platform/google_appengine/_python_runtime.py", line 103, in <module>
_run_file(__file__, globals())
File "/usr/local/share/google/google-cloud-sdk/platform/google_appengine/_python_runtime.py", line 97, in _run_file
execfile(_PATHS.script_file(script_name), globals_)
File "/usr/local/share/google/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/runtime.py", line 192, in <module>
main()
File "/usr/local/share/google/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/runtime.py", line 172, in main
sandbox.enable_sandbox(config)
File "/usr/local/share/google/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 326, in enable_sandbox
__import__('%s.threading' % dist27.__name__)
File "/usr/local/share/google/google-cloud-sdk/platform/google_appengine/google/appengine/dist27/threading.py", line 11, in <module>
import warnings
File "/usr/local/share/google/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 1076, in load_module
raise ImportError('No module named %s' % fullname)
ImportError: No module named warnings
ERROR 2017-08-31 14:09:39,070 instance.py:280] Cannot connect to the instance on localhost:52366
I've solved it by removing from the skip_files of my .yaml a - venv line. venv is my virtualenv folder, and I still have a - ^venv$ line. In case that helps someone ;-)
All dependencies for standard environment GAE apps (which aren't provided by GAE) must be installed in the app itself, not on your local system. See Using third-party libraries.
Since GAE doesn't care about your local system libraries (besides the basic python 2.7 installation needed to run the development server), using a virtualenv for developing standard env GAE apps doesn't make a lot of sense.
The use of the virtualenv as suggested by the articles you mentioned can actually cause trouble:
local python libraries can interfere with the GAE runtime-provided equivalent libraries (from the SDK) when running locally (I suspect this is somehow what you're experiencing)
at deployment time the content of the lib directory (which includes all the site packages for your python installation) will be uploaded to GAE, potentially causing clashes with the GAE runtime-provided libraries or exceeding the app file quota.
So my suggestion is to drop virtualenv (which, in a way, you did when you skipped the virtualenv activation) and follow the official documentation instead.
I had this problem when running two AppEngine projects in separate directories at once using dev_appserver.py in a virtualenv.
I found it works correctly if I use absolute paths instead.

Error installing pyflycapture2 on Windows

I am attempting to install this https://github.com/jordens/pyflycapture2 python binding on my Windows machine. The readme only has instructions on how to do it for Linux systems, but I imagine the library should still work.
I am able to run "python setup.py install" and it seems to successfully complete, but when I try to run "python test_flycapture2.py" I get this error:
C:\Users\clinic\Desktop\pyflycapture2>python test_flycapture2.py Traceback (most recent call last):
File "test_flycapture2.py", line 20, in <module>
import flycapture2 as fc2
File "build\bdist.win-amd64\egg\flycapture2.py", line 7, in <module>
File "build\bdist.win-amd64\egg\flycapture2.py", line 6, in __bootstrap__
ImportError: DLL load failed: The specified module could not be found.
This seems to imply that flycapture2 wasn't installed correctly. When I instead just open a python session and do "import flycapture2" I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build\bdist.win-amd64\egg\flycapture2.py", line 7, in <module>
File "build\bdist.win-amd64\egg\flycapture2.py", line 6, in __bootstrap__
ImportError: DLL load failed: The specified module could not be found.
Have I done something wrong with the installation process or does pyflycapture2 just not work with Windows?
A dumb solution that's worth a try. There are chances that the DLL are searched directly from where you're starting the python script. So if you have the dll somewhere on your computer, copy it along where you have your test_flycapture2.py.
But given the fact that the setup.py file has a whole bunch of absolute paths in there, I would not place my hopes too high. You can also try to install FlyCapture 2 at the exact same path, run python setup.py bdist_wheel (you will need to install wheel first with pip) in the pyflycapture2 folder, and see if that succeeds.
If it does, try installing the generated wheel (that will be in dist/ subfolder) by doing pip install dist/pyfly....wheel and test again.
Hope this helps
I'm answering this mostly because I found another post where the same question had been posted but the original problem was never answered.
How do I run an installed Python module on Windows?
In the comments, the original poster says that it suddenly started working. I found that the solution was simply to restart my computer. I have now attempted this on two computers and this worked for both of them.

No modules named flask (GAE) [duplicate]

This question already has answers here:
How do I manage third-party Python libraries with Google App Engine? (virtualenv? pip?)
(7 answers)
Closed 7 years ago.
I'm trying to run the vanilla gae-init project here https://github.com/gae-init/gae-init/ to start playing around with Flask and GAE. I keep getting this error -
INFO 2015-10-11 13:28:25,924 devappserver2.py:763] Skipping SDK update check.
INFO 2015-10-11 13:28:26,001 api_server.py:205] Starting API server at: http://localhost:48281
INFO 2015-10-11 13:28:26,024 dispatcher.py:197] Starting module "default" running at: http://127.0.0.1:8080
INFO 2015-10-11 13:28:26,026 admin_server.py:116] Starting admin server at: http://localhost:8081
ERROR 2015-10-11 13:28:28,552 wsgi.py:263]
Traceback (most recent call last):
File "/media/thomas/2CCC2F86CC2F4982/Dev Stuff/SDKs/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/media/thomas/2CCC2F86CC2F4982/Dev Stuff/SDKs/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/media/thomas/2CCC2F86CC2F4982/Dev Stuff/SDKs/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/media/thomas/2CCC2F86CC2F4982/Linux/Python/gae-init/main/main.py", line 3, in <module>
import flask
ImportError: No module named flask
INFO 2015-10-11 13:28:28,560 module.py:786] default: "GET /_ah/warmup HTTP/1.1" 500 749
I've tried adding the PYTHONPATH to my .bashrc file with export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/dist-packages (dist-packages because that's where pip seems to be installing all my stuff? I saw mentions of site-packages, but there's nothing in that folder)
I've tried running pip install -r requirements.txt -t lib because as far as I can tell, dev_server.py cannot find flask at all.
I've checked out answers here and here but they didn't help much. The second one seems promising, but I'm running Ubuntu and not Windows.
I'm quite a beginner with Python so trying to figure this out as I go along.
Thanks for any help!
You have to tell your app where third-party libraries are by adding appengine_config.py to your project root.
https://cloud.google.com/appengine/docs/python/tools/libraries27#vendoring

GAE "500 Server Error" message when trying to load my application

I'm not sure which log to look at, but in general, all the errors are the same as this paste. I recently upgraded my client machine to Python version 2.7.8, from 2.7.7. The app runs locally.
E 22:20:58.694
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 302, in _LoadHandler
raise err
ImportError: <module 'blog' from '/base/data/home/apps/s~eminent-augury-789/1.380687153152922933/blog.pyc'> has no attribute application
It didn't work under 2.7.7, I was getting the same error. I created another project, with a different project id, and it works. I'm guessing that the app.yaml file was corrupt and I just couldn't find the problem. I upgraded app engine before I started this. I use VIM, for editing. I used the same project id for different projects, just changed the version number, not sure if that was the problem, either. I don't know how to cut and paste in code samples, they get formatted differently, let me work on that and I'll paste the app.yaml file in.

Sync django-piston models when using egg module

I'm using django-piston and running into the following problem when running the manage.py syncdb command:
Traceback (most recent call last):
File "./manage.py", line 13, in <module>
execute_manager(settings)
File "/home/appfirst/django/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
............ lines ommitted ...........
File "/home/appfirst/django/django/utils/translation/trans_real.py", line 176, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/home/appfirst/django/django/utils/translation/trans_real.py", line 160, in _fetch
apppath = os.path.join(os.path.dirname(app.__file__), 'locale')
AttributeError: 'module' object has no attribute '__file__'
In my development environment, I don't have this problem. There I have my python path set to include the django-piston directory. On production, I installed piston by compiling it to an rpm (python setup.py bdist --format=rpm) and installing it as an egg in /usr/lib/python2.6/site-packages/. This means that in development, I can do
>>> import piston
>>> piston.__file__
/some/file/path/here
But on production I get
>>> import piston
>>> piston.__file__
AttributeError: 'module' object has no attribute '__file__'
Does anyone know a way around this?
Looks like this is a known issue with Piston 0.2.3. You could apply this patch or just use version 0.2.2 by installing it as so:
pip install django-piston==0.2.2
I had the same issue, not sure what caused it, but to fix it, I uncommented the piston app out of my INSTALLED_APPS in settings, and it started working again, so it was something to do with loading piston. I'm going to remove piston from my site-packages directory and try to reload it, and see if that helps.
Also, while trying to find the answer to my question I came across a few sites with similar issues.
This site describes an issue related to __init__.py missing.
http://www.willmer.com/kb/2007/12/attributeerror-module-object-has-no-attribute-blah/
This site describes circular imports as an issue.
http://www.answermysearches.com/python-fixing-module-object-has-no-attribute/333/
And another one that I can't find, mentioned something about not being able to load the files correctly from an app installed as an egg.

Categories

Resources