Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Visual Studio Code keep changing the working directory?

I am trying to use VS Code to work my way through the "Flask Web Development" book. I can get the simple hello world example running from the command line but I want to use VS code for debugging etc. I modify the launch.json file to build a Flask config:

    "name": "Flask",
    "type": "python",
    "request": "launch",
    "module": "flask",
    "env": {
         "FLASK_APP": "flasker.py",
         "FLASK_ENV": "development",
         "FLASK_DEBUG": "0"
    },
   "args": [
       "run",
           "--no-debugger",
           "--no-reload"
       ],
       "jinja": true
    },

where flasker.py. is the name of my hello world type app. Every time I try to run it, or debug it, VS can not find the file. My dir structure is:

dev
    --pythonStuff
        --pythonClass
        --flask
              flasker.py

pythonClass is a dir/playground from a recent python class I took. The flask dir is where I'm currently working. Doing a pwd in the console always yields pythonClass. I'll cd to flasker, export FLASK_APP=flasker.py and FLASK_DEBUG=1 and then flask run and everything is good. But when I try to run the debugger, it's still pointing to pythonClass and can't find the flasker.py app. I did find a .vscode dir in the pythonClass dir, which has launch.json and settings.json files, but not sure how/why it was created there. Nothing magical in either file. I've googled every combination of flask cwd/pwd PATH I can think of. I know it's probably a simple fix, but can't seem to sort this out. Appreciate any guidance.

like image 875
GeoffWillis Avatar asked Dec 27 '25 22:12

GeoffWillis


1 Answers

A launch.json attributes list is supposed to include cwd (for "most debugger")

So try and add a cwd attributes, with the exact path you want, to check if that is respected.
For instance:

"cwd": "${workspaceFolder}",

The OP GeoffWillis adds in the comments:

Seems odd that when doing a 'pwd' in the VScode console, it always defaults to ~/pythonStuff/pythonClass even if I launch VScode from my "flasky" directory using the "code" alias.
As stated, I can cd in the console to my flasky dir, and run the code just fine, but want the debugger.
I'm using OSX 10.13.6 on a newish Mac book pro, and I installed VScode, then installed Anaconda (With VScode included). Maybe they're stepping on each other?

I suggesting using a minimal PATH, and the OP confirms:

Just cd to the desired dir and type "code ." instead of just "code" seems to solve the problem.

like image 186
VonC Avatar answered Dec 31 '25 00:12

VonC