Windows 终端中的“py"和“python"有什么区别? [英] What is the difference between 'py' and 'python' in the Windows terminal?

查看:51
本文介绍了Windows 终端中的“py"和“python"有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么'py'和'python'之间有区别,当我使用pip通过命令安装模块时:

Why is there a difference between 'py' and 'python', when I'm using to pip to install modules through the command:

python -m pip install [Mod]

或者

py -m pip install [Mod]

当我使用 Python IDLE 时,这些模块不可用.此外,当我检查

The modules aren't available when I'm using the Python IDLE. Furthermore, when I'm checking the

sys.path

'python' 和 'py' 都不同.我如何使它们相同,并且在安装模块时,安装到它们都可以访问的同一个文件夹中.

it's different for both 'python' and 'py'. How do I make it so they are both the same, and when installing modules, installing into the same folder where they can both access.

我忘了在 windows 上提到这一点.所以无论如何,我执行了

I forgot to mention that this on windows. So Anyways, I executed

python -V

它说版本是Python 3.6.4:: Anaconda, Inc"

and it says the version is "Python 3.6.4:: Anaconda, Inc"

虽然:

py -V

给出Python 3.6.5".有多大区别?如果它们是相同的版本(3.6),为什么它们的路径不同?

gives "Python 3.6.5". How much difference is there? and why do they have different paths if they are the same version(3.6)?

推荐答案

在 Windows 上

python 是 Python 安装的 Python 可执行文件,您在安装过程中将其选为默认值.这基本上是将那个版本的路径放在 PATH 中,这样可执行文件就可以直接使用了.

On Windows

python is the Python executable of the Python installation which you have selected as a default during the installation. This basically put the path to that version inside the PATH, so that the executable is directly available.

pyPython 启动器,它是 Windows 上 Python 安装附带的实用程序.它安装在 C:Windows 中,因此无需修改 PATH 即可使用.Python 启动器检测您的机器上安装了哪些 Python 版本,并能够自动委派给正确的版本.默认情况下,它将使用您机器上的最新 Python 版本.因此,如果您安装了 2.7、3.5 和 3.6,运行 py 将启动 3.6.您还可以通过执行例如指定不同的版本py -3.5 启动 3.5,或 py -2 在您的机器上启动最新的 Python 2 版本.

py is the Python launcher which is a utility that comes with Python installations on Windows. It gets installed into C:Windows so it’s available without requiring PATH modifications. The Python launcher detects what Python versions are installed on your machine and is able to automatically delegate to the right version. By default, it will use the latest Python version that is on your machine. So if you have installed 2.7, 3.5 and 3.6, running py will launch 3.6. You can also specify a different version by doing e.g. py -3.5 to lauch 3.5, or py -2 to launch the latest Python 2 version on your machine.

您可以在文档中在文档中阅读有关启动器的更多信息.

You can read more about the launcher in the documentation.

这些天,我个人从不将 Python 直接放在我的 PATH 中.我只对所有事情使用启动器,因为这让我可以更好地控制将启动的 Python.如果您看到 py -m pip install 不会为您使用 IDLE 运行的 Python 版本安装模块,您应该检查有哪些版本.每个 Python 安装都带有自己的 pip 模块安装目录.为 Python 3.5 启动 IDLE,您需要确保您还使用 Python 3.5 运行 pip(例如 py -3.5 -m pip install).

These days, I personally never put Python directly in my PATH. I only use the launcher for everything as that gives me more control over what Python will be launched. If you see that py -m pip install will not install modules for the Python version you run with IDLE, you should check what versions there are. Every Python installation comes with its own directory where pip modules are installed in. So if you e.g. launch IDLE for Python 3.5, you need to make sure that you also run pip with Python 3.5 (e.g. py -3.5 -m pip install).

python 是您机器上默认 Python 安装的符号链接.对于许多 Linux 机器,这只会是 Python 2.即使不再随 Python 2 提供但仅提供 Python 3 的发行版也不会将 python 用于 Python 3,因为对工具的一般期望是 python 是 Python 2.所以他们可能只有一个 python3 符号链接.

python is a symlink to the default Python installation on your machine. For many Linux machines, this will only be Python 2. Even distributions that no longer come with Python 2 but only ship Python 3 will not use python for Python 3 since the general expectations of tools would be that python is a Python 2. So they may only have a python3 symlink.

py 通常在 Linux 上不存在,除非您自己设置别名或符号链接.您可以使用 which pythonwhich py 来查看这些命令实际上是什么.

py usually does not exist on Linux, unless you set an alias or symlink yourself. You can check with which python and which py to see what these commands actually are.

您使用的 Python 版本来自 Anaconda,这是一个不同的 Python针对数据科学家的发行版捆绑了很多东西.它使用与 python.org 提供的官方 CPython 版本不同的 Python 版本.我认为这些版本在默认情况下根本无法通过 Python 启动器使用.

The Python version you are using is from Anaconda, which is a different Python distribution targeted at data scientists that comes bundled with quite a few things. It uses a different Python version that is separate from the official CPython releases that are available from python.org. I assume that those versions simply won’t be available through the Python launcher by default.

这篇关于Windows 终端中的“py"和“python"有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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