也许我做错了什么,但是在盯着代码1小时之后,我并没有变得更聪明。
我的问题在于我的virtualenv。我在我的主目录中设置了venv2和venv3作为文件夹。我和其他软件包一起安装了Flask。
问题是我无法从Flask运行HelloWorld-Example。
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World'
venv2示例:
(venv2) #( 7.09.16@14:11 )( dun@Arch64L ):~ which python
/home/dun/venv2/bin/python
(venv2) #( 7.09.16@14:12 )( dun@Arch64L ):~ which python3
/usr/bin/python3
(venv2) #( 7.09.16@14:12 )( dun@Arch64L ):~ which pip
/home/dun/venv2/bin/pip
(venv2) #( 7.09.16@14:12 )( dun@Arch64L ):~ cd _workspace/py/flask
(venv2) #( 7.09.16@14:12 )( dun@Arch64L ):~/_workspace/py/flask python2 helloworld.py
Traceback (most recent call last):
File "helloworld.py", line 1, in <module>
from flask import Flask
ImportError: cannot import name Flask
(venv2) #( 7.09.16@14:13 )( dun@Arch64L ):~/_workspace/py/flask pip list
click (6.6)
Flask (0.11.1)
itsdangerous (0.24)
Jinja2 (2.8)
MarkupSafe (0.23)
pip (8.1.2)
setuptools (26.1.1)
Werkzeug (0.11.11)
wheel (0.29.0)
(venv2) #( 7.09.16@14:13 )( dun@Arch64L ):~/_workspace/py/flask python2 helloworld.py
Traceback (most recent call last):
File "helloworld.py", line 1, in <module>
from flask import Flask
ImportError: cannot import name Flask
venv3示例:
(venv3) #( 7.09.16@14:10 )( dun@Arch64L ):~ which python
/home/dun/venv3/bin/python
(venv3) #( 7.09.16@14:10 )( dun@Arch64L ):~ which pip
/home/dun/venv3/bin/pip
(venv3) #( 7.09.16@14:10 )( dun@Arch64L ):~ pip list
click (6.6)
Django (1.10.1)
Flask (0.11.1)
itsdangerous (0.24)
Jinja2 (2.8)
MarkupSafe (0.23)
PasteDeploy (1.5.2)
pip (8.1.2)
pyramid (1.7.3)
repoze.lru (0.6)
setuptools (26.1.1)
translationstring (1.3)
venusian (1.0)
WebOb (1.6.1)
Werkzeug (0.11.11)
wheel (0.29.0)
zope.deprecation (4.1.2)
zope.interface (4.3.2)
(venv3) #( 7.09.16@14:10 )( dun@Arch64L ):~ cd _workspace/py/flask
(venv3) #( 7.09.16@14:11 )( dun@Arch64L ):~/_workspace/py/flask python helloworld.py
Traceback (most recent call last):
File "helloworld.py", line 1, in <module>
from flask import Flask
ImportError: cannot import name 'Flask'
答案 0 :(得分:0)
我没有看到您的文件结构,所以我无法确定,但如果您在同一文件夹中有一个名为flask.py
的文件,python将导入它而不是Flask模块
答案 1 :(得分:0)
我认为这就是答案:
if($stateParams.param1 == 'AFTER_SIGNUP'){
/* accountverify page */
}else{
/* login page */
}
在名字中使用下划线'_',python认为你想从你'烧瓶python helloworld'中导入烧瓶。