Home > Blockchain >  Is there a way to run code as administrator in visual studio code?
Is there a way to run code as administrator in visual studio code?

Time:03-21

I have this problem: Unable to run 'keyboard.is_pressed' on Mac

To fix this, I need to run it as an administrator from the terminal. Is there a way to do this from Visual Studio Code? Thanks

I have now also tried so other things that have been, so far, unsuccessful. These are:

  • Launching VS Code as an admin
  • changing my launch.json with "sudo": true and some other things the internet said to do
  • running the python file as an administrator to see if that gives it the correct "privileges" to be run as admin from the app
  • given VS Code access to my documents folder

the requested message, final few lines:

Library/Frameworks/Python.framework/Versions/3.9/bin/python3' '/Users/wayow/.vscode/extensions/ms-python.python-2022.2.1924087327/pythonFiles/lib/python/debugpy/launcher' '59853' '--' '/Users/wayow/mystuff/Pythonstuff/test/problemthing.py'
env: illegal option -- a
usage: env [-iv] [-P utilpath] [-S string] [-u name]
           [name=value ...] [utility [argument ...]]

CodePudding user response:

Try to put this in .vscode/launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current file",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "externalTerminal",
            "sudo": true
        }
    ]
}

and run your .py file and paste any error messages in your question.

It should open an external terminal.

I tested fine in MacOS Monterey.

Update

To get around env '-a' issue, open a Terminal and run :

  1. mkdir $HOME/bin

  2. Paste following (from cat ... including EOF) in the Terminal, type Enter at the end :

cat <<'EOF' > $HOME/bin/env
#!/bin/bash
test "$1" = -a && shift
exec /usr/bin/env "$@"
EOF
  1. chmod x "$HOME/bin/env"

  2. PATH="$HOME/bin:$PATH"

  3. open -a "Visual Studio Code" "python-project-directory"

  4. Run .py file

  • Related