本文共 2692 字,大约阅读时间需要 8 分钟。
本文翻译自:
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。
参考:
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 sysprint(sys.version)
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 djangoIn [2]: django.VERSIONOut[2]: (1, 6, 1, 'final', 0)
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 thislocate 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
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。
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 win32Type "help", "copyright", "credits" or "license" for more information.
转载地址:http://zbexb.baihongyu.com/