1

When I execute the command $env:path to get the path variable in the powershell mode in spacemacs I get the following:

C:\Program Files (x86)\Common Files\Oracle\Java\javapath;
C:\Windows\system32;
C:\Windows;
C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Windows\System32\OpenSSH\;
C:\ProgramData\chocolatey\bin;
C:\Program Files\Git\cmd;
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;
C:\Program Files\PuTTY\;
C:\Users\Oliver Marshall\AppData\Local\Microsoft\WindowsApps;

Which only partly matches the System Environment Variable:

C:\Program Files\ImageMagick-7.0.8-Q16;
C:\Python37\Scripts\;
C:\Python37\;
C:\Program Files (x86)\Common Files\Oracle\Java\javapath;
C:\Windows\system32;
C:\Windows;
C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Windows\System32\OpenSSH\;
C:\ProgramData\chocolatey\bin;
C:\Program Files\Git\cmd;
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;
C:\Program Files\PuTTY\;
C:\Program Files\MiKTeX 2.9\miktex\bin\x64\;

And doesn't match the User Environment Variable either:

%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;
C:\Python37;
C:\Python37\Scripts;
C:\Users\Oliver Marshall\AppData\Roaming\Python\Python37\Scripts;
C:\tools\msys64;
C:\Program Files\MiKTeX 2.9\miktex\bin\x64;

What's weird is that the exec-path variable shows what I'd consider to be the correct result:

c:/Program Files/ImageMagick-7.0.8-Q16
C:/Python37/Scripts/
C:/Python37/
C:/Program Files (x86)/Common Files/Oracle/Java/javapath
C:/Windows/system32
C:/Windows
C:/Windows/System32/Wbem
C:/Windows/System32/WindowsPowerShell/v1.0/
C:/Windows/System32/OpenSSH/
C:/ProgramData/chocolatey/bin
C:/Program Files/Git/cmd
C:/Program Files (x86)/NVIDIA Corporation/PhysX/Common
C:/Program Files/PuTTY/
C:/Program Files/MiKTeX 2.9/miktex/bin/x64/
C:/Users/Oliver Marshall/AppData/Local/Microsoft/WindowsApps
C:/Python37
C:/Python37/Scripts
C:/Users/Oliver Marshall/AppData/Roaming/Python/Python37/Scripts
C:/tools/msys64
C:/Program Files/MiKTeX 2.9/miktex/bin/x64
c:/ProgramData/chocolatey/lib/Emacs/tools/emacs/libexec/emacs/26.1/x86_64-w64-mingw32
C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath
C:\\Windows\\system32
C:\\Windows
C:\\Windows\\System32\\Wbem
C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\
C:\\Windows\\System32\\OpenSSH\\
C:\\ProgramData\\chocolatey\\bin
C:\\Program Files\\Git\\cmd
C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common
C:\\Program Files\\PuTTY\\
C:\\Users\\Oliver Marshall\\AppData\\Local\\Microsoft\\WindowsApps

Why is powershell getting this malformed path variable?

This has also affected the building of LaTeX documents as it says it can't find the pdflatex executable but I've included the MiKTeX installation in the environment variable and executable-find finds the executable just fine.

1

The cause of this problem was hinted to me by eli-zaretskii over on reddit (link to the post here).

It turns out that when spacemacs loads for the first time it creates a file .spacemacs.env in your home directory which saves the state of your environment variables at that time. This file gets loaded at startup by spacemacs to initialise the environment variables for emacs.

The top of the file includes instructions on how to re-initialize the file, disable it and other useful actions.

For me, the solution was to simply run spacemacs/force-init-spacemacs-env to re-initialize the file and now everything has the correct values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.