我有一个小型Flask应用程序,我在其中将entry_point
的setup.py定义为:
entry_points={
'console_scripts': ['myapp = myapp.__main__:main']
},
我的app.py
文件如下:
app = Flask(__name__)
# ... All my views here
if __name__ == '__main__':
app.run(
port=int(os.environ.get('PORT', 8000)),
debug=True)
如果我将应用程序作为PORT=9000 python myapp/app.py
运行,我可以通过localhost:9000正确访问应用程序。但是我想在entry_point中做同样的事情,它指向我的__main__.py
文件:
import os
from dragoman.app import app
if __name__ == '__main__':
app.run(
port=int(os.environ.get('PORT', 8000)),
debug=True)
如果我尝试运行PORT=9000 myapp
时出现以下错误,则无法执行此操作:
File "/lib/python3.6/site-packages/werkzeug/serving.py", line 720, in run_simple
s.bind((hostname, port))
TypeError: an integer is required (got type str)
为什么它不能选择PORT
env变量,当我没有通过应用程序运行的ENV变量PORT
时,但是我没有在我指定的默认端口上传递8000但在Flask上默认为5000.同时运行PORT=7777 python -m myapp
在指定端口上运行完美。
我错过了什么?