我关注了此视频:https://www.youtube.com/watch?v=Y2q_b4ugPWk 并让我的cmd将python识别为路径变量。但这只有在我打开cmd和powershell作为管理员时才有效。如何让它适用于所有用户?
作为管理员:
PS C:\windows\system32> python
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 10:22:32) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
作为用户:
PS C:\Users> python
python : The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ python
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (python:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\Users>
答案 0 :(得分:2)
使用提升的权限(右键单击powershell.exe
,以管理员身份运行)
$PathToPython = 'C:\whatever\containingfolderforpythonexe'
$CurrentValue = [Environment]::GetEnvironmentVariable('Path', 'Machine')
[Environment]::SetEnvironmentVariable('Path', "$CurrentValue;$PathToPython", 'Machine')
答案 1 :(得分:-1)
我为我的powershell脚本构建了一个批处理开启工具。一旦以提升的权限打开,任何其他调用的脚本也会被提升。 我用.vbs做类似的事情,在admin中打开批处理。
@ECHO off
ECHO Please Wait.
powershell.exe -ExecutionPolicy ByPass -file "File.ps1"
ECHO.
ECHO PRESS ANY KEY ONCE DEBUGGED
Pause >nul
exit