我安装了哪个版本的 Python?
我必须在 Windows 服务器上运行 Python 脚本。我如何知道我拥有哪个版本的 Python,这真的很重要吗?
我正在考虑更新到最新版本的Python。
I have to run a Python script on a Windows server. How can I know which version of Python I have, and does it even really matter?
I was thinking of updating to the latest version of Python.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(27)
Python 2.5+:
Python 2.4-:
Python 2.5+:
Python 2.4-:
在命令提示符处键入:
或者如果您有 pyenv:
At a command prompt type:
Or if you have pyenv:
尽管问题是“我正在使用哪个版本?”,但这实际上可能并不是您需要了解的全部内容。您可能安装了其他版本,这可能会导致问题,特别是在安装附加模块时。这是我查明已安装版本的粗略方法:
单个 Python 安装的输出应如下所示:
多个安装将输出如下所示:
Although the question is "which version am I using?", this may not actually be everything you need to know. You may have other versions installed and this can cause problems, particularly when installing additional modules. This is my rough-and-ready approach to finding out what versions are installed:
The output for a single Python installation should look something like this:
Multiple installations will have output something like this:
当我打开 Python(命令行) 时,它告诉我的第一件事就是版本。
When I open
Python (command line)
the first thing it tells me is the version.简而言之:
只需打开命令提示符 (Win + R) 并键入
cmd
并在命令提示符然后输入python
将为您提供有关版本的所有必要信息:In short:
Simply open the command prompt (Win + R) and type
cmd
and in the command prompt then typingpython
will give you all necessary information regarding versions:要检查 Jupyter Notebook 中的 Python 版本,您可以使用:
获取版本号,as:
或:
获取更多信息,as
或:
获取主要版本、次要版本和微版本,as
To check the Python version in a Jupyter notebook, you can use:
to get version number, as:
or:
to get more information, as
or:
to get major, minor and micro versions, as
我在 Windows 10 上安装了 Python 3.7.0。
这在命令提示符和 Git Bash 中对我有用:
运行 Python 并检查版本:
仅检查您拥有的版本:
或
注意:
python
、python --version
、python -V
、Python
,Python --version
,Python -V
对我不起作用。I have Python 3.7.0 on Windows 10.
This is what worked for me in the command prompt and Git Bash:
To run Python and check the version:
To only check which version you have:
or
Note:
python
,python --version
,python -V
,Python
,Python --version
,Python -V
did not work for me.所以从命令行:
so from the command line:
使用
或
注意:请注意,
python -V
命令中的“V”是大写 V。python -v
(小写的“v”)将以详细模式启动 Python 。Use
or
NOTE: Please note that the "V" in the
python -V
command is capital V.python -v
(small "v") will launch Python in verbose mode.您可以使用以下命令获取 Python 的版本
您甚至可以使用 pip freeze 获取安装在 venv 中的任何软件包的版本:
或者使用 Python 解释器:
You can get the version of Python by using the following command
You can even get the version of any package installed in venv using
pip freeze
as:Or using the Python interpreter as:
Windows 上默认的 Python 版本和所有已安装版本的路径:
One-Liners:
The default Python version and the paths of all installed versions on Windows:
One-Liners:
在装有 Python 3.9.1 的 Windows 10 上,使用命令行:
On Windows 10 with Python 3.9.1, using the command line:
如果您已位于 REPL 窗口中并且没有看到欢迎消息通过版本号,您可以使用 help() 查看主要版本和次要版本:
If you are already in a REPL window and don't see the welcome message with the version number, you can use help() to see the major and minor version:
在 Windows 上的命令提示符中输入
where python
可能会告诉您多个不同版本的 python 的安装位置(假设它们已添加到您的路径中)。在命令提示符中输入 python -V 应该会显示版本。
Typing
where python
on Windows into a Command Prompt may tell you where multiple different versions of python are installed, assuming they have been added to your path.Typing
python -V
into the Command Prompt should display the version.如果您安装了 Python,那么检查版本号的最简单方法是在命令提示符中键入“python”。它将显示版本号以及它是在 32 位还是 64 位上运行以及一些其他信息。对于某些应用程序,您希望拥有最新版本,有时则不需要。这取决于您要安装或使用哪些软件包。
If you have Python installed then the easiest way you can check the version number is by typing "python" in your command prompt. It will show you the version number and if it is running on 32 bit or 64 bit and some other information. For some applications you would want to have a latest version and sometimes not. It depends on what packages you want to install or use.
对我来说,打开 CMD 并运行
将显示类似的内容
For me, opening CMD and running
will show something like
要验证 Windows 上命令的 Python 版本,请在命令提示符中运行以下命令并验证输出:
此外,要查看每个 Python 版本的文件夹配置,请运行以下命令:
To verify the Python version for commands on Windows, run the following commands in a command prompt and verify the output:
Also, to see the folder configuration for each Python version, run the following commands:
有两种简单的方法可以检查已安装的 Python 版本。
在命令提示符下运行任何代码:
或
There are two simple ways to check for the version of Python installed.
Run any of the codes on the command prompt:
or
只需创建一个以 .py 结尾的文件并将以下代码粘贴到并运行它。
如果系统上安装了多个Python解释器版本,请运行以下命令。
在 Linux 上,在终端中运行:
在 Windows 上,在命令提示符中运行:
Just create a file ending with .py and paste the code below into and run it.
If several Python interpreter versions are installed on a system, run the following commands.
On Linux, run in a terminal:
On Windows, run in a command prompt:
在命令提示符中输入以下内容通常会告诉您已安装的 Python 版本:
但是,如果您未能将 Python 添加到 PATH 变量,则此操作将不起作用。 (如下所示,Python在安装时默认不会添加到系统路径中。)另请参阅:添加 PATH 环境变量Windows 10
另外,请记住您可能安装了多个版本的 Python。我安装了 Python 作为某些东西的依赖项,并安装了我用来编写代码的另一个版本。
另一种方法是执行以下操作:
数字对应于版本 src="https://i.sstatic.net/bZn3qH5U.png" alt="python 搜索结果">
例如,这里的许多搜索结果表明我安装了 3.11 版本。如果您想将 Python 添加到您的路径中,并且您可能需要参考此文件,请打开此文件。
Entering the following in the command prompt will typically tell you the version of Python you have installed:
However, if you failed to add Python to your PATH variable, this won't work. (As shown below, Python isn't added to your system path by default upon installation.) See also: Add PATH environment variable in Windows 10
Also, keep in mind you might have more than one version of Python installed. I have Python installed as a dependency for something and another version installed that I use to write code.
An alternative method would be to do the following:
For example, many of the search results here indicate that I have version 3.11 installed. Keep these search results open if you want to add Python to your path and you may want to refer to this in order to do so.
对于最新版本,请使用以下 python 版本命令
For the latest versions please use the below command for the python version
主要使用命令:
或者
Mostly usage commands:
Or
对于 bash 脚本,这将是最简单的方法:
如果您只需要
major.minor
版本(例如3.6
),您可以使用上面的内容,然后选择前 3 个字符:或
For bash scripts this would be the easiest way:
And if you just need the
major.minor
version (e.g.3.6
) you can either use the above and then pick the first 3 characters:or
打开命令提示符窗口(按 Windows + R,输入
cmd
,然后按 Enter)。输入
python.exe
Open a command prompt window (press Windows + R, type in
cmd
, and hit Enter).Type
python.exe
要检查 Python 软件版本,应在命令提示符下使用以下代码:
参考: http://docs.python.org/using/cmdline.html#generic-options
To check the version of one's Python's Software version, one should use the following code in command prompt:
Reference: http://docs.python.org/using/cmdline.html#generic-options
在 Python IDE 中,只需复制并粘贴以下代码并运行它(版本将出现在输出区域中):
In a Python IDE, just copy and paste in the following code and run it (the version will come up in the output area):