Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第一章 page14页,运行不了程序, #34

Closed
wheatekzp opened this issue Sep 28, 2018 · 3 comments
Closed

第一章 page14页,运行不了程序, #34

wheatekzp opened this issue Sep 28, 2018 · 3 comments

Comments

@wheatekzp
Copy link

c:\helloflask>pipenv shell
Launching subshell in virtual environment鈥?Microsoft Wind
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。

(helloflask-_7dot6hq) c:\helloflask>cd demos\hello

(helloflask-_7dot6hq) c:\helloflask\demos\hello>flask run

之后就报错,如下:

  • Environment: development

  • Debug mode: on

  • Restarting with stat
    Traceback (most recent call last):
    File "C:\ProgramData\Anaconda2\Lib\runpy.py", line 1

    "main", fname, loader, pkg_name)
    File "C:\ProgramData\Anaconda2\Lib\runpy.py", line 7
    exec code in run_globals
    File "C:\Users\Administrator.virtualenvs\helloflask
    e_main_.py", line 9, in
    File "c:\users\administrator.virtualenvs\helloflask
    s\flask\cli.py", line 894, in main
    cli.main(args=args, prog_name=name)
    File "c:\users\administrator.virtualenvs\helloflask
    s\flask\cli.py", line 557, in main
    return super(FlaskGroup, self).main(*args, **kwarg
    File "c:\users\administrator.virtualenvs\helloflask
    s\click\core.py", line 697, in main
    rv = self.invoke(ctx)
    File "c:\users\administrator.virtualenvs\helloflask
    s\click\core.py", line 1066, in invoke
    return process_result(sub_ctx.command.invoke(sub
    File "c:\users\administrator.virtualenvs\helloflask
    s\click\core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
    File "c:\users\administrator.virtualenvs\helloflask
    s\click\core.py", line 535, in invoke
    return callback(*args, **kwargs)
    File "c:\users\administrator.virtualenvs\helloflask
    s\click\decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args[1:], **kwargs)
    File "c:\users\administrator.virtualenvs\helloflask
    s\click\core.py", line 535, in invoke
    return callback(*args, **kwargs)
    File "c:\users\administrator.virtualenvs\helloflask
    s\flask\cli.py", line 771, in run_command
    threaded=with_threads, ssl_context=cert)
    File "c:\users\administrator.virtualenvs\helloflask
    s\werkzeug\serving.py", line 812, in run_simple
    reloader_type)
    File "c:\users\administrator.virtualenvs\helloflask
    s\werkzeug_reloader.py", line 275, in run_with_reload
    sys.exit(reloader.restart_with_reloader())
    File "c:\users\administrator.virtualenvs\helloflask
    s\werkzeug_reloader.py", line 132, in restart_with_re
    close_fds=False)
    File "C:\ProgramData\Anaconda2\Lib\subprocess.py", l
    return Popen(*popenargs, **kwargs).wait()
    File "C:\ProgramData\Anaconda2\Lib\subprocess.py", l
    errread, errwrite)
    File "C:\ProgramData\Anaconda2\Lib\subprocess.py", l

    startupinfo)
    TypeError: environment can only contain strings

有时候会报这个错误,如下:

(helloflask-_7dot6hq) c:\helloflask>cd demos\hell

(helloflask-_7dot6hq) c:\helloflask\demos\hello>fl
Usage: flask run [OPTIONS]

Error: Could not locate Flask application. You did
ironment variable.

For more information see http://flask.pocoo.org/do

折腾了几个小时,就是运行不了- -
python版本:Python 2.7.14 |Anaconda custom (64-bit)| (default, Mar 27 2018, 12:30:5
.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
win7系统

@greyli
Copy link
Owner

greyli commented Sep 29, 2018

第一个错误是因为0.14版本的Werkzeug在Windows下有一个bug,目前临时的解决方法是注释掉.flaskenv文件的FLASK_ENV定义那行:

FLASK_APP=sayhello
# FLASK_ENV=development

不过这会导致没法开启调试模式。替代的方法是修改 python-dotenv 源码,具体可以参考这里
第二个错误描述不全,不太好判断。

@greyli
Copy link
Owner

greyli commented Dec 5, 2018

先关闭了,有问题可以继续评论或重开。

@greyli greyli closed this as completed Dec 5, 2018
@greyli
Copy link
Owner

greyli commented Dec 5, 2018

python-dotenv 发布新版本了,使用下面的命令更新即可解决第一个问题:

$ pip install -U python-dotenv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants