0

I am modifying the PATH variable using os.environ(),following is the code i am using:

os.environ["PATH"] += os.pathsep + 'C:\\Program Files (x86)\\VideoLAN\\VLC\\'

the command runs fine and if i show the content of PATH variable using os.environ["PATH"] in python interpreter the modification is being shown i.e(vlc is added to PATH or it seems so):

C:\Windows\System32;C:\linuxlikecli;C:\Program Files\Git\cmd;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\Falcon\MinGW\bin;C:\Windows\System32\wbem;C
:\Program Files\OpenSSH-Win64;C:\Program Files\nodejs\;C:\ProgramData\chocolatey\bin;C:\Program Files (x86)\MSBuild\12.0\Bin;C:\ProgramData\chocolatey\lib\mpv.install\too
ls;C:\Users\asnlze\AppData\Local\Programs\Python\Python38\Scripts\;C:\Users\asnlze\AppData\Local\Programs\Python\Python38\;C:\Program Files (x86)\Common Files\Oracle\Java
\javapath;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Falcon\MinGW\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\Sy
stem32\WindowsPowerShell\v1.0\;C:\Users\asnlze\AppData\Local\Programs\Python\Python37-32;C:\Program Files\Java\jdk-15\bin;C:\Program Files\Git\cmd;C:\Program Files (x86)\
Common Files\Oracle\Java\javapath;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Falcon\MinGW\bin;C:\Windows\system32;C:\Windows;C:\Windows\Sys
tem32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Users\asnlze\AppData\Local\Programs\Python\Python37-32;C:\Program Files\Java\jdk-15\bin;C:\Program Files\Ash;C:\
php-8.0.0-Win32-vs16-x64;E:\Software\_download.org_Burp.Suite.2020.7\Crackdownload.org_Burp.Suite.2020.7;C:\Program Files\JetBrains\PyCharm Community Edition 2020.2.3\bin
;C:\Program Files (x86)\VideoLAN\VLC\

but whenever i start the edit environmental vairables dialog or if i do echo %PATH% in cmd the modification is not being shown(vlc is actually not being added to path):

C:\Windows\System32;C:\linuxlikecli;C:\Program Files\Git\cmd;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\Falcon\MinGW\bin;C:\Windows\System32\wbem;C
:\Program Files\OpenSSH-Win64;C:\Program Files\nodejs\;C:\ProgramData\chocolatey\bin;C:\Program Files (x86)\MSBuild\12.0\Bin;C:\ProgramData\chocolatey\lib\mpv.install\too
ls;;C:\Users\asnlze\AppData\Local\Programs\Python\Python38\Scripts\;C:\Users\asnlze\AppData\Local\Programs\Python\Python38\;C:\Program Files (x86)\Common Files\Oracle\Jav
a\javapath;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Falcon\MinGW\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\S
ystem32\WindowsPowerShell\v1.0\;C:\Users\asnlze\AppData\Local\Programs\Python\Python37-32;C:\Program Files\Java\jdk-15\bin;C:\Program Files\Git\cmd;C:\Program Files (x86)
\Common Files\Oracle\Java\javapath;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Falcon\MinGW\bin;C:\Windows\system32;C:\Windows;C:\Windows\Sy
stem32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Users\asnlze\AppData\Local\Programs\Python\Python37-32;C:\Program Files\Java\jdk-15\bin;C:\Program Files\Ash;C:
\php-8.0.0-Win32-vs16-x64;E:\Software\_download.org_Burp.Suite.2020.7\Crackdownload.org_Burp.Suite.2020.7;C:\Program Files\JetBrains\PyCharm Community Edition 2020.2.3\bi
n;

note that i am refreshing the environment after setting it,what's wrong in my implementation,any help is appreciated .i am using python3.8 on windows 7 64 bit.tried it with admin and without admin shell

6
  • 1
    You are changing "session" env. It will not change anything else, else sessions' nor system wide settings Commented Jun 27, 2021 at 10:38
  • also please give a reason for downvoting Commented Jun 27, 2021 at 10:39
  • @MarcinOrlowski then how should i change the PATH variable Commented Jun 27, 2021 at 10:40
  • @MarcinOrlowski according to this answer we can change the PATH the way i did Commented Jun 27, 2021 at 10:47
  • It's important for context purposes that you define what you are trying to achieve with this piece of code. Are you trying to change the system-wide PATH variable forever? or are you just trying to add this to your PATH for the purposes of this script? More details would help Commented Jun 27, 2021 at 11:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.