ImportError: No module named google.cloud.error_reporting - python

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?

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
Install all pipenv dependencies to lib folder via command
pipenv run pip install -r <(pipenv lock -r) -t lib --upgrade
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
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
Enter into pipenv shell via command pipenv shell
See installed packages via pip list
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
Find absolute path to desirable interpreter. I used a global one /usr/bin/python
Run the project via this interpreter like /usr/bin/python $(which dev_appserver.py) .
Project
Example project contains applied workaround

Related

What is the difference between <package name> and python-<package name>?

I want to downgrade tornado to a previous version because the new one causes an error according to the answers here: Jupyter notebook kernel not connecting. I am on Ubuntu, in a virtual environment.
To check the current version of it, I used pip freeze and got this: tornado==6.0.1. When I use apt-cache policy tornado the output is: "Unable to locate package tornado". When I type apt-cache policy python-tornado the output is "python-tornado: Installed: 4.5.3-1".
How do I proceed from here? My ultimate goal is to make the jupyter notebook run, and I need to figure out this tornado module for that. What is the difference between tornado and python-tornado? Which one I should care about?
One of those names is the actual package name under which it is published to the Python Package Index (PyPI), which is the namespace that pip deals in.
The other is the name as set by your Ubuntu operating system, and given the version string, I am guessing that you are using Ubuntu 18.04 Bionic Beaver. Ubuntu uses a strict naming convention, where all Python packages must start with a python- prefix. These packages are managed and installed by your OS package manager.
How to proceed depends on your Jupyter setup. If it is installed and running from a virtualenv, then you can use the pip command when the virtualenv is active to alter versions there. Take into account that using pip should already ensure you are getting compatible versions installed; you could try to upgrade jupyter if tornado was upgraded independently.
If you are using the Ubuntu-managed jupyter package then there too the package manager should take care of matching versions.
However, if you you are using a virtualenv that still has access to the OS-mananged jupyter system while locally only tornado is installed, then you want to add jupyter to your virtualenv to mask the system version, which is too old.

Distributing Python and dependencies on Ubuntu

My goal is to be able to package a fully-functional Python interpreter and all dependencies. Couple of quick thoughts up front:
I can't install via pip/requirements.txt on due to Firewall restrictions. I will only have access to pip install on the build system.
Maintaining an internal repo wouldn't be feasible
The code to be distributed will be a number of tools/utilities, not a single script (not as straight-forward to use 'freeze' utilities)
I'm attempting to avoid third-party tools that don't have a strong community.
I'm not using the version of Python packaged with the OS (Ubuntu uses 3.5, we'll likely be using 3.6)
My plan was as follows:
Create a Docker container for the target OS (Ubuntu)
Download Python source and manually build it with a prefix of /build
Use the full path to Python to install dependencies with Pip. For example:
/build/bin/python3.6 -m pip install -r requirements.txt
Tar up the /build directory with the Python runtime and all dependencies
All scripts and utilities will use the absolute path to the interpreter such as:
/opt/python/bin/python3.6
Does anyone see any glaring issues with this plan? I was able to build successfully, move the package to another host, and import all of the pip installed dependencies (requests, numpy, psutil, etc.)

Local development of Google App Engine not importing built-in library

I followed the quickstart then I simply clone hello_world from here. I already downloaded google_appengine sdk from here. I extract it and now I have folder google_appengine alongside with hello_world
so I execute it like this:
It runs well apparently, until I start to request to localhost:8080.
then I got this error:
what's wrong with it? did I miss something?
google said that I can use the built-in library without manually install it with pip.
PS: it works when I just deploy it to my project on Google. and also it works if I manually install webapp2 inside lib inside hello_world like described here then request it locally.
my python version Python 2.7.6 on ubuntu 14.04 32bit
Please if anybody can solve this I would be appreciate it.
Seems like this is acknowledged bug in app engine SDK. As a temporary workaround, you may try this steps:
Uninstalling the following PIP packages resolved this issue for me.
sudo pip uninstall gcloud
sudo pip uninstall googleapis-common-protos
sudo pip uninstall protobuf
Credit to this thread:
https://groups.google.com/forum/?hl=nl#!topic/google-appengine/LucknWk8iaQ
Be sure to use correct executable of pip if you use virtualenv or have multiple python versions installed.
Thanks to #Dmytro Sadovnychyi for the answer. It doesn't work for me to uninstall those packages because I never installed it before, But that makes me think maybe built-in library conflict with other package so I decide to create Virtual Environment. just fresh environment no need to install any package.
activate the environment then execute dev_appserver.py hello_world now it works
for now I'll stick with it until next update like said here

Getting ImportError: No module named azure.storage.blob when doing python manage.py syncdb

When I try to do python manage.py syncdb in my Django app, I get the error ImportError: No module named azure.storage.blob. But thing is, the following packages are installed if one does pip freeze:
azure-common==1.0.0
azure-mgmt==0.20.1
azure-mgmt-common==0.20.0
azure-mgmt-compute==0.20.0
azure-mgmt-network==0.20.1
azure-mgmt-nspkg==1.0.0
azure-mgmt-resource==0.20.1
azure-mgmt-storage==0.20.0
azure-nspkg==1.0.0
azure-servicebus==0.20.1
azure-servicemanagement-legacy==0.20.1
azure-storage==0.20.3
Clearly azure-storage is installed, as is evident. Why is azure.storage.blob not available for import? I even went into my .virtualenvs directory, and got in all the way to azure.storage.blob (i.e. ~/.virtualenvs/myvirtualenv/local/lib/python2.7/site-packages/azure/storage/blob$). It exists!
What do I do? This answer here has not helped: Install Azure Python api on linux: importError: No module named storage.blob
Note: please ask for more information in case you need it
I had a similar issue. To alleviate that, I followed this discussion here: https://github.com/Azure/azure-storage-python/issues/51#issuecomment-148151993
Basically, try pip install azure==0.11.1 before trying syncdb, and I'm confident it will work for you!
There is a thread similar with yours, please check my answer for the thread Unable to use azure SDK in Python.
Based on my experience, Python imports the third-party library packages from some library paths that you can check them thru codes import sys & sys.path in the python interpreter. So you can try to dynamically add the new path contains the installed azure packages into the sys.path in the Python runtime to solve the issue. For adding the new library path, you just code sys.path.append('<the new paths you want to add>') at the front of the code like import azure.
If the way has not helped, I suggest you can try to reinstall Python environment. On Ubuntu, you can use the command sudo apt-get remove python python-pip & sudo apt-get install python python-pip to reinstall Python 2.7 & pip 2.7.(Note: The current major Linux distributions use Python 2.7 as the system default version.)
If Python 3.4 as your runtime for Django, the apt package names for Ubuntu are python3 and python3-pip, and you can use sudo pip3 install azure for Python 3.4 on Ubuntu.
Any concern, please feel free to let me know.

ImportError: No module named requests - Python

I get an error message when I run the following line of code
import requests
Here is the error message
Traceback (most recent call last):
File "C:\Python27\test", line 1, in <module>
import requests
ImportError: No module named requests
Based on what I've seen from other posts, the common reason for the problem is individuals download the requests module but have not installed it. I downloaded the tarball, unzipped it and installed the setup.py file via the computer command line. There is a requests-2.4.0-py2.7.egg folder in the Python27/Lib/site-packages folder.
For Windows, install pip. You'll probably need other packages later on, so it will pay off to have a proper package manager.
Here is the documentation: https://pip.pypa.io/en/latest/index.html
You might actually be missing certifi module.
Overview:
From your error stack trace, it appears that you are using Windows platform and have the native windows Python installation. So I will stick to Windows instructions here. But since I have Cygwin based python installation, I will provide here cygwin-based steps to resolve your issue.
However, you can very easily use these steps on the Windows command prompt as well, by installing pip or easy_install, pre-built binary, or source code.
Windows-Cygwin-Pip way:
Add the directory that hosts python executable to your environment's PATH variable. Instructions here
Get pip to easily install new python packages. Best way is to download get-pip.py in cygwin’s home directory and run python get-pip.py in cygwin bash shell command prompt. Detailed and Alternative instructions here
Run pip install requests in the cygwin bash shell. It will install requests and certifi packages, which results in results, requests-2.4.0.dist-info, certifi, and certifi-14.05.14-py2.7.egg-info in the /lib/site-packages folder.
Run python and execute your original line of code import requests. It will run without errors.
Alternatives Ways to Installing a New Package:
There are several other alternatives of downloading this requests package, or for that matter any new python package. These include:
Getting easy_install in Cygwin and Running easy_install requests. Get easy_install in cygwin by installing setuptools package or by following instructions here.
Downloading a pre-built binary available here. And running it as executable. It will automatically install the module under the latest python installation available in windows registry.
Downloading source code for requests from Github into the home directory and Running python setup.py install
Python-Requests Installation Doc:
There is a brief list of ways to install requests available on the original python-requests project website as well. See here.
For a more productive environment and saving lots of headaches, follow these steps:
Install virtualenv
Install virtualenvwrapper
Always manage your environments with virtualenvwrapper
Always use pip to install dependencies inside your virtual environment
Use 'pip freeze --local' to see what's installed or to produce a requirements.txt file (pip freeze --local > requirements.txt )
If you have no idea what I'm talking about, you should spend some time reading up on these things, and you'll discover one of the many things that makes python so nice to work with (well, ok other programming languages have similar tools)

Categories

Resources