microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
165.02k stars 29.55k forks source link

Task running python script fails with : Cannot create process, error code: 193 #141751

Closed Butanium closed 2 years ago

Butanium commented 2 years ago

Issue Type: Bug

I have this task decimate and plot csv executing a python script plotting the csv I'm editing, and several others which executs cmd as dune utop :

{
            "label": "dune utop",
            "command": "external_tools/_run_config/dune_utop.cmd"
        },
        {
            "label": "decimate and plot csv",
            "command": "external_tools/show_data/show_task.py",
            "args": ["${relativeFile}","${input:decimateFactor}"]
        }

    ],
    "inputs": [
        {
            "id": "decimateFactor",
            "description": "Decimate factor :",
            "default": "1000",
            "type": "promptString"
        }
    ]

The dune task works well but the python one just doesn't :

> Executing task in folder ocaml-tsp: C:\Users\Clement\Documents\prepa\tipe\ocaml-tsp\external_tools\show_data\show_task.py logs\MCTS-att48-7s-Random-Min_spanning_tree-Two_opt_optimization_200len_100iter_1s\all_scores.csv 1000 <

Échec du lancement du processus de terminal : A native exception occurred during launch (Cannot create process, error code: 193).

Le terminal sera réutilisé par les tâches, appuyez sur une touche pour le fermer.

However when I copy paste the task in a vscode cmd, it works well :

Microsoft Windows [version 10.0.19043.1466]
(c) Microsoft Corporation. Tous droits réservés.

C:\Users\Clement\Documents\prepa\tipe\ocaml-tsp>C:\Users\Clement\Documents\prepa\tipe\ocaml-tsp\external_tools\show_data\show_task.py logs\MCTS-att48-7s-Random-Min_spanning_tree-Two_opt_optimization_200len_100iter_1s\all_scores.csv 1000
debugging...
file decimated

By the way this is the python script called :

from show_data import decimate
import matplotlib.pyplot as plt
import os
import sys

print("debugging...", flush=True)
os.chdir("C:/Users/Clement/Documents/prepa/tipe/ocaml-tsp/")
factor = 1000 if len(sys.argv) <= 2 else int(sys.argv[2])
result = decimate(sys.argv[1], factor)

plt.plot(result['timestamp'], result['length'])
plt.show()

VS Code version: Code 1.63.2 (899d46d82c4c95423fb7e10e68eba52050e30ba3, 2021-12-15T09:40:02.816Z) OS version: Windows_NT x64 10.0.19043 Restricted Mode: No

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz (8 x 2304)| |GPU Status|2d_canvas: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
skia_renderer: enabled_on
video_decode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled| |Load (avg)|undefined| |Memory (System)|7.80GB (0.97GB free)| |Process Argv|--crash-reporter-id 8a98e7f6-95cb-41bb-86c4-651ceca005df| |Screen Reader|no| |VM|0%|
Extensions (1) Extension|Author (truncated)|Version ---|---|--- vscode-language-pack-fr|MS-|1.63.3
A/B Experiments ``` vsliv368:30146709 vsreu685:30147344 python383:30185418 vspor879:30202332 vspor708:30202333 vspor363:30204092 pythonvspyl392cf:30425750 pythontb:30283811 pythonptprofiler:30281270 vshan820:30294714 vstes263:30335439 pythondataviewer:30285071 vscod805:30301674 pythonvspyt200:30340761 binariesv615:30325510 bridge0708:30335490 bridge0723:30353136 vsaa593cf:30376535 vsc1dst:30428979 pythonvs932:30410667 vscop804cf:30404767 vscop341:30404997 vsrem710:30416614 vsbas813:30426126 ```
alexr00 commented 2 years ago

@Butanium can you share any terminal and task related settings you have set?

Butanium commented 2 years ago

@alexr00 I can't remember which settings I changed, if any, can I send you my whole settings.json or screenshots of terminal and tasks settings ?

alexr00 commented 2 years ago

Yes, the whole settings.json would be useful.

Butanium commented 2 years ago

The one inside my .vscode project folder is just :

{
    "ocaml.sandbox": {
        "kind": "global"
    },
    "python.formatting.provider": "black",
    "discord.enabled": true
}

The global one in C:\Users\Clement\AppData\Roaming\Code\User\settings.json :

{
    "workbench.colorTheme": "Default Dark+",
    "terminal.integrated.profiles.windows": {
        "PowerShell": {
            "source": "PowerShell",
            "icon": "terminal-powershell"
        },
        "Command Prompt": {
            "path": [
                "${env:windir}\\Sysnative\\cmd.exe",
                "${env:windir}\\System32\\cmd.exe"
            ],
            "args": [],
            "icon": "terminal-cmd"
        },
        "Git Bash": {
            "source": "Git Bash"
        },
        "ocaml_terminal": {
            "path": "C:\\WINDOWS\\System32\\cmd.exe",
            "args": []
        }
    },
    "files.autoSave": "onFocusChange",
    "files.autoGuessEncoding": true,
    "timeline.excludeSources": [],
    "git.confirmSync": false,
    "tabnine.experimentalAutoImports": true,
    "git.enableSmartCommit": true,
    "diffEditor.ignoreTrimWhitespace": false,
    "files.watcherExclude": {
        "**/_build/**": true,
        "**/archive/**": true,
        "**/puzzle_input/**": true
    },
    "search.exclude": {
        "**/_build/**": true,
        "**/archive/**": true,
        "**/logs/**": true
    },
    "files.eol": "\n",
    "gitlens.defaultTimeFormat": null,
    "gitlens.hovers.currentLine.over": "line",
    "update.mode": "manual"
}

Let me know if I can provide you more info

alexr00 commented 2 years ago

It looks like when you run the script manually you're using cmd.exe. However, unless you specify a different shell, tasks will use your default shell (in this case powershell). Can you try adding this setting to change the shell that tasks uses?

    "terminal.integrated.automationProfile.windows": {
        "path": "cmd.exe",
    },
Butanium commented 2 years ago

I just tried to run manually my script in powershell and it works,

PS C:\Users\Clement\Documents\prepa\tipe\ocaml-tsp> external_tools/show_data/show_task.py 
logs\MCTS-att48-1800s-Random-Min_spanning_tree-Two_opt_optimization_200len_100iter_1s--1\all_scores.csv 1000

but opens an external python console image

I added the parameters you sent in both settings.json but it seems like the task still execute in a Powershell console : image

I also tried to replace your path by "path":"${env:windir}\\Sysnative\\cmd.exe" and "${env:windir}\\System32\\cmd.exe" but got the same result

alexr00 commented 2 years ago

Do you also have settings in a *.code-workspace file?

Butanium commented 2 years ago

image Opens this settings.json :

{
    "ocaml.sandbox": {
        "kind": "global"
    },
    "python.formatting.provider": "black",
    "discord.enabled": true
}

And I have no *.code-workspace file on my computer (I made a search of any file with code-workspace extension)

alexr00 commented 2 years ago

@Butanium it looks like you're running your tasks as a process task. Your task should work if you add the property "type": "shell" to it. I missed this in the original post.

Butanium commented 2 years ago

I had to enter the entire path instead of the relative one but it works now. Thanks !