0

I have some old code I'm trying to use which uses httplib2 Python lib. The same exact code works fine on Linux (e.g. Raspberry Pi).

I have used pip to uninstall the httplib2 lib and pip3 to re-install.

Here's what "pip list" (or "pip3 list") shows:

C:\Users\g7847>pip list
Package                 Version
----------------------- ---------
bcrypt                  3.2.0
cachetools              4.2.4
certifi                 2021.5.30
cffi                    1.15.0
chardet                 4.0.0
cryptography            36.0.0
cycler                  0.10.0
google-auth             2.3.3
google-auth-httplib2    0.1.0
httplib2                0.20.2
idna                    2.10
kiwisolver              1.3.1
matplotlib              3.4.2
numpy                   1.21.0
paramiko                2.8.1
Pillow                  8.3.1
pip                     21.3.1
pyasn1                  0.4.8
pyasn1-modules          0.2.8
pycparser               2.21
PyNaCl                  1.4.0
pyparsing               2.4.7
python-dateutil         2.8.2
requests                2.25.1
requests-http-signature 0.2.0
rsa                     4.8
setuptools              57.1.0
six                     1.16.0
urllib3                 1.26.6
wheel                   0.36.2

C:\Users\g7847>

and yet:

C:\Users\g7847>python3 sshConnect.py
Traceback (most recent call last):
  File "C:\Users\g7847\sshConnect.py", line 12, in <module>
    import httplib2 
ModuleNotFoundError: No module named 'httplib2 '

This is the import section at the beginning. The only library that is complained about is httlib2.

import json
import time
import subprocess
import datetime
import base64
import sys
import os
import getpass
import errno
import re
import string
import httplib2
Digital Larry
  • 21
  • 1
  • 3

3 Answers3

1

pip and pip3 are not the same.

pip will use one of your Python versions depending on what exactly is first in the system PATH variable, whereas with pip3 you can be sure that the module will be installed in python3 library.

So, could you double check if the module is actually installed in the python3 library ?

If the module really is installed in python3 library, you could check if the PATH variable is correct. (You can check the PATH by using the following : Reference)

Toyeesh
  • 134
  • 6
0

The httplib2 library is part of the standard library in Python 3.

import httplib ImportError: No module named httplib

is it installed on version 2.x?

pip2 install httplib2
NeoTheNerd
  • 566
  • 3
  • 11
  • I only have pip and pip3, not pip2. – Digital Larry Dec 02 '21 at 20:27
  • I have python37 and python39 in my PATH. – Digital Larry Dec 02 '21 at 20:31
  • Run **`'httplib2' in sys.modules`** does it come back as **True**? – NeoTheNerd Dec 02 '21 at 20:37
  • 1
    @DigitalLarry That sounds like your problem. One of your pythons has pip and the packages installed. The other python doesn't. You should make sure which python you're using when you run python and pip. I would suggest using `python3 -m pip` and python3. That way they should be the same. – matt Dec 02 '21 at 20:46
  • **`python -m pip3 install httplib2`** - & set as environment variable for it. – NeoTheNerd Dec 02 '21 at 20:49
  • 1
    surprised **`import json`** does not error before **httplib2**. Its not in your pip list output.... – NeoTheNerd Dec 02 '21 at 20:52
  • I'm sorry but I'm not sure how to do that. I imported sys and ran sys.modules, it spits out a bunch of JSON holding a bunch of paths, I don't see httplib2 in there. – Digital Larry Dec 02 '21 at 20:57
  • All right thanks for the help, I think it may be best for me to unwind all of this. I had Python2 installed years ago and only use this stuff rarely. Really appreciate the help. – Digital Larry Dec 02 '21 at 20:58
  • OK, I uninstalled Python 3.7 and Python 3.9. Then I reinstalled Python 10 from Python.org, but attempts to run python3 took me to the Microsoft store to download and install python 3.9.9. So now I have 3.9.9. And I am now getting: C:\WINDOWS\system32>pip install httplib2 Requirement already satisfied: httplib2 in c:\users\garyw\appdata\local\programs\python\python39\lib\site-packages (0.20.2) Requirement already satisfied: pyparsing!=3.0.0,!=3.0.1,!=3.0.2,!=3.0.3,<4,>=2.4.2 in c:\users\garyw\appdata\local\programs\python\python39\lib\site-packages (from httplib2) (2.4.7) – Digital Larry Dec 02 '21 at 21:33
  • Sorry, I meant I attempted to install Python 3.10. Seems like the Windows part of making Python work is a little tougher than Linux. I'm searching the entire hard drive for "httplib2", and I've found a number of things, but I'm not 100% positive which is the actual library. Well, not true, I found a folder that actually has some py files in it. Still not sure why it is not found. – Digital Larry Dec 02 '21 at 21:42
-1

I still don't really know what was going on. I decided for other reasons to switch to the requests library rather than httplib2. My program runs OK inside Idle and I also made Windows EXE of it using pyinstaller on the command line. I thought I was having trouble running it directly as a Python program but I just checked it and it's fine.

One thing that MIGHT have been an issue is that I also have been using WSL (Ubuntu) in Windows and had installed httplib2 over there. I really don't know. I did uninstall that just in case but I'm not using httplib2 any more anyway.

There is a weird issue that happens if you run the Windows 3.9 installer from Python.org. If you subsequently try to run Python, then the Windows Store opens and you can't do anything except install that. So I uninstalled and reinstalled everything a few times but the last time it was just the Windows Store version as it seemed fairly insistent.

Digital Larry
  • 21
  • 1
  • 3