我安装了哪个版本的Python ?

时间:2021-01-27 06:58:14

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 latest version of Python.

我必须在Windows服务器上运行Python脚本。我怎么知道我有哪个Python版本,它真的重要吗?我正在考虑更新到Python的最新版本。

17 个解决方案

#1


423  

python -V

http://docs.python.org/using/cmdline.html#generic-options

http://docs.python.org/using/cmdline.html generic-options

--version may also work (introduced in version 2.5)

——版本也可以工作(在版本2.5中引入)

#2


100  

Python 2.5+:

Python 2.5 +:

python --version

Python 2.4-:

Python 2.4 -:

python -c 'import sys; print(sys.version)'

#3


80  

in a Python IDE just copy and paste in the following code and run it (the version will come up in the output area)

在Python IDE中,只需复制并粘贴以下代码并运行它(版本将出现在输出区域)

import sys
print(sys.version)

#4


25  

At a command prompt type:

在命令提示符下输入:

 python -V

#5


20  

When I open Python (command line) the first thing it tells me is the version.

当我打开Python(命令行)时,它首先告诉我的是版本。

#6


18  

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:

单个Python安装的输出应该如下所示:

/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

#7


9  

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

#8


6  

python -V

or

python --version

NOTE :- Please note that the "V" in python-V command is capital V. python -v (small "v") will launch Python in verbose mode.

注意:-请注意,python-V命令中的“V”是大写的V. python-V(小“V”)将以详细模式启动python。

#9


5  

>>> 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))"

#10


4  

you can get version of python by using following command

您可以使用以下命令获得python版本

python --version

You can even get version of any package installed in venv using pip freeze as

您甚至可以使用pip freeze as获得任何安装在venv中的包的版本

pip freeze | grep "package name"

or using python interpreter as

或者使用python解释器as

In [1]: import django
In [2]: django.VERSION
Out[2]: (1, 6, 1, 'final', 0)

#11


4  

just start it at terminal

从终点站开始

python
sergio@tarro:
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

#12


3  

In Short :

简而言之:

Type python in command prompt

在命令提示符中输入python

Simply open command prompt (Clr + R) and type cmd and and in command prompt then typing python will give you all necessary info regarding versions

只要打开命令提示符(Clr + R),输入cmd,在命令提示符中输入python,就会得到关于版本的所有必要信息

我安装了哪个版本的Python ?

#13


1  

For me. open CMD and run py it 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.

给我。打开CMD并运行py,它将显示类似Python 3.4.3 (v3.4.3:9b73f1c3e601, 2015年2月24日,22:43:06)的内容。关于win32类型的“帮助”,“版权”,“积分”或“许可”的更多信息。

#14


0  

On Windows 10 with Python 3.6

在使用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

#15


0  

Open a command prompt window (press Windows+R, type in cmd, and hit enter). Type python.exe

打开命令提示窗口(按Windows+R,输入cmd,点击enter)。类型python.exe

#16


0  

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.

如果已经安装了Python,那么检查版本号的最简单方法是在命令提示符中输入“Python”。它将显示版本号,如果它运行在32位或64位以及其他信息上。对于某些应用程序,您可能希望拥有最新的版本,但有时不会。这取决于您希望安装或使用的包。

#17


0  

Just create a file ending with .py and paste the code bellow into and run it.

只需创建一个以.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(),
))

If several Python interpreter versions are installed on a system, run the following commands.

如果系统上安装了多个Python解释器版本,请运行以下命令。

On Linux run in terminal:

在Linux上运行的终端:

ll /usr/bin/python*

On Windows run in command prompt:

在Windows上运行命令提示符:

dir %LOCALAPPDATA%\Programs\Python

#1


423  

python -V

http://docs.python.org/using/cmdline.html#generic-options

http://docs.python.org/using/cmdline.html generic-options

--version may also work (introduced in version 2.5)

——版本也可以工作(在版本2.5中引入)

#2


100  

Python 2.5+:

Python 2.5 +:

python --version

Python 2.4-:

Python 2.4 -:

python -c 'import sys; print(sys.version)'

#3


80  

in a Python IDE just copy and paste in the following code and run it (the version will come up in the output area)

在Python IDE中,只需复制并粘贴以下代码并运行它(版本将出现在输出区域)

import sys
print(sys.version)

#4


25  

At a command prompt type:

在命令提示符下输入:

 python -V

#5


20  

When I open Python (command line) the first thing it tells me is the version.

当我打开Python(命令行)时,它首先告诉我的是版本。

#6


18  

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:

单个Python安装的输出应该如下所示:

/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

#7


9  

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

#8


6  

python -V

or

python --version

NOTE :- Please note that the "V" in python-V command is capital V. python -v (small "v") will launch Python in verbose mode.

注意:-请注意,python-V命令中的“V”是大写的V. python-V(小“V”)将以详细模式启动python。

#9


5  

>>> 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))"

#10


4  

you can get version of python by using following command

您可以使用以下命令获得python版本

python --version

You can even get version of any package installed in venv using pip freeze as

您甚至可以使用pip freeze as获得任何安装在venv中的包的版本

pip freeze | grep "package name"

or using python interpreter as

或者使用python解释器as

In [1]: import django
In [2]: django.VERSION
Out[2]: (1, 6, 1, 'final', 0)

#11


4  

just start it at terminal

从终点站开始

python
sergio@tarro:
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

#12


3  

In Short :

简而言之:

Type python in command prompt

在命令提示符中输入python

Simply open command prompt (Clr + R) and type cmd and and in command prompt then typing python will give you all necessary info regarding versions

只要打开命令提示符(Clr + R),输入cmd,在命令提示符中输入python,就会得到关于版本的所有必要信息

我安装了哪个版本的Python ?

#13


1  

For me. open CMD and run py it 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.

给我。打开CMD并运行py,它将显示类似Python 3.4.3 (v3.4.3:9b73f1c3e601, 2015年2月24日,22:43:06)的内容。关于win32类型的“帮助”,“版权”,“积分”或“许可”的更多信息。

#14


0  

On Windows 10 with Python 3.6

在使用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

#15


0  

Open a command prompt window (press Windows+R, type in cmd, and hit enter). Type python.exe

打开命令提示窗口(按Windows+R,输入cmd,点击enter)。类型python.exe

#16


0  

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.

如果已经安装了Python,那么检查版本号的最简单方法是在命令提示符中输入“Python”。它将显示版本号,如果它运行在32位或64位以及其他信息上。对于某些应用程序,您可能希望拥有最新的版本,但有时不会。这取决于您希望安装或使用的包。

#17


0  

Just create a file ending with .py and paste the code bellow into and run it.

只需创建一个以.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(),
))

If several Python interpreter versions are installed on a system, run the following commands.

如果系统上安装了多个Python解释器版本,请运行以下命令。

On Linux run in terminal:

在Linux上运行的终端:

ll /usr/bin/python*

On Windows run in command prompt:

在Windows上运行命令提示符:

dir %LOCALAPPDATA%\Programs\Python