0
from flask import Flask

app = Flask(__main__)

if __name__ == "__main__":
    app.run()

So this is my code and I don't think anything is wrong with it, I downloaded flask from pycharm and command prompt, but still doesnt work, could someone help?

The error:

[Errno 2] No such file or directory
furas
  • 134,197
  • 12
  • 106
  • 148
  • You should always show the error you are getting.. – moctarjallo Jul 28 '20 at 04:10
  • always put full error message (starting at word "Traceback") in question (not comment) as text (not screenshot). There are other useful information. – furas Jul 28 '20 at 05:12
  • what do you mean "downloaded flask from pycharm" ? `Flask` should be installed in Python (ie. using `pip install flask`) and there is no need to download it from PyCharm. – furas Jul 28 '20 at 05:14
  • If you have multiple versions of Python, make sure your Pycharm Project is set to use the interpreter where you installed `Flask` into. Unless - of course - you are using `venv`. – sal Jul 28 '20 at 05:20
  • im new to programming, does anybody have tips how to make it work? –  Jul 28 '20 at 05:45

1 Answers1

1

First thing first, your first line is wrong. You wrote app = Flask(main) instead of app= Flask(name_).

Also I would Add at least a Hello world. So try with this and see if it works:

from flask import Flask

app = Flask(__name__)

if __name__ == "__main__":
    app.run()

Is not really clear How you got this error. However because you are using Pycharm it may be because you have not configured the Pycharm's interpreter correctly?

Does this video solve your issue and can you confirm you have and interpreter? ---->

No python interpreter configured for the project pycharm

If this didn't solve your issue, then are you sure you are running the file correctly?

Alt+Shift+F10 and then select the script you want to run.

After that Shift+F10 will run the last script that has been run.

If also this didn't help then specify better your issue, add screenshot if needed. Also because if once you adjust the code still give you issue, is a Pycharm Configuration issue a not with the code itself

Federico Baù
  • 6,013
  • 5
  • 30
  • 38
  • now it gives me this error message: ImportError: cannot import name 'Flask' from partially initialized module 'flask' (most likely due to a circular import) –  Jul 28 '20 at 06:31
  • you probably named your flask file "flask", which unfortunately creates an error because the script will import itself. You need to change the filename of the file you're running, such as "flask_server.py" or something other than just "flask" – c8999c 3f964f64 Jul 28 '20 at 08:19
  • did @c8999c3f964f64 comment solve the issue? Just in case I invite you to look at this video by Miguel Grinberg : https://www.youtube.com/watch?v=NH-8oLHUyDc Also some other refference: -- How to avoid circular imports in a Flask app with Flask SQLAlchemy models?: https://stackoverflow.com/questions/48718768 -- Can I avoid circular imports in Flask and SQLAlchemy: https://stackoverflow.com/questions/42909816 – Federico Baù Jul 28 '20 at 11:52