问题
I trying to convert my project to python3.
My server script is server.py:
#!/usr/bin/env python
#-*-coding:utf8-*-
import http.server
import os, sys
server = http.server.HTTPServer
handler = http.server.CGIHTTPRequestHandler
server_address = ("", 8080)
#handler.cgi_directories = [""]
httpd = server(server_address, handler)
httpd.serve_forever()
But when I try:
import urllib.request, urllib.parse, urllib.error
I get this in terminal of python3 ./server.py:
import urllib.request, urllib.parse, urllib.error
ImportError: No module named request
127.0.0.1 - - [18/Sep/2016 22:47:18] CGI script exit status 0x100
How can I do this?
回答1:
Your shebang suggests that code should be run by python
binary, which is historically associated with Python 2.x releases.
Simply change first line to:
#!/usr/bin/env python3
来源:https://stackoverflow.com/questions/39559384/cant-import-urllib-request-urllib-parse-urllib-error