I've been experimenting with the Google App Engine, and I'm trying to import certain libraries in order to execute API commands. I've been having trouble importing, however. When I tried to execute "from apiclient.discovery import build", my website doesn't load anymore. When I test locally in IDLE, this command works.
the python api-client package comes with a command enable-app-engine-project that will install all of the required packages into your project folder:
http://code.google.com/p/google-api-python-client/wiki/GoogleAppEngine
The packages needs to be locally available, where did you put the packages, in the Python folder or in your project folder?
Related
I'm trying to install Instagram-API-python in Azure Automation to automatize data extraction from this API with a Python script.
When I try to install it uploading the .tar.gz file or by the "Import Python 2 packages from pypi" script, azure automation shows me the following message:
Orchestrator.Activities.PythonPackageExtractException: Error while
extractinig Python package: Error converting tar.gz file to wheel
file. Unexpected number of wheel files were created. at
Orchestrator.Activities.SetModuleActivity.ExecuteInternal(CodeActivityContext
context, Byte[] moduleContent, String moduleName, ModuleLanguage
moduleLanguage, Guid moduleVersionId, String modulePath) at
Orchestrator.Activities.SetModuleActivity.Execute(CodeActivityContext
context) at
System.Activities.CodeActivity.InternalExecute(ActivityInstance
instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at
System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor
executor, BookmarkManager bookmarkManager, Location resultLocation)
Any idea why it is showing me this message?
I am assuming that it is failing as it is not able to resolve all the dependencies , try using the Manual download option.
Azure automation doesn't resolve dependencies for python packages during the import process. There are two ways to import a package with all its dependencies. Only one of the following steps needs to be used to import the packages into your Automation Account.
Manual Download
On a Windows 64-bit machine with python2.7 and pip installed, run the following command to download a package and all its dependencies:
C:\Python27\Scripts\pip2.7.exe download -d <output dir> <package name>
Once the packages are downloaded, you can import them into your automation account.
RunBook
Import the python runbook Import Python 2 packages from pypi into Azure Automation account from the gallery into your Automation Account. Make sure the Run Settings are set to Azure and start the runbook with the parameters. The runbook requires a Run As Account for the Automation Account to work. For each parameter make sure you start it with the switch as seen in the following list and image:
s
g
a
m
The runbook allows you to specify what package to download, for example, Azure (the fourth parameter) will download all Azure modules and all its dependencies, which is about 105.
Once the runbook has completed you can check the Python 2 packages page under Shared Resources in your Automation Account to verify that they package was imported correctly.
Hope it helps.
The Manual Download worked for me.
I'm trying to set up a roguelike Python project, but I can't seem to be able to import libtcod module into my project. This helloworld crashes, and the IDE keeps telling me that there is no module named libtcodpy.
import libtcodpy
def main():
print('Hello World!')
if __name__ == '__main__':
main()
What is the proper way to import modules into Python projects? I'm used to Java, so I was expecting something along the lines of Maven to manage the dependencies. There indeed seems to be something like that in PyCharm as well, this package manager for the venv, which from what I gather serves to isolate the project-specific stuff from the OS- or python-global stuff:
but libtcod simply isn't present in the rather exhaustive list of modules that appears after clicking on the "+" button, just some other module that has something to do with libtcod library (I guess?). Moreover, all the tutorials I found on setting libtcod up advise one to manually copy over files somewhere or run some command that I suppose does the importing somehow and other such solutions, all of which i tried and none of which worked. I don't want to pollute my project structure by using such hodgepodge ways of handling dependencies if I can at all avoid it.
Q: How do I get libtcod to work in my PyCharm project in the most clean and convention-abiding way possible?
Take a look at this github project called tcod: https://github.com/libtcod/python-tcod/blob/master/README.rst#installation
It's a python port of libtcod.
To install using pip, use the following command:
python -m pip install tcod
If you get the error "ImportError: DLL load failed: The specified module could not be found." when trying to import tcod/tdl then you may need the latest Microsoft Visual C runtime.
Blockquote
I'm trying to deploy a Flask app on GAE using Windows. It runs fine locally but runs into problems when I try to run it on GAE.
First I get this error in flask\json.py:
from itsdangerous import json as _json
ImportError: No module named itsdangerous
Downloading and unpacking https://pypi.python.org/pypi/itsdangerous in the same directory doesn't fix the issue. If I just grab itsdangerous.py and put it in the flask directory, I get:
_slash_escape = '\\/' not in _json.dumps('/')
AttributeError: 'module' object has no attribute 'dumps'
I've read that it may be due to conflicting json.py files but I've also tried using absolute paths for the import json and it doesn't seem to make a difference.
You put the itsdangerous.py in the wrong directory. Because json.py and itsdangerous.py both exist in the /flask directory, itsdangerous.py will import /flask/json.py intead of the right one.
The GAE official doc mentioned a way to include 3rd-party libraries:
You can include other pure Python libraries with your application by
putting the code in your application directory. If you make a symbolic
link to a module's directory in your application directory, appcfg.py
will follow the link and include the module in your app.
Obviously, it's a poor solution because we don't want to mix the libraries we used with the code we write. The community have found better ways.
I suggest you to use a gae-flask project template(e.g. flask-appengine-template) or at least follow some of its project structure. You can put all these 3rd-party libraries under a directory like /lib and add '/lib' to sys.path. Actually flask-appengine-template include common flask modules like itsdangerous for you by default.
sample code:
import os
import sys
sys.path.insert(1, os.path.join(os.path.abspath('.'), 'lib'))
import application
Google now makes it super-easy:
https://console.developers.google.com/start/appengine
Since python is bundled with the Tide SDK, I can't figure out how to use access external modules. I've tried copying the module folder "Lib/site-packages/YourModuleHere" to the tide SDK directory, and this suggestion here: TIdeSDK Python module import but with no success. The module I'm trying to use is https://github.com/burnash/gspread
Any ideas?
Thanks...
You may try http://www.py2exe.org/index.cgi/Tutorial
to convert your python code to exe with all needed modules then use Ti.Process.createProcess() to call your exe
In current version of TideSDK, loading custom python modules is not supported.It loads default set of Python modules compiled within the SDK.
I've had some luck installing a view external modules by running setup.py install from TideSDK's python.exe
This post helped:
Installing python modules in TideSDK
For Windows 7:
launch powershell
cd into the module folder
run:
C:\ProgramData\TideSDK\Modules\python\1.3.1-beta\python.exe setup.py install
It installs the module in \Lib\site-packages, as it should, and I'm able to use the import function in the python code.
This has worked for PIL and I'm trying to get it to function with pywin32. I'd love to hear if it works for other modules
I'm trying to install the icalendar Python module for use in my Google App Engine project. I have created a Python virtual environment in my project folder, and installed the icalendar package in it. If I run the Python interpreter from the venv, I can import icalendar and use it just fine (help(icalendar) shows it's getting the module from the correct path: venv/lib/python2.7/site-packages/icalendar). I have created a symlink called icalendar pointing to that directory in my project root (same place as app.yaml). The project can deploy and run on GAE, but anytime it tries to use icalendar, I get "Cannot import module 'icalendar'".
I used the exact same steps to install the Twilio library in my app, which worked fine. If I don't include the symlink to the Twilio module, the error message is actually 'No module named twilio', instead of "Cannot import..". Not sure if that's relevant.
I've seen this: https://groups.google.com/forum/?fromgroups=#!topic/google-appengine/FM_NXd9cbus, which is exactly my problem, but there was no solution!
What am I doing wrong?
Edit: I also tried just putting the icalendar module directory in the project root, w/o the symlink. No difference.
You need to check how to use python libraries in GAE.
Pay attention as the docs are a bit confusing, you need to pick one (and only one) solution for a library, you can't mix both (they're both chapters on the above-mentioned page):
Requesting a library - for libs supplied by GAE - for these check notes for what you may need to do for your local development server
Installing a library - for additional libraries you need to include in your app - for these check also the restrictions the library needs to meet