Repository navigation
Error running "from google.cloud import storage" command #4039
Description
Thank you for reporting an issue to google-cloud-python!
If you are reporting an issue or requesting a feature, please search the
existing open and closed issues to see if there is already work being done.
- https://github.com/GoogleCloudPlatform/google-cloud-python/issues
- http://stackoverflow.com/questions/tagged/google-cloud-python
If you can provide us with as much of the following information as possible it
will help us identify the cause of your issue more quickly.
Hello, I'm hoping you can help. I'm trying to run the Python Client Library for Google Compute and running into issues. See below for my information. Thanks for any help you can provide.
1. OS type and version
$ cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)
2. Python version and virtual environment information python --version
$ python3 -V
Python 3.4.5
3. google-cloud-python version pip show google-cloud, pip show google-<service> or pip freeze
$ pip3 freeze | grep ^google
google-auth==1.1.1
google-cloud==0.27.0
google-cloud-bigquery==0.26.0
google-cloud-bigtable==0.26.0
google-cloud-core==0.26.0
google-cloud-datastore==1.2.0
google-cloud-dns==0.26.0
google-cloud-error-reporting==0.26.0
google-cloud-language==0.27.0
google-cloud-logging==1.2.0
google-cloud-monitoring==0.26.0
google-cloud-pubsub==0.27.0
google-cloud-resource-manager==0.26.0
google-cloud-runtimeconfig==0.26.0
google-cloud-spanner==0.26.0
google-cloud-speech==0.28.0
google-cloud-storage==1.3.2
google-cloud-translate==1.1.0
google-cloud-videointelligence==0.25.0
google-cloud-vision==0.26.0
google-gax==0.15.15
google-resumable-media==0.2.3
googleapis-common-protos==1.5.2
4. Stacktrace if available
- See below
5. Steps to reproduce
- from a fresh CentOS 7 VM in Google Compute, I ran the following commands:
sudo yum -y install epel-release
sudo yum -y install python34
sudo yum -y install python34-devel
sudo yum -y install python34-setuptools
sudo python3 /usr/lib/python3.4/site-packages/easy_install.py pip
sudo pip3 install --upgrade pip
pip3 install --upgrade google-cloud
- from python IDLE, ran the following command:
from google.cloud import storage
- error received:
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python3.4/site-packages/google/cloud/storage/init.py", line 37, in
from google.cloud.storage.batch import Batch
File "/usr/lib/python3.4/site-packages/google/cloud/storage/batch.py", line 29, in
from google.cloud import _helpers
File "/usr/lib/python3.4/site-packages/google/cloud/_helpers.py", line 33, in
from google.protobuf import duration_pb2
ImportError: No module named 'google.protobuf'
6. Code example
N/A
Using GitHub flavored markdown can help make your request clearer.
See: https://guides.github.com/features/mastering-markdown/
Activity
lukesneeringer commentedon Sep 23, 2017
Is
protobufinstalled? (Your pip freeze command obscures this.)ep-tpat commentedon Sep 25, 2017
Hi Luke. Yes, protobuf seems to be installed:
$ pip3 freeze | egrep '^google|protobuf'
google-auth==1.1.1
google-cloud==0.27.0
google-cloud-bigquery==0.26.0
google-cloud-bigtable==0.26.0
google-cloud-core==0.26.0
google-cloud-datastore==1.2.0
google-cloud-dns==0.26.0
google-cloud-error-reporting==0.26.0
google-cloud-language==0.27.0
google-cloud-logging==1.2.0
google-cloud-monitoring==0.26.0
google-cloud-pubsub==0.27.0
google-cloud-resource-manager==0.26.0
google-cloud-runtimeconfig==0.26.0
google-cloud-spanner==0.26.0
google-cloud-speech==0.28.0
google-cloud-storage==1.3.2
google-cloud-translate==1.1.0
google-cloud-videointelligence==0.25.0
google-cloud-vision==0.26.0
google-gax==0.15.15
google-resumable-media==0.2.3
googleapis-common-protos==1.5.2
protobuf==3.4.0
$ python3
Python 3.4.5 (default, May 29 2017, 15:17:55)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
lukesneeringer commentedon Sep 27, 2017
Hmm. I just tried on my machine with a new virtualenv and was successful.
Are you able to import
google.protobufdirectly? (Just trying to think of things to eliminate.)dhermes commentedon Sep 27, 2017
We've seen this issue quite a lot and it's almost always caused by a "bad" install, i.e. one where the correct
.pthfiles don't get created.@ep-tpat Try installing into a
virtualenv, so you can verify the install works. Then from your global install (i.e./usr/lib/python3.4/site-packages) you can work on fixing the issue. (Usually justpip install --ignore-installed protobufwill work.)I am pre-emptively closing this since it's not an issue in our code (i.e. we can install it on lots of different machines) and it's a common issue we've seen with
pipusage in the wild. I'm happy to re-open if this turns out to be something else.Feel free to keep asking questions in this issue though, we're happy to help.
ep-tpat commentedon Sep 28, 2017
Thanks for the help, guys. After installing virtualenv, it worked perfectly. So....any chance you can point me in the right direction to get the issue ironed out not using virtualenv? This was a freshly spun up Google VM running CentOS 7. I didn't do anything else to it other than install Python3, Pip and Google Cloud. Also note, I'm new to Python (only about 2-3 months). Commands below:
sudo yum -y install epel-release
sudo yum -y install python34
sudo yum -y install python34-devel
sudo yum -y install python34-setuptools
sudo python3 /usr/lib/python3.4/site-packages/easy_install.py pip
sudo pip3 install --upgrade pip
pip3 install --upgrade google-cloud
Thanks for any help you can offer.
dhermes commentedon Sep 28, 2017
@ep-tpat
pyenv/virtualenvreally are good optionspip install --ignore-installed protobuf(will need to be withsudoif you use theyuminstalled Python)?import googleand print outgoogle.__path__, it should give you an idea of where it is installed.site-packages(e.g. I see.../site-packages/protobuf-3.4.0-py3.4-nspkg.pth, but I want that there, i.e. it isn't bad / dangling from an uninstalled package)google, but you didn't expect to be there (just ``.../site-packages/google/`).ep-tpat commentedon Sep 28, 2017
@dhermes
I'll stick with your first point. If virtualenv is a good option then I'll just move forward with that. Thanks for everyone's help!
rsmith49 commentedon Oct 31, 2017
@dhermes I'm also running into this problem (but with google-cloud-language), not sure if I should make a new issue or just continue on this thread.
OS Type and Version
Using AWS Elastic Beanstalk, EC2 instance with:
Amazon Linux AMI release 2017.03
Python Version and Virtual Environment Info
Python 3.4.3
Not sure what virtualenv version the EC2 instance is running, Elastic Beanstalk creates its own virtual environments on application deployment
google-cloud-python version
Current
pip freezeoutput:Previously had been using:
which worked fine, but now need to upgrade to the latest
google-cloud-languageversion, and theprotobuf==3.0.0b2.post2workaround is too outdated to work with the latest version.Stacktrace
Steps to Reproduce
Since Elastic Beanstalk automatically installs packages on deployment, I have been ssh'ing into the EC2 instance, running
source /opt/python/run/venv/lib/activate, and playing around with different combinations/versions of installingprotobufandgoogle-cloud-language.I have also tried uninstalling all packages and reinstalling using
--ignore-installed, which also did not work (same error):dhermes commentedon Oct 31, 2017
@ep-tpat That is quite a lot of packages! Part of the problem may also be that we don't support Python 3.4, so there may be some unknown issues. What exactly does
protobuf==3.0.0b2.post2work around?In addition to uninstalling and reinstalling using
--ignore-installed, you should for path files (/opt/python/run/venv/local/lib/python3.4/site-packages/*pth) that seem out of place. Thisgooglepackage confusion can happen if there is a mix of installed eggs (you don't want any when dealing with namespace packages) and "normal" (i.e.pip install-ed) packages.rsmith49 commentedon Oct 31, 2017
@dhermes Not sure what Issue I was reading, but I came across a potential fix where setting the protobuf version to
3.0.0b2.post2solved the problem, so I had been using that for the past few months. However, I guess the latestgoogle-cloud-languageversion needs a later version of protobuf.As far as files that seem out of place, do you have any suggestions on what to look out for? I am not that familiar with the package dependency structure used by pip/python
rsmith49 commentedon Oct 31, 2017
Here is the output of
ls /opt/python/run/venv/local/lib/python3.4/site-packages/*pthdhermes commentedon Oct 31, 2017
When you uninstall, just make sure all the
.pthfiles are deleted too. (The "bad" one is usually justeasy-install.pthwhen a namespace package comes in as part of an egg.) Similarly, you may want to delete any "dist info" or.eggfiles that don't seem to belong.I can confirm the issue isn't Python 3.4 (at least for installing and importing):
rsmith49 commentedon Nov 8, 2017
Apparently the issue had to do with Amazon Linux AMI causing pip to import some packages to
venv/lib/python3.4/site-packages/and some tovenv/lib64/python3.4/site-packages, which I expect then caused problems because thegoogle/cloudmodules were underliband thegoogle/protobufmodule was underlib64.Here is a relevant link tracking the issue for pip, just in case anyone else runs into this issue with AWS EC2 instances: pypa/pip#4464, and I solved this by including:
as container commands in
.ebextensionsharshit0605 commentedon Jun 14, 2018
Hi,
I am not able to import google.cloud.vision package in python. The stack trace is given below:
Please help me out.
tseaver commentedon Jun 14, 2018
@harshitHadoop You've tagged onto a closed (and not exactly related) issue here. Please open a new issue, including showing the version of Python, how you've installed
google-cloud-vision, etc.chore: move samples from python-docs-sample (#33)
Update dependency google-cloud-pubsub to v1.6.0 [(#4039)](GoogleCloud…
Update dependency google-cloud-pubsub to v1.6.0 [(#4039)](GoogleCloud…
samples: add samples from pubsub/cloud-client (#134)
Update dependency google-cloud-pubsub to v1.6.0 [(#4039)](GoogleCloud…
samples: add cloud client samples from python-docs-samples (#626)