简体   繁体   English

更改命令提示符的默认 python 版本

[英]Change default python version for command prompt

On my machine I have python3.4 and a recently downloaded python3.6 installed, I would like to set python3.6 as my default python used in command prompt.在我的机器上,我安装了 python3.4 和最近下载的 python3.6,我想将 python3.6 设置为命令提示符中使用的默认 python。

I have removed the python34 path variable but my when I access python through the command prompt it still defaults to opening python3.4.我已经删除了 python34 路径变量,但是当我通过命令提示符访问 python 时,它仍然默认打开 python3.4。 I saw this question about access the non default python but that was for specific files.我看到了这个关于访问非默认 python 的问题,但那是针对特定文件的。

在此处输入图片说明 在此处输入图片说明

Since posting the question:自发布问题以来:

I have also removed python34 from the system path variables.我还从系统路径变量中删除了 python34。

Typing where python in command prompt returns this:在命令提示符中输入where python返回:

C:\>where python
C:\Python34\python.exe
C:\Python36\python.exe

Typing echo %PATH% returns输入echo %PATH%返回

C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Python34;;C:\WINDOWS\System32\OpenSSH\;C:\Python36\Scripts\;C:\Python36\;C:\Users\ME\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;

The accepted answer on the proposed duplicate states it is possible but you shouldn't do it, and doesn't give details on how to do it.关于提议的重复项的公认答案是可能的,但您不应该这样做,并且没有提供有关如何执行的详细信息。

You can run multiple python versions on your machine.你可以在你的机器上运行多个 python 版本。

To make Python 3.6 default, just put path of Python 3.6 before path of Python 3.4 in system variables.要使 Python 3.6 默认,只需在系统变量中将 Python 3.6 的路径放在 Python 3.4 的路径之前。

OR或者

In python34 directory on C drive rename python.exe to python3.4.exe.在 C 盘的 python34 目录中,将 python.exe 重命名为 python3.4.exe。 After doing this if you run command python in command prompt it will open python 3.6.执行此操作后,如果您在命令提示符下运行命令python ,它将打开 python 3.6。 And to run python 3.4 you need to run command python3.4 as we have renamed it to python3.4.exe in python34 directory .要运行 python 3.4,您需要运行命令python3.4,因为我们已将其重命名为 python34 目录中的 python3.4.exe

After making changes in system variables in environment variables you just need to restart your command prompt.在环境变量中更改系统变量后,您只需要重新启动命令提示符。 No need to restart machine.无需重启机器。

After some communication I guess I know what is the problem.经过一些沟通,我想我知道问题出在哪里了。 Have you checked your system wide environment variables?您是否检查过系统范围的环境变量? Here is a link about how to:这是有关如何操作的链接

  1. In Search, search for and then select: System (Control Panel)在搜索中,搜索并选择:系统(控制面板)
  2. Click the Advanced system settings link.单击高级系统设置链接。
  3. Click Environment Variables.单击环境变量。 In the section System Variables, find the PATH environment variable and select it.在 System Variables 部分,找到 PATH 环境变量并选择它。 Click Edit.单击编辑。 If the PATH environment variable does not exist, click New.如果 PATH 环境变量不存在,请单击新建。
  4. In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable.在 Edit System Variable(或 New System Variable)窗口中,指定 PATH 环境变量的值。 Click OK.单击确定。 Close all remaining windows by clicking OK.单击确定关闭所有剩余的窗口。

Further, your application(your command prompt) wide environment variables are appended after system wide ones.此外,您的应用程序(您的命令提示符)范围的环境变量附加在系统范围的环境变量之后。

After doing a restart of my machine after deleting python34 from my system path variables as @Talha Junaid mentioned in the comments, my python now defaults to python3.6 when accessed through command prompt, windows must load all the path variables on startup and hold them in memory until a restart occurs.在注释中提到的@Talha Junaid 从我的系统路径变量中删除 python34 后重新启动我的机器后,当通过命令提示符访问时,我的 python 现在默认为 python3.6,Windows 必须在启动时加载所有路径变量并保留它们在内存中,直到发生重新启动。


Steps for anyone else starting the process.其他任何人开始该过程的步骤。

Windows 10视窗 10

  1. Type "System" into the search bar to go to system settings in the control panel (Control Panel\\All Control Panel Items\\System)在搜索栏中键入“系统”以转到控制面板中的系统设置(控制面板\\所有控制面板项目\\系统)

  2. Click "Advanced System Settings" -> 2Environment Variables2点击“高级系统设置”->2环境变量2

For User Variables:对于用户变量:

  1. Highlight the row for "Path" by clicking on it and then click the "Edit" button通过单击突出显示“路径”行,然后单击“编辑”按钮
  2. Highlight by clicking the version of python you want to remove from your environment variables and then click the "Delete" button.通过单击要从环境变量中删除的 python 版本突出显示,然后单击“删除”按钮。

Repeat steps 3 and 4 for System Environment Variables.对系统环境变量重复步骤 3 和 4。

  1. Close all the windows by clicking the "Ok" buttons单击“确定”按钮关闭所有窗口

  2. Restart your machine重启你的机器

我遇到了同样的问题,在将 python.exe 更改为 python3.6.exe 后,我从 Windows 商店下载了版本 8,并且安装和替换自动完成,并且默认版本也更新了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM