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

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

问题描述

当我习惯通过以下命令通过pip安装模块时,为什么'py'和'python'之间没有区别:

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安装的可执行文件.基本上,这会将该版本的路径放在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.

py Python启动器,它是Windows上Python安装随附的实用程序.它已安装到C:\Windows\中,因此无需修改PATH就可以使用. Python启动器会检测您的计算机上安装了哪些Python版本,并能够自动将其委派给正确的版本.默认情况下,它将使用您计算机上的最新Python版本.因此,如果您已安装2.7、3.5和3.6,则运行py将启动3.6.您还可以通过执行以下操作来指定其他版本: py -3.5转到lauch 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.

您可以在文档中中详细了解.

这几天,我个人从未将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机器,这只会是Python2.即使Python 2不再附带但仅发行Python 3的发行版也不会对Python 3使用python,因为工具的普遍期望是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版本与 python.org 中提供的官方CPython版本不同.我认为默认情况下,这些版本根本无法通过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.

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

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