Import error on first-party library with dev_appserver.py

2024/10/12 8:19:45

On Ubuntu 16.04, am suddenly getting import errors from the local GAE development server.

The local dev server starts up, including the admin interface, but app no longer loads.

Native python imports of the same library on same machine (in this case "from google.cloud import datastore") work fine.

The GAE standard app does run when deployed, but development just got a little challenging.

google-cloud is version 0.27.0 gcloud components is 172.0.1 python is Anaconda 2.7.13 GAE is standard

I have confirmed to the best of my middling abilities that $PATH is correct for all named libraries.

I have removed and re-added all the named libraries to no effect.

cachetools(2.0.1) it should probably be noted, is installed as a dependency of the google cloud libraries, so I don't think this is addressable through requirements.txt or "libraries" in app.yaml.

I did recently go through a cycle of removing and adding libraries to fix a problem with apache_beam 2.0.1, so I may have jacked up something else, but am not sure where to look.

Suggestions deeply appreciated. Full traceback (from admin, same as from app):

Traceback (most recent call last):File "/usr/lib/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/runtime/request_handler.py", line 232, in handle_interactive_requestexec(compiled_code, self._command_globals)File "<string>", line 1, in <module>File "/home/brian/anaconda3/lib/python2.7/site-packages/google/cloud/datastore/__init__.py", line 61, in <module>from google.cloud.datastore.client import ClientFile "/home/brian/anaconda3/lib/python2.7/site-packages/google/cloud/datastore/client.py", line 23, in <module>from google.cloud.client import ClientWithProjectFile "/home/brian/anaconda3/lib/python2.7/site-packages/google/cloud/client.py", line 27, in <module>from google.oauth2 import service_accountFile "/home/brian/anaconda3/lib/python2.7/site-packages/google/oauth2/service_account.py", line 79, in <module>from google.auth import jwtFile "/home/brian/anaconda3/lib/python2.7/site-packages/google/auth/jwt.py", line 49, in <module>import cachetools
ImportError: No module named cachetools
Answer

The stacktrace indicates you're running the libraries from the local system installation (the site-packages dir), not from your app.

For standard env GAE apps you need to install the dependencies inside your app and they will be uploaded to GAE together with your app code.

More specifically you need to use the -t <your_app_lib_dir> option for the pip installation. From Installing a third-party library:

  1. Use pip (version 6 or later) with the -t <directory> flag to copy the libraries into the folder you created in the previousstep. For example:

    pip install -t lib/ <library_name>
    
https://en.xdnf.cn/q/118218.html

Related Q&A

Split dictionary based on values

I have a dictionary:data = {cluster: A, node: B, mount: [C, D, E]}Im trying to split the dictionary data into number of dictionaries based on values in key mount.I tried using:for value in data.items()…

Using defaultdict to parse multi delimiter file

I need to parse a file which has contents that look like this:20 31022550 G 1396 =:0:0.00:0.00:0.00:0:0:0.00:0.00:0.00:0:0.00:0.00:0.00 A:2:60.00:33.00:37.00:2:0:0.02:0.02:40.00:2:0.98:126.00…

Iterating in DataFrame and writing down the index of the values where a condition is met

I have a data made of 20 rows and 2500 columns. Each column is a unique product and rows are time series, results of measurements. Therefore each product is measured 20 times and there are 2500 product…

Access denied to ClearDB database using Python/Django on Heroku

Im trying to build a webapp on Heroku using Python/Django, and I just followed the tutorial to set up a Django project and push it to Heroku. However, I can never even get to the normal Django "I…

Replacing a line in a file based on a keyword search, by line from another file

Here is my file1: agadfadsdffasdfElement 1, 0, 0, 0PcomElement 2Here is my file2: PBARElement 1, 100, 200, 300, 400Element 2Continue...I want to search with a keyword, "Element 1" in file1,…

How to check for pop up alert using selenium in python

What I want is to continue with the next iteration if there is a pop up message in the webpage being scrapped. That is if there is any pop up message, I want to accept that message and go to the next i…

Rally host is non-existent or unreachable via pyral

I am trying to call rally server simply using below: rally = Rally(server, user, password, workspace=workspace, project=project)But it is giving below error:Traceback (most recent call last):File "…

Query tangled array in Pymongo

I am trying to query a very tangled collection. The schema:{tags: {variables: [{value: 3x9, var_name: s},{value: 12:00AM, var_name: x},{value: goog, var_name: y}]},url: https://www.google.com}]The Quer…

manipulating value of pandas dataframe cell based on value in previous row without iteration

I have a pandas dataframe with~3900 rows and 6 columns compiled from Google Finance . One of these columns defines a time in unix format, specifically defining a time during the trading day for a marke…

Convert ctypes code to cython

Id like to convert some ctypes code to use cython instead, but Im struggling. Essentially, the ctypes code:copies the contents (floats) of two lists into C-compatible structs sends the structs to my b…