我已经安装了哪个版本的Python?

本文翻译自:Which version of Python do I have installed?

I have to run a Python script on a Windows server. 我必须在Windows服务器上运行Python脚本。 How can I know which version of Python I have, and does it even really matter? 我怎么知道我拥有哪个版本的Python,它真的很重要吗?

I was thinking of updating to the latest version of Python. 我当时想更新到最新版本的Python。


#1楼

参考:https://stackoom.com/question/bPwr/我已经安装了哪个版本的Python


#2楼

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)

#3楼

You can get the version of Python by using the following command 您可以使用以下命令获取Python的版本

python --version

You can even get the version of any package installed in venv using pip freeze as: 您甚至可以使用pip freeze Frozen获得venv中安装的任何软件包的版本,如下所示:

pip freeze | grep "package name"

Or using the Python interpreter as: 或将Python解释器用作:

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

#4楼

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

#5楼

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. 注意:请注意python -V命令中的“ V”为大写python -v (小“ v”)将以详细模式启动Python。


#6楼

For me, opening CMD and running 对我来说,打开CMD并运行

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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值