Import Error: Google Analytics API Authorization

老子叫甜甜 提交于 2019-12-04 02:56:17

It seems oauth2client installation is unsuccessful. Try

pip install --upgrade google-api-python-client

Blairg23

Installing pyopenssl fixed the issue for me:

pip install pyopenssl

Based on this answer.

I had similar issues where I was getting cannot import name xxxx error. It turn out I had old *.pyc files in my environment from an older oauth2client version. Even though I updated to the lastest oauth2client version, the *.pyc files were getting used when I tried to run. I simply deleted the oauth2client *.pyc files and then reran my program without any issues.

Even if you upgrade to use the latest google-api-python-client... you'll want to make sure any *.pyc files from the old library have been removed.

I was able to fix the issue in python3.

My python packages were a little bit messy and broken, because I was using python2 (being default one) and python3 and I was not using virtualenv. My os was Debian GNU/Linux 8 (jessie). I had exactcly the same issue:

ImportError: cannot import name ServiceAccountCredentials

Before I have fixed it, my packages were like this in python3:

Python 3.4.2 (default, Feb  7 2019, 06:08:06)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import oauth2client
>>> oauth2client.__version__
'1.5.2'

I had to uninstall every pip installation:

sudo pip uninstall pip
sudo pip3 uninstall pip
sudo python -m pip uninstall pip
sudo python3 -m pip uninstall pip

I had to install pip3 with easy_install:

sudo easy_install3 pip

I had also to uninstall oauth2client:

sudo pip3 uninstall oauth2client

It also turned out there was some files under ~/.local/lib/python3.4/site-packages/oauth2client/ in my home directory, so I executed the following command from my current user (not root) to delete the directory:

rm -rf ~/.local/lib/python3.4/site-packages/oauth2client*

I have installed oauth2client:

sudo pip3 uninstall oauth2client

After that the issue was resolved. Please note that while it was resolved on my local system, the other systems might need different solution (for example, python temporary files might be in a different path). However, the main approach is to have only 1 pip module, 1 oauth2client installation and be sure that there are no conflicting or temporary files that might affect current python3 environment.

Python 3.4.2 (default, Feb  7 2019, 06:08:06)
[GCC 4.9.2] on linux
>>> import oauth2client
>>> oauth2client.__version__
'4.1.2'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!