1

I am learning Flask and first to use PyCharm.

Here is the template code:

from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
    return 'Hello World!'
if __name__ == '__main__':
    app.run()

When i click to run, Here is the Error Info:

Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/jzd/Movies/flask/Three_pyCharm/venv/lib/python3.6/site-packages/flask/__main__.py", line 14, in <module>
    main(as_module=True)
  File "/Users/jzd/Movies/flask/Three_pyCharm/venv/lib/python3.6/site-packages/flask/cli.py", line 894, in main
    cli.main(args=args, prog_name=name)
  File "/Users/jzd/Movies/flask/Three_pyCharm/venv/lib/python3.6/site-packages/flask/cli.py", line 557, in main
    return super(FlaskGroup, self).main(*args, **kwargs)
  File "/Users/jzd/Movies/flask/Three_pyCharm/venv/lib/python3.6/site-packages/click/core.py", line 676, in main
    _verify_python3_env()
  File "/Users/jzd/Movies/flask/Three_pyCharm/venv/lib/python3.6/site-packages/click/_unicodefun.py", line 118, in _verify_python3_env
    'for mitigation steps.' + extra)
RuntimeError: Click will abort further execution because Python 3 was configured to use ASCII as encoding for the environment.  Consult http://click.pocoo.org/python3/for mitigation steps.

This system lists a couple of UTF-8 supporting locales that
you can pick from.  The following suitable locales where
discovered: af_ZA.UTF-8, am_ET.UTF-8, be_BY.UTF-8, bg_BG.UTF-8, ca_ES.UTF-8, cs_CZ.UTF-8, da_DK.UTF-8, de_AT.UTF-8, de_CH.UTF-8, de_DE.UTF-8, el_GR.UTF-8, en_AU.UTF-8, en_CA.UTF-8, en_GB.UTF-8, en_IE.UTF-8, en_NZ.UTF-8, en_US.UTF-8, es_ES.UTF-8, et_EE.UTF-8, eu_ES.UTF-8, fi_FI.UTF-8, fr_BE.UTF-8, fr_CA.UTF-8, fr_CH.UTF-8, fr_FR.UTF-8, he_IL.UTF-8, hr_HR.UTF-8, hu_HU.UTF-8, hy_AM.UTF-8, is_IS.UTF-8, it_CH.UTF-8, it_IT.UTF-8, ja_JP.UTF-8, kk_KZ.UTF-8, ko_KR.UTF-8, lt_LT.UTF-8, nl_BE.UTF-8, nl_NL.UTF-8, no_NO.UTF-8, pl_PL.UTF-8, pt_BR.UTF-8, pt_PT.UTF-8, ro_RO.UTF-8, ru_RU.UTF-8, sk_SK.UTF-8, sl_SI.UTF-8, sr_YU.UTF-8, sv_SE.UTF-8, tr_TR.UTF-8, uk_UA.UTF-8, zh_CN.UTF-8, zh_HK.UTF-8, zh_TW.UTF-8

I think the line is important.

RuntimeError: Click will abort further execution because Python 3 was configured to use ASCII as encoding for the environment.

I find the answer Click will abort further execution because Python 3 was configured to use ASCII as encoding for the environment .

While still not to know how to fix it.

Instructions is very needed, which is easy to follow .

dengApro
  • 3,848
  • 2
  • 27
  • 41
  • 1
    Have you tried putting `# coding: utf8` at the beginning of your file (first line)? – Thibault D. Jul 05 '18 at 12:13
  • Combine with @Nipun Sampath's answer , it works. – dengApro Jul 06 '18 at 04:48
  • 1
    FYI for those wondering "why python3 can error out because of something small like unset locale (i.e. env vars `LANG`, `LC_ALL`)" --> read [PEP 538](https://www.python.org/dev/peps/pep-0538/) and the related [PEP 540](https://www.python.org/dev/peps/pep-0540/). The error appears to only be an issue for python 3.0 to 3.6 because PEP 538 fixes the issues for python >= 3.7. – Trevor Boyd Smith Oct 18 '21 at 14:41
  • Does this answer your question? [Encoding issue with python3 and click package](https://stackoverflow.com/questions/32234393/encoding-issue-with-python3-and-click-package) – Trevor Boyd Smith Oct 18 '21 at 15:25
  • @Trevor Boyd Smith,it has been 3 years. I am not a python programmer any more – dengApro Oct 19 '21 at 01:21

1 Answers1

5

The Run/debug configurations can be opened from here.

enter image description here

There you can add the environment variable using this.(click the 3 dot icon next to the environment variables)

step two

dengApro
  • 3,848
  • 2
  • 27
  • 41
Nipun Thennakoon
  • 3,586
  • 1
  • 18
  • 26