我应该如何在 Windows 中设置默认 Python 版本? [英] How Should I Set Default Python Version In Windows?

查看:44
本文介绍了我应该如何在 Windows 中设置默认 Python 版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 7 上安装了 Python 2.6Python 3.1 并设置了环境变量:path = d:python2.6.p>

当我在 cmd 中运行 python 时,它会显示 python 版本 2.6,这正是我想要的!
但是,当我在 bat 文件中编写脚本并运行它时,显示的 python 版本是 3.1.

导入系统打印(系统版本)

这是怎么回事?

解决方案

如果您同时安装了这两个版本.

转到 这台电脑 ->右键->点击属性->高级系统设置.

您将看到系统属性.从这里导航到 "Advanced" 选项卡 -> 点击 Environment Variables.

您将看到用户变量的上半部分和系统变量下半部分.

检查System Variables并双击Path(编辑路径).

检查 Python(您希望运行的路径,即 Python 2.x 或 3.x)并将其移动到路径列表的顶部.

重新启动命令提示符,现在当您检查 Python 的版本时,它应该会正确显示所需的版本.

I installed Python 2.6 and Python 3.1 on Windows 7 and set environment variable: path = d:python2.6.

When I run python in cmd, it displays the python version 2.6, which is what I want!
But, when I wrote a script in a bat file and ran it, the displayed python version was 3.1.

import sys
print (sys.version)

What's going on here?

解决方案

This is if you have both the versions installed.

Go to This PC -> Right-click -> Click on Properties -> Advanced System Settings.

You will see the System Properties. From here navigate to the "Advanced" Tab -> Click on Environment Variables.

You will see a top half for the user variables and the bottom half for System variables.

Check the System Variables and double-click on the Path(to edit the Path).

Check for the path of Python(which you wish to run i.e. Python 2.x or 3.x) and move it to the top of the Path list.

Restart the Command Prompt, and now when you check the version of Python, it should correctly display the required version.

这篇关于我应该如何在 Windows 中设置默认 Python 版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆