如何使用 py 而不是 python 从命令行访问 python [英] how to access python from command line using py instead of python
问题描述
我有一个很奇怪的要求.我的一个可执行文件有一个对 python 脚本的系统调用,它类似于 py file1.py现在,在我的系统中,虽然 py 显示为无法识别的内部或外部命令.但是 python file1.py 可以工作.
I have a very weird request. An executable I have has a system call to a python script which goes like py file1.py Now, in my system though py is shown as an unrecognized internal or external command. python file1.py works however.
有什么方法可以让我的 Windows 命令提示符识别出 py 和 python 指的是同一件事吗?
is there some way I can get my windows command prompt to recognize that py and python refer to the same thing?
推荐答案
py
命令是 Python3.x 自带的,允许在多个 Python 解释器中进行选择.例如,如果您同时安装了 Python 3.4 和 2.7,py -2
将启动 python2.7,py -3
将启动 python3.4.如果您只使用 py
,它将启动默认定义的那个.
py
command comes with Python3.x and allow to choose among multiple Python interpreters. For example if you have both Python 3.4 and 2.7 installed, py -2
will start python2.7 and py -3
will start python3.4 . If you just use py
it will start the one that was defined as default.
所以官方的方法是安装 Python 3.x,将 Python 2.7 声明为默认值,py
命令将完成它的工作.
So the official way would be to install Python 3.x, declare Python 2.7 as the default, and the py
command will do its job.
但是如果你只是想让 py
成为 python
的别名,doskey py=python.exe
就像@Nizil 和 @ 提出的那样ergonaut 会简单很多...或者如果你不想被 doskey
的限制所困扰,或者将 python.exe 复制到 Python27 文件夹中的 py.exe.
But if you just want py
to be an alias of python
, doskey py=python.exe
as proposed by @Nizil and @ergonaut will be much simpler... Or copying python.exe to py.exe in Python27 folder if you do not want to be bothered by the limitations of doskey
.
这篇关于如何使用 py 而不是 python 从命令行访问 python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!