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