Python Forum
A trouble with VS Code - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Forum & Off Topic (https://python-forum.io/forum-23.html)
+--- Forum: Bar (https://python-forum.io/forum-27.html)
+--- Thread: A trouble with VS Code (/thread-20833.html)

Pages: 1 2 3


RE: A trouble with VS Code - snippsat - Sep-05-2019

(Sep-05-2019, 12:31 PM)Truman Wrote: When I go to Terminal>Run task it opens the box "select the task to run". What should I do then?
I never use this,you should install Code Runner,i have more about this in my tutorial.

When installed open setting,search code-runner.executorMap.
"code-runner.executorMap": {
        "javascript": "node",
        "java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
        "c": "gcc -o $fileNameWithoutExt $fullFileName && $fileNameWithoutExt",
        "cpp": "g++ -o $fileNameWithoutExt $fullFileName && $fileNameWithoutExt",
        "objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "php": "php",
        "python": "$pythonPath $fullFileName",
        "perl": "perl",
        "ruby": "ruby",
        "go": "go run",
        "lua": "lua",
Set "python": "$pythonPath $fullFileName",
With this command will also switch automatically if change Python interpreter(down in left corner).

Now get a button to run code or right click run code.
[Image: CQMz7n.png]


RE: A trouble with VS Code - Larz60+ - Sep-05-2019

Quote:When I go to Terminal>Run task it opens the box "select the task to run". What should I do then?
use 'run python file in terminal ' (from right click on code window) instead


RE: A trouble with VS Code - Truman - Sep-05-2019

snippsat, after locating code-runner.executorMap I see only settings.json file with this code:


 {
    "python.pythonPath": "C:\\Python37\\Anaconda3\\pythonw.exe",
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "python.jediEnabled": false,
    "python.formatting.provider": "black",
    "terminal.integrated.rendererType": "dom",
    "telemetry.enableTelemetry": false,
    "telemetry.enableCrashReporter": false,
    "workbench.colorTheme": "FlatUI Dark"
}
@Larz60+
I tried your suggestion and after delay got this:
Output:
PS C:\Python37\kodovi> C:/Python37/Anaconda3/Scripts/activate PS C:\Python37\kodovi> conda activate base conda : The term 'conda' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + conda activate base + ~~~~~ + CategoryInfo : ObjectNotFound: (conda:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Python37\kodovi> & C:/Python37/Anaconda3/pythonw.exe c:/Python37/kodovi/lucky1.py
could the bath be wrong? Does it have to go through Anakonda3?


RE: A trouble with VS Code - snippsat - Sep-05-2019

Follow command in image under,of course Code Runner have to installed first.
[Image: CxOIlx.png]


RE: A trouble with VS Code - Truman - Sep-05-2019

I uninstalled Anaconda and now the execution of the file in the traditional way works fine.

@snippsat, I followed these steps. As I said, settings.json has that code that I posted.


RE: A trouble with VS Code - snippsat - Sep-05-2019

(Sep-05-2019, 04:52 PM)Truman Wrote: @snippsat, I followed these steps. As I said, settings.json has that code that I posted.
Then something most be wrong on your side,push Extensions(left side) --> show installed Extensions.
See that Code Runner has This extensions is enable globally.

This is what you should see,can try to copy this to settings.json.
"code-runner.executorMap": {
        "javascript": "node",
        "java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
        "c": "gcc -o $fileNameWithoutExt $fullFileName && $fileNameWithoutExt",
        "cpp": "g++ -o $fileNameWithoutExt $fullFileName && $fileNameWithoutExt",
        "objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "php": "php",
        "python": "$pythonPath $fullFileName",
        "perl": "perl",
        "ruby": "ruby",
        "go": "go run",
        "lua": "lua",
        "groovy": "groovy",
        "powershell": "powershell -ExecutionPolicy ByPass -File",
        "bat": "cmd /c",
        "shellscript": "bash",
        "fsharp": "fsi",
        "csharp": "scriptcs",
        "vbscript": "cscript //Nologo",
        "typescript": "ts-node",
        "coffeescript": "coffee",
        "scala": "scala",
        "swift": "swift",
        "julia": "julia",
        "crystal": "crystal",
        "ocaml": "ocaml",
        "r": "Rscript",
        "applescript": "osascript",
        "clojure": "lein exec",
        "haxe": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt",
        "rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt",
        "racket": "racket",
        "ahk": "autohotkey",
        "autoit": "autoit3",
        "kotlin": "cd $dir && kotlinc $fileName -include-runtime -d $fileNameWithoutExt.jar && java -jar $fileNameWithoutExt.jar",
        "dart": "dart",
        "pascal": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
        "d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt",
        "haskell": "runhaskell",
        "nim": "nim compile --verbosity:0 --hints:off --run"
    },



RE: A trouble with VS Code - Truman - Sep-05-2019

Now it works fine. Thank you.


RE: A trouble with VS Code - adt - Sep-08-2019

(Sep-05-2019, 02:11 PM)snippsat Wrote: Set "python": "$pythonPath $fullFileName",

In VS-Code version-1.38.0x64 system installed on Windows-10, it is seen that in Settings, while at the item "Code-Runner:Executor Map", clicking the caption "Edit in settings.json" opens the json file without actually showing the contents of Executor Map code block therein.

To get at this content, clicking the gear wheel that appears on left when you hover over "Code-Runner:Executor Map" provides the option to copy on to clipboard, which can then be pasted into json file as desired.

In my case, I have selected Python as default language for Code-Runner and the Executor Map reads as follows:
  "code-runner.executorMap": {
  "javascript": "node",
  "java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
  "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
  "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
  "objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
  "php": "php",
  "python": "python -u",
  "perl": "perl",
  "perl6": "perl6",
  "ruby": "ruby",
  "go": "go run",
  "lua": "lua",
  "groovy": "groovy",
  "powershell": "powershell -ExecutionPolicy ByPass -File",
  "bat": "cmd /c",
  "shellscript": "bash",
  "fsharp": "fsi",
  "csharp": "scriptcs",
  "vbscript": "cscript //Nologo",
  "typescript": "ts-node",
  "coffeescript": "coffee",
  "scala": "scala",
  "swift": "swift",
  "julia": "julia",
  "crystal": "crystal",
  "ocaml": "ocaml",
  "r": "Rscript",
  "applescript": "osascript",
  "clojure": "lein exec",
  "haxe": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt",
  "rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt",
  "racket": "racket",
  "scheme": "csi -script",
  "ahk": "autohotkey",
  "autoit": "autoit3",
  "dart": "dart",
  "pascal": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
  "d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt",
  "haskell": "runhaskell",
  "nim": "nim compile --verbosity:0 --hints:off --run",
  "lisp": "sbcl --script",
  "kit": "kitc --run"
}
relevant extract from existing json file reads as follows:
    "code-runner.clearPreviousOutput": true,
    "code-runner.defaultLanguage": "python",
    "code-runner.runInTerminal": false,
    "code-runner.preserveFocus": false
At present, everything seems o be working fine. Under the circumstances, would you still recommend that the line:
"python": "python -u",

as now shown in Executor Map should be replaced by:
"python": "$pythonPath $fullFileName",
and then the modified Executor Map inserted into the existing json file?


RE: A trouble with VS Code - snippsat - Sep-09-2019

(Sep-08-2019, 03:58 PM)adt Wrote: and then the modified Executor Map inserted into the existing json file?
Yes,with that option it will always run with Python interpreter that's active(down in left corner click to change).
I have many different version i run Anaconda,PyPy,Virtual environment...ect.
So when i push button to run code i want it use active interpreter(down in left corner).


RE: A trouble with VS Code - adt - Sep-09-2019

(Sep-09-2019, 05:40 AM)snippsat Wrote: Yes,with that option it will always run with Python interpreter that's active

Thanks for your kind confirmation.

Some points encountered during implementation of suggested course of action are placed below, for ready reference:

In my case, the file path involves a space (i.e. Program Files). As a result, insertion of generic statement (shown below) into json file attracts error:
"code-runner.executorMap": {"python": "$pythonPath $fullFileName"}
As a remedial measure, if hard string (with enclosing escape characters) is entered as shown below, there is no problem:
"code-runner.executorMap": {"python": "\"C:\\Program Files\\Python37\\python.exe\""}
However, such hard wiring of path would have the drawback of losing the flexibility provided by the generic statement as per your original suggestion i.e.:
"code-runner.executorMap": {"python": "$pythonPath $fullFileName"}
It would be great if a way could be found to make a success of generic statement, even for file paths having empty spaces.

In absence of such solution, might it not be preferable to avoid making any entry at all in json file. That way, the default python interpreter, as selected by the user, would prevail.