skip to Main Content

I got this error today;
previously I didn’t get that.
My python file is in "C:UsersHDownloadsHossein-OHVSCODEPYTHON APImain.py"
and this is the documentation👇👇👇

from flask import Flask, Request, jsonify

app = Flask(__name__)

@app.route("/")
def home():
    return "Home"

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

I tried to run my code in VScode terminal with "python main.py"
but I got this error:

can’t open file ‘C:UsersHDownloadsHossein-OHVSCODEmain.py’: [Errno 2] No such file or directory

2

Answers


  1. The reason might be the two paths you show do not match:

    • C:UsersHDownloadsHossein-OHVSCODEPYTHONAPImain.py
    • C:UsersHDownloadsHossein-OHVSCODEmain.py
    Login or Signup to reply.
  2. When you manually execute commands to run python scripts in the terminal, you need to check the folder path in the terminal.

    I think when you execute the script, your terminal is at C:UsersHDownloadsHossein-OHVSCODE.

    You need to execute command cd PYTHON API. So it can find the main.py file you need.

    Another solution is to use Run Python File Command provided by Python extension.

    You could open your Settings and search for Executr In File Dir then check it. It’ll allow you run python script in the file’s directory instead of the workspce.

    enter image description here

    Then use Run Python File button.

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search