0
我試圖將我的項目轉換爲python3。不能「導入urllib.request,urllib.parse,urllib.error」
我的服務器腳本是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()
但是當我嘗試:
import urllib.request, urllib.parse, urllib.error
我得到這個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
我該怎麼做?
你確定你想在Python 3運行的代碼,而不是Python的2? –
只需檢查 - 「python3 -V」顯示什麼? –
對不起。我犯了一個錯誤。我運行'python3 ./server.py',但我在使用python2的編輯器上測試過。 – Bonn