dushkin
dushkin

Reputation: 2111

Flask on PyCharm - ImportError: attempted relative import with no known parent package

I am trying to create and run a simple flask server on PyCharm community 2019.3

I work with python 3.7. I used venv to create the project. Flask was installed like this:

(venv) pip install flask

from the pycharm terminal on c:\Users\Damo\PycharmProjects\myflaskproj\venv\Lib\site-packages\flask\

In the Edit configuration I created a new python run configuration.

I used the above path as my script path and set "run" as the parameters.

I added FLASK_APP=myflaskproj.py to the environment parameters. Finally I set C:\Users\Damo\PycharmProjects\myflaskproj as my working directory.

enter image description here

When I run the project, I get :

C:\Users\Damo\PycharmProjects\myflaskproj\venv\Scripts\python.exe C:/Users/Damo/PycharmProjects/myflaskproj/venv/Lib/site-packages/flask run
Traceback (most recent call last):
  File "c:\Users\Damo\AppData\Local\Programs\Python\Python37-32\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\Users\Damo\AppData\Local\Programs\Python\Python37-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:/Users/Damo/PycharmProjects/myflaskproj/venv/Lib/site-packages/flask\__main__.py", line 13, in <module>
    from .cli import main
ImportError: attempted relative import with no known parent package

Where do I go wrong?

Thanks

Upvotes: 1

Views: 919

Answers (1)

dushkin
dushkin

Reputation: 2111

This is the complete answer...

Running flask server configuration for PyCharm

Upvotes: 1

Related Questions