python - ImportError: No module named 'SocketServer' ?
阿神
阿神 2017-04-18 09:19:03
0
3
2412

使用pycharm建立flask工程后无法运行默认的hello world!模板,出现的错误:

图片不太清晰,补发一份文字版;

C:\Users\jowu\virtualEnvironment\Scripts\python.exe C:/Users/jowu/Desktop/PyWeb/PyWeb.py
Traceback (most recent call last):
  File "C:\Users\jowu\AppData\Local\Programs\Python\Python36\lib\site-packages\werkzeug\serving.py", line 65, in <module>
    from SocketServer import ThreadingMixIn, ForkingMixIn
ImportError: No module named 'SocketServer'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/jowu/Desktop/PyWeb/PyWeb.py", line 12, in <module>
    app.run()
  File "C:\Users\jowu\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 828, in run
    from werkzeug.serving import run_simple
  File "C:\Users\jowu\AppData\Local\Programs\Python\Python36\lib\site-packages\werkzeug\serving.py", line 68, in <module>
    from socketserver import ThreadingMixIn, ForkingMixIn
ImportError: cannot import name 'ForkingMixIn'

Process finished with exit code 1

python版本:3.6

pycharm 默认设置:

出现的问题是:ImportError: No module named 'SocketServer'

google之后发现可能是virtualenv没有配置好,但是尝试在Default setting中删除重新配置也还是出现同样的问题。ps.配置方法是根据pycharm文档来配置的。

以上,第一次提问,不到之处,还望海涵。望不吝赐教。

阿神
阿神

闭关修行中......

reply all(3)
大家讲道理

A bug by werkzeug.
https://github.com/pallets/we...
It is available after python36, use python35.

The answer below is wrong, because ./Python36/lib/site-packages/werkzeug/serving.py is written as follows:

try:
    from SocketServer import ThreadingMixIn, ForkingMixIn
    from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
except ImportError:
    from socketserver import ThreadingMixIn, ForkingMixIn
    from http.server import HTTPServer, BaseHTTPRequestHandler

So there is no case problem.

Peter_Zhu

After Python 3, the name of the SocketServer module changed to socketserver.
It is written in the NOTE at the beginning of the Python2.7 document:
SocketServer — A framework for network servers
I am using Python 2.7, so I have not tried it. It is recommended to change the name of the module and try again.

阿神

For this kind of problem, first enter virtualenv and type python directly on the command line. After entering, directly import SocketServer to see if it can be imported. If not, it must be that the name is wrong or the package is missing.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!