ImportError: No module named _winreg
在Flask项目部署到linux上时出现了一个问题,但是在windows上是好的,没有问题。以下是bug
Traceback (most recent call last):
File "foodie.py", line 10, in <module>
app.run(debug=True)
File "/usr/local/lib/python2.7/dist-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 772, in run
run_simple(host, port, self, **options)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 622, in run_simple
reloader_type)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/_reloader.py", line 265, in run_with_reloader
reloader.run()
File "/usr/local/lib/python2.7/dist-packages/werkzeug/_reloader.py", line 155, in run
for filename in chain(_iter_module_files(), self.extra_files):
File "/usr/local/lib/python2.7/dist-packages/werkzeug/_reloader.py", line 70, in _iter_module_files
for package_path in getattr(module, '__path__', ()):
File "/usr/lib/python2.7/dist-packages/six.py", line 116, in __getattr__
_module = self._resolve()
File "/usr/lib/python2.7/dist-packages/six.py", line 105, in _resolve
return _import_module(self.mod)
File "/usr/lib/python2.7/dist-packages/six.py", line 76, in _import_module
__import__(name)
ImportError: No module named _winreg
本以为是第三方库没有安装正确,重装了还是出现了问题。
网上给出了方法是修改
/usr/lib/python2.7/dist-packages/six.py
将__getattr__函数中
if (attr in ("__file__", "__name__", "__path__") and self.mod not in sys.modules):
raise AttributeError
_module = self._resolve()
改为
if (attr in ("__file__", "__name__", "__path__") and self.mod not in sys.modules):
raise AttributeError(attr)
try:
_module = self._resolve()
except ImportError:
raise AttributeError(attr)
问题解决
链接
https://bitbucket.org/gutworth/six/commits/e914c4c89b073b7eacb440a8bf456dd1d28018ba
http://stackoverflow.com/questions/11133506/importerror-while-importing-winreg-module-of-python