Unable to install certain python modules

I’m trying to follow a tutorial about creating and hosting an HTTP proxy. When I try to install the modules, it fails. (SimpleHTTPServer and SocketServer)

Tutorial used: https://levelup.gitconnected.com/how-to-build-a-super-simple-http-proxy-in-python-in-just-17-lines-of-code-a1a09192be00

Output:

pip install SimpleHTTPServer

ERROR: Could not find a version that satisfies the requirement SimpleHTTPServer (from versions: none)
ERROR: No matching distribution found for SimpleHTTPServer
pip install SocketServer

ERROR: Could not find a version that satisfies the requirement SocketServer (from versions: none)
ERROR: No matching distribution found for SocketServer

When I try to run the program:

Traceback (most recent call last):
  File "simpleServer.py", line 1, in <module>
    import SocketServer
ModuleNotFoundError: No module named 'SocketServer'

>Solution :

Those are standard library’s modules as LeopardShark mentioned. You can import them directly to your code without installing them with pip.

The complete list of modules coming with standard library you can find here: https://docs.python.org/3/library/

Also, the specific modules you’re asking about were renamed in Python3:

Note The SimpleHTTPServer module has been merged into http.server in Python 3.

Based on module’s documentation: https://docs.python.org/2/library/simplehttpserver.html

Basically, you just need to do:

import http.server
import socketserver

Leave a Reply