22

I am trying to run the 'generate_refresh_token.py' file in the authentification folder of the AdWords API.

But when I do python generate_refresh_token.py as described in the documentation, I get the error ModuleNotFoundError: No module named 'google_auth_oauthlib'.

So I try to install the module with pip install google-auth-oauthlib, and here is the output:

Requirement already satisfied: google-auth-oauthlib in /home/$USER/anaconda3/lib/python3.6/site-packages (0.2.0)

I activate my anaconda3 environment by doing source activate /home/$USER/anaconda3/envs/$environment_name. I try to generate the token again with the command above, same error.

Could not find any useful answer or anyone having the same issue with this module. Does anyone have a suggestion I could try?

UPDATE: I have found the error. When I installed the google-auth-oauthlib module via pip, it was installed as a module in the anaconda3 library. But when I run python from the command line, it uses the version from my system, which doesn't have this module.

Thomas
  • 422
  • 1
  • 4
  • 12

5 Answers5

28

I had the same issue. Was resolved by using:

sudo pip install google-auth-oauthlib

the sudo was necessary, not sure why, maybe someone else can eleborate.

Tyler Tresslar
  • 383
  • 3
  • 6
  • 4
    Just an update. Don't use sudo with pip...bad practice there are a bunch of SO threads out there about why you shouldn't. Basically, best practice is to use pip --user – Tyler Tresslar Jan 18 '20 at 02:30
  • 2
    Check if it works with just ´pip install --user google-auth-oauthlib`. Do NOT use sudo with pip as you are almost certain to duck your python dist to smithereens. – Jakob Guldberg Aaes Jul 21 '20 at 06:48
11

If you use conda instead of pip:

conda install google-auth google-auth-oauthlib
hobs
  • 18,473
  • 10
  • 83
  • 106
  • 1
    This one worked like a charm. In my case conda was already installed, if anyone has it installed too, this method seemed to work better for me than the pip method. – Brookie_C Oct 15 '21 at 19:18
5

I have found the error. When I installed the google-auth-oauthlib module via pip, it was installed as a module in the anaconda3 library. But when I run python from the command line, it uses the version from my system, which doesn't have this module.

Thomas
  • 422
  • 1
  • 4
  • 12
4

I was in a situation where installing using pip install google-auth-oauthlib worked, but I was still seeing ModuleNotFoundError you mention above.

I tried the approach of installing via sudo pip install google-auth-oauthlib. That didn't work, and I kept seeing ModuleNotFoundError: No module named 'pip._internal.cli.main.

If anyone else is in the same boat, I was able to successfully install using pip3 install google-auth-oauthlib (oddly enough, pip3 and pip both point to the same location for me: pip 21.2.4).

Dharman
  • 30,962
  • 25
  • 85
  • 135
scrollex
  • 2,575
  • 7
  • 24
  • 38
0

Activate your virtual environment and install the module there.It will works

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 23 '22 at 16:53