Maison  >  Questions et réponses  >  le corps du texte

python - ImportError: No module named 'SocketServer' ?

使用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文档来配置的。

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

阿神阿神2740 Il y a quelques jours2418

répondre à tous(3)je répondrai

  • 大家讲道理

    大家讲道理2017-04-18 09:21:03

    Un bug dans werkzeug.
    https://github.com/pallets/we...
    Il est disponible après python36, utilisez python35.

    La réponse ci-dessous est fausse car ./Python36/lib/site-packages/werkzeug/serving.py s'écrit comme suit :

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

    Il n'y a donc pas de problème de boîtier.

    répondre
    0
  • 天蓬老师

    天蓬老师2017-04-18 09:21:03

    Après Python 3, le nom du module SocketServer a été changé en socketserver.
    C'est écrit dans la NOTE au début du document Python2.7 :
    SocketServer — Un framework pour les serveurs réseau
    J'utilise Python 2.7, donc je ne l'ai pas essayé. Il est recommandé de changer. le nom du module. Réessayez plus tard.

    répondre
    0
  • 阿神

    阿神2017-04-18 09:21:03

    Pour ce genre de problème, entrez d'abord virtualenv et tapez python directement sur la ligne de commande. Après avoir entré, importez directement SocketServer pour voir s'il peut être importé. Sinon, il doit s'agir d'un nom erroné ou d'un package. manquant.

    répondre
    0
  • Annulerrépondre