ImportError: No module named google.cloud.error_reporting

我的未来我决定 提交于 2019-12-11 15:18:05

问题


A few weeks ago I've installed Ubuntu 18.10 at home and today I decided to move from Windows to this OS at home.

I use it for Python development.

Unfortunately, I faced with some strange error and don't know how to solve it.

When I try to run my project I see next error during simple request

File "/usr/lib/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/runtime/sandbox.py", line 1154, in load_module
    raise ImportError('No module named %s' % fullname)
ImportError: No module named google.cloud.error_reporting

When I run pip show google_cloud_error_reporting it shows me proper info about the package

DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Name: google-cloud-error-reporting
Version: 0.30.1
Summary: Stackdriver Error Reporting API client library
Home-page: https://github.com/GoogleCloudPlatform/google-cloud-python
Author: Google LLC
Author-email: googleapis-packages@google.com
License: Apache 2.0
Location: /home/p35/.local/share/virtualenvs/tt-T7X9xdJU/lib/python2.7/site-packages
Requires: google-cloud-logging
Required-by: 

Output from gcloud --version

Google Cloud SDK 240.0.0
alpha 2019.03.22
app-engine-python 1.9.84
app-engine-python-extras 1.9.84
beta 2019.03.22
bq 2.0.42
cloud-datastore-emulator 2.1.0
core 2019.03.22
gsutil 4.37
kubectl 2019.03.22

I tried to reinstall pipenv, setuptools, project dependencies itself, but nothing helps me.

Simplified project https://github.com/pahan35/google-cloud-error-reporting-import-bug

Any idea how to fix this problem?


回答1:


I've found a workaround for this problem: we should add google dependencies via vendor.add([any_accessible_folder]) and then either run a project under another interpreter or we need to remove all google dependencies from the current pipenv interpreter.

Workaround (right solution still welcome)

For this specific project I did next steps.

Common steps

  1. Install all pipenv dependencies to lib folder via command

    pipenv run pip install -r <(pipenv lock -r) -t lib --upgrade

  2. Use your local folder as another source of packages in your entry file before imported google cloud dependency

from google.appengine.ext import vendor

vendor.add('lib')

from google.cloud import error_reporting # causing problems dependency
  1. Then you need either remove google packages from your pipenv interpreter or use another one. I tested both: B is easier but may cause unexpected conflicts or missed packages

A. Clear current pipenv interpreter from all google cloud dependencies

  1. Enter into pipenv shell via command pipenv shell
  2. See installed packages via pip list
  3. Remove all google cloud packages plus some extra noticed via iterated runs

    pip uninstall google_cloud_error_reporting google_auth google_core google_cloud_core google_api_core google_cloud_logging googleapis_common_protos protobuf

    Maybe we can optimize it via removing all packages from pipenv interpreter?

B. Use another interpreter

  1. Find absolute path to desirable interpreter. I used a global one /usr/bin/python
  2. Run the project via this interpreter like /usr/bin/python $(which dev_appserver.py) .

Project

Example project contains applied workaround



来源:https://stackoverflow.com/questions/55476842/importerror-no-module-named-google-cloud-error-reporting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!