pythonpowershellimportpackagepath-variables

Computer can't find installed libraries


I use VSCode Anytime I install a python library, I get this notification:

WARNING: The scripts auto-py-to-exe.exe and autopytoexe.exe are installed in 'C:\Users\PC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\Scripts' which is not on PATH

But I've added that to path. If I run:

echo $env:PATH

I get

C:\Users\PC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\Scripts:C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Users\PC\AppData\Local\Microsoft\WindowsApps;C:\Users\PC\AppData\Local\Programs\Microsoft VS Code\bin;C:\texlive\2023\bin\windows

suggesting that I've added said path.

I'm confused because I can't run packages from the CLI directly, even though importing them works.

I added the path manually and I've tried removing it but that doesn't work. Any ideas on what to do?


Solution

  • Your own solution is effective in principle - ; is the required separator on Windows - except that your statement isn't valid PowerShell code, and that \ chars. don't need escaping as \\ in PowerShell; also, you can express the new directory path more generically using the LOCALAPPDATA environment variable; therefore:

    $newDir = "$env:LOCALAPPDATA\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\Scripts"
    $env:PATH = "$newDir;$env:PATH" 
    

    The above modifies $env:PATH only for the current session (process).
    To also persist this change on Windows - so that future sessions see it too:

    Note that .NET cannot offer APIs for persistent environment-variable definitions on Unix-like platforms, because there's no unified mechanism across all of them.


    Cross-platform background information on the PATH environment variable: