问题:我已经安装了哪个版本的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.
回答 0
回答 1
Python 2.5以上版本:
python --version
Python 2.4-:
python -c 'import sys; print(sys.version)'
Python 2.5+:
python --version
Python 2.4-:
python -c 'import sys; print(sys.version)'
回答 2
在Python IDE中,只需复制并粘贴以下代码并运行它(版本将显示在输出区域中):
import sys
print(sys.version)
In a Python IDE, just copy and paste in the following code and run it (the version will come up in the output area):
import sys
print(sys.version)
回答 3
在命令提示符下键入:
python -V
或者,如果您有pyenv:
pyenv versions
At a command prompt type:
python -V
Or if you have pyenv:
pyenv versions
回答 4
当我打开Python (command line)
第一件事时,它会告诉我版本。
When I open Python (command line)
the first thing it tells me is the version.
回答 5
尽管问题是“我正在使用哪个版本?”,但这实际上可能并不是您需要知道的所有内容。您可能安装了其他版本,这可能会导致问题,尤其是在安装其他模块时。这是我了解安装了哪些版本的粗略方法:
updatedb # Be in root for this
locate site.py # All installations I've ever seen have this
单个Python安装的输出应如下所示:
/usr/lib64/python2.7/site.py
/usr/lib64/python2.7/site.pyc
/usr/lib64/python2.7/site.pyo
多个安装将输出如下内容:
/root/Python-2.7.6/Lib/site.py
/root/Python-2.7.6/Lib/site.pyc
/root/Python-2.7.6/Lib/site.pyo
/root/Python-2.7.6/Lib/test/test_site.py
/usr/lib/python2.6/site-packages/site.py
/usr/lib/python2.6/site-packages/site.pyc
/usr/lib/python2.6/site-packages/site.pyo
/usr/lib64/python2.6/site.py
/usr/lib64/python2.6/site.pyc
/usr/lib64/python2.6/site.pyo
/usr/local/lib/python2.7/site.py
/usr/local/lib/python2.7/site.pyc
/usr/local/lib/python2.7/site.pyo
/usr/local/lib/python2.7/test/test_site.py
/usr/local/lib/python2.7/test/test_site.pyc
/usr/local/lib/python2.7/test/test_site.pyo
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:
updatedb # Be in root for this
locate site.py # All installations I've ever seen have this
The output for a single Python installation should look something like this:
/usr/lib64/python2.7/site.py
/usr/lib64/python2.7/site.pyc
/usr/lib64/python2.7/site.pyo
Multiple installations will have output something like this:
/root/Python-2.7.6/Lib/site.py
/root/Python-2.7.6/Lib/site.pyc
/root/Python-2.7.6/Lib/site.pyo
/root/Python-2.7.6/Lib/test/test_site.py
/usr/lib/python2.6/site-packages/site.py
/usr/lib/python2.6/site-packages/site.pyc
/usr/lib/python2.6/site-packages/site.pyo
/usr/lib64/python2.6/site.py
/usr/lib64/python2.6/site.pyc
/usr/lib64/python2.6/site.pyo
/usr/local/lib/python2.7/site.py
/usr/local/lib/python2.7/site.pyc
/usr/local/lib/python2.7/site.pyo
/usr/local/lib/python2.7/test/test_site.py
/usr/local/lib/python2.7/test/test_site.pyc
/usr/local/lib/python2.7/test/test_site.pyo
回答 6
In [1]: import sys
In [2]: sys.version
2.7.11 |Anaconda 2.5.0 (64-bit)| (default, Dec 6 2015, 18:08:32)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
In [3]: sys.version_info
sys.version_info(major=2, minor=7, micro=11, releaselevel='final', serial=0)
In [4]: sys.version_info >= (2,7)
Out[4]: True
In [5]: sys.version_info >= (3,)
Out[5]: False
In [1]: import sys
In [2]: sys.version
2.7.11 |Anaconda 2.5.0 (64-bit)| (default, Dec 6 2015, 18:08:32)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
In [3]: sys.version_info
sys.version_info(major=2, minor=7, micro=11, releaselevel='final', serial=0)
In [4]: sys.version_info >= (2,7)
Out[4]: True
In [5]: sys.version_info >= (3,)
Out[5]: False
回答 7
简而言之:
键入python
在命令提示
只需打开命令提示符(Win+ R)并键入,cmd
然后在命令提示符中键入,即可python
为您提供有关版本的所有必要信息:
In short:
Type python
in a command prompt
Simply open the command prompt (Win + R) and type cmd
and in the command prompt then typing python
will give you all necessary information regarding versions:
回答 8
>>> import sys; print('{0[0]}.{0[1]}'.format(sys.version_info))
3.5
所以从命令行:
python -c "import sys; print('{0[0]}.{0[1]}'.format(sys.version_info))"
>>> import sys; print('{0[0]}.{0[1]}'.format(sys.version_info))
3.5
so from the command line:
python -c "import sys; print('{0[0]}.{0[1]}'.format(sys.version_info))"
回答 9
采用
python -V
要么
python --version
注意:请注意,python -V
命令中的“ V” 为大写V。python -v
(小“ v”)将以详细模式启动Python。
Use
python -V
or
python --version
NOTE: Please note that the “V” in the python -V
command is capital V. python -v
(small “v”) will launch Python in verbose mode.
回答 10
您可以使用以下命令获取Python的版本
python --version
您甚至可以使用以下命令获取venv中安装的任何软件包的版本pip freeze
:
pip freeze | grep "package name"
或将Python解释器用作:
In [1]: import django
In [2]: django.VERSION
Out[2]: (1, 6, 1, 'final', 0)
You can get the version of Python by using the following command
python --version
You can even get the version of any package installed in venv using pip freeze
as:
pip freeze | grep "package name"
Or using the Python interpreter as:
In [1]: import django
In [2]: django.VERSION
Out[2]: (1, 6, 1, 'final', 0)
回答 11
我在Windows 10上使用Python 3.7.0。
这是在命令提示符和Git Bash中对我有用的方法:
要运行Python并检查版本:
py
仅检查您拥有的版本:
py --version
要么
py -V # Make sure it is a capital V
注: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:
py
To only check which version you have:
py --version
or
py -V # Make sure it is a capital V
Note: python
, python --version
, python -V
,Python
, Python --version
, Python -V
did not work for me.
回答 12
如果您已经在REPL窗口中,但没有看到带有版本号的欢迎消息,则可以使用help()查看主要版本和次要版本:
>>>help()
Welcome to Python 3.6's help utility!
...
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:
>>>help()
Welcome to Python 3.6's help utility!
...
回答 13
要在Jupyter笔记本中检查Python版本,可以使用:
from platform import python_version
print(python_version())
获取版本号,例如:
3.7.3
要么:
import sys
print(sys.version)
以获取更多信息
3.7.3 (default, Apr 24 2019, 13:20:13) [MSC v.1915 32 bit (Intel)]
要么:
sys.version_info
获得主要版本,次要版本和微型版本
sys.version_info(major=3, minor=7, micro=3, releaselevel='final', serial=0)
To check the Python version in a Jupyter notebook, you can use:
from platform import python_version
print(python_version())
to get version number, as:
3.7.3
or:
import sys
print(sys.version)
to get more information, as
3.7.3 (default, Apr 24 2019, 13:20:13) [MSC v.1915 32 bit (Intel)]
or:
sys.version_info
to get major, minor and micro versions, as
sys.version_info(major=3, minor=7, micro=3, releaselevel='final', serial=0)
回答 14
只需创建一个以.py结尾的文件,然后将以下代码粘贴到并运行即可。
#!/usr/bin/python3.6
import platform
import sys
def linux_dist():
try:
return platform.linux_distribution()
except:
return "N/A"
print("""Python version: %s
dist: %s
linux_distribution: %s
system: %s
machine: %s
platform: %s
uname: %s
version: %s
""" % (
sys.version.split('\n'),
str(platform.dist()),
linux_dist(),
platform.system(),
platform.machine(),
platform.platform(),
platform.uname(),
platform.version(),
))
如果系统上安装了多个Python解释器版本,请运行以下命令。
在Linux上,在终端上运行:
ll /usr/bin/python*
在Windows上,在命令提示符下运行:
dir %LOCALAPPDATA%\Programs\Python
Just create a file ending with .py and paste the code below into and run it.
#!/usr/bin/python3.6
import platform
import sys
def linux_dist():
try:
return platform.linux_distribution()
except:
return "N/A"
print("""Python version: %s
dist: %s
linux_distribution: %s
system: %s
machine: %s
platform: %s
uname: %s
version: %s
""" % (
sys.version.split('\n'),
str(platform.dist()),
linux_dist(),
platform.system(),
platform.machine(),
platform.platform(),
platform.uname(),
platform.version(),
))
If several Python interpreter versions are installed on a system, run the following commands.
On Linux, run in a terminal:
ll /usr/bin/python*
On Windows, run in a command prompt:
dir %LOCALAPPDATA%\Programs\Python
回答 15
要在Windows上验证Python版本的命令,请在命令提示符下运行以下命令并验证输出:
c:\> python -V
Python 2.7.16
c:\> py -2 -V
Python 2.7.16
c:\> py -3 -V
Python 3.7.3
另外,要查看每个Python版本的文件夹配置,请运行以下命令:
For Python 2, 'py -2 -m site'
For Python 3, 'py -3 -m site'
To verify the Python version for commands on Windows, run the following commands in a command prompt and verify the output:
c:\> python -V
Python 2.7.16
c:\> py -2 -V
Python 2.7.16
c:\> py -3 -V
Python 3.7.3
Also, to see the folder configuration for each Python version, run the following commands:
For Python 2, 'py -2 -m site'
For Python 3, 'py -3 -m site'
回答 16
在具有Python 3.6的Windows 10上
python
Python 3.6.0a4 (v3.6.0a4:017cf260936b, Aug 16 2016, 00:59:16) [MSC v.1900 64 bit (AMD64)] on win32
python -V
Python 3.6.0a4
python --version
Python 3.6.0a4
On Windows 10 with Python 3.6
python
Python 3.6.0a4 (v3.6.0a4:017cf260936b, Aug 16 2016, 00:59:16) [MSC v.1900 64 bit (AMD64)] on win32
python -V
Python 3.6.0a4
python --version
Python 3.6.0a4
回答 17
如果已安装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.
回答 18
对我来说,打开CMD并运行
py
将显示类似
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
For me, opening CMD and running
py
will show something like
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
回答 19
打开命令提示符窗口(按Windows+ R,输入cmd
,然后单击Enter)。
类型 python.exe
Open a command prompt window (press Windows + R, type in cmd
, and hit Enter).
Type python.exe
回答 20
打字 where python
在Windows上命令提示符可能会告诉您在哪里安装了多个不同版本的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.
回答 21
主要是用法命令:
python -version
要么
python -V
Mostly usage commands:
python -version
Or
python -V
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。