我已經安裝了哪個版本的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.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章