Search code examples
python-3.xprettier

Program 'black.exe' failed to run: Access is deniedAt line:1 char:1


I did pip install black for VS code editor. It is an alternative to prettier for python in vs code.

I received the following issues when I run black Untitled-1.py.

Program 'black.exe' failed to run: Access is deniedAt line:1 char:1
+ black Untitled-1.py
+ ~~~~~~~~~~~~~~~~~~~.
At line:1 char:1
+ black Untitled-1.py
+ ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    + FullyQualifiedErrorId : NativeCommandFailed

In the VS terminal.

I did not understand why access is deniedAt. I do not have any antiviruses running on my Windows 10.

enter image description here


Solution

  • I uninstalled python and ensure that it is uninstalled everywhere on my machine including the default version that comes with windows 10 now.

    1. Uninstall python
    2. Make sure you follow this link.
    3. Restarted the machine
    4. Reinstall the newest version of python
    5. Install black pip install black
    6. In the VS code editor ensure the setting knows the location of black here is a small setting in JSON for those interested:
     {
          "workbench.colorTheme": "Community Material Theme High Contrast",
          "editor.mouseWheelZoom": true,
          "workbench.iconTheme": "Monokai Pro Icons",
          "editor.defaultFormatter": "esbenp.prettier-vscode",
          "[solidity]": {
            "editor.defaultFormatter": "JuanBlanco.solidity",
            "editor.formatOnSave": true
          },
          "editor.guides.bracketPairs": true,
          "[python]": {
            "editor.defaultFormatter": "ms-python.python",
            "editor.formatOnSave": true
          },
          "editor.formatOnSave": true,
          "jupyter.askForKernelRestart": false,
          "python.defaultInterpreterPath": "C:\\Users\\Username\\AppData\\Local\\Programs\\Python\\Python310\\python.exe",
          "python.formatting.blackPath": "C:\\Users\\Username\\AppData\\Local\\Programs\\Python\\Python310\\Scripts\\black.exe",
          "python.formatting.provider": "black"
        }
    
    1. Then create a new file and save

    This has solved my problem!