Python 3.4 ImportError when in debug mode
I created a python3.4 virtualenv in which I installed flask, after that I created an application like so:
testcase
├── http.py
└── __init__.py
http.py contains:
from flask import Flask
app = Flask(__name__)
app.debug = True
if __name__ == "__main__":
app.run()
When debug is turned on on the application the following error occurs. If I have to take a wild guess it has to do with autoreloading and the fact that a module inside the testcase package is called http.py.
(env3.4) λ testcase → python -m testcase.http
* Running on http://127.0.0.1:5000/
* Restarting with reloader
Traceback (most recent call last):
File "/home/simon/src/testcase/env3.4/lib/python3.4/site-packages/werkzeug/http.py", line 26, in <module>
from urllib2 import parse_http_list as _parse_list_header
ImportError: No module named 'urllib2'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/simon/src/testcase/testcase/http.py", line 1, in <module>
from flask import Flask
File "/home/simon/src/testcase/env3.4/lib/python3.4/site-packages/flask/__init__.py", line 17, in <module>
from werkzeug.exceptions import abort
File "/home/simon/src/testcase/env3.4/lib/python3.4/site-packages/werkzeug/__init__.py", line 154, in <module>
__import__('werkzeug.exceptions')
File "/home/simon/src/testcase/env3.4/lib/python3.4/site-packages/werkzeug/exceptions.py", line 71, in <module>
from werkzeug.wrappers import Response
File "/home/simon/src/testcase/env3.4/lib/python3.4/site-packages/werkzeug/wrappers.py", line 26, in <module>
from werkzeug.http import HTTP_STATUS_CODES, \
File "/home/simon/src/testcase/env3.4/lib/python3.4/site-packages/werkzeug/http.py", line 28, in <module>
from urllib.request import parse_http_list as _parse_list_header
File "/usr/lib/python3.4/urllib/request.py", line 88, in <module>
import http.client
File "/home/simon/src/testcase/testcase/http.py", line 1, in <module>
from flask import Flask
ImportError: cannot import name 'Flask'
You appear to have an old version of Werkzeug installed. The ImportError in werkzeug.http should've been catched as of version 0.9.
Please do
pip install --upgrade werkzeug
inside your virtualenv.
Closing this because of inactivity.
still get this error with 0.14.1 with python version 3.6
Closed by #1416