通常情況下,我使用R,並且通常在想使事物可重複使用時使用sessionInfo()
。原因是我喜歡讓人們知道我使用的是什麼版本,我已經安裝/加載了哪些軟件包,以及我在哪些操作系統等等,以便它很清楚。在Python中是否有sessionInfo()等價物?
sessionInfo
返回R的版本,處理器類型(例如32/64位x86),操作系統,語言環境詳細信息以及哪些軟件包已加載。
我是新來的python,想知道是否有相當於Python?我希望在IPython的筆記本使用它...
通常情況下,我使用R,並且通常在想使事物可重複使用時使用sessionInfo()
。原因是我喜歡讓人們知道我使用的是什麼版本,我已經安裝/加載了哪些軟件包,以及我在哪些操作系統等等,以便它很清楚。在Python中是否有sessionInfo()等價物?
sessionInfo
返回R的版本,處理器類型(例如32/64位x86),操作系統,語言環境詳細信息以及哪些軟件包已加載。
我是新來的python,想知道是否有相當於Python?我希望在IPython的筆記本使用它...
下面將讓你們分開有:
In [1]: import IPython
In [2]: print IPython.sys_info()
{'codename': 'Work in Progress',
'commit_hash': '4dd36bf',
'commit_source': 'repository',
'default_encoding': 'UTF-8',
'ipython_path': '/Users/matthiasbussonnier/ipython/IPython',
'ipython_version': '2.0.0-dev',
'os_name': 'posix',
'platform': 'Darwin-11.4.2-x86_64-i386-64bit',
'sys_executable': '/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python',
'sys_platform': 'darwin',
'sys_version': '2.7.6 (default, Nov 28 2013, 17:25:22) \n[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)]'}
否則沒有標準的方式來獲得的導入模塊的版本。 pip freeze
會成家了大多數模塊的安裝版本的機器上,但:
In [3]: !pip freeze
Cython==0.20dev
Django==1.4.2
Fabric==1.7.0
Flask==0.9
Flask-Cache==0.10.1
Flask-Markdown==0.3
Flask-SQLAlchemy==0.16
Jinja2==2.7.1
Logbook==0.6.0
...
這是我們認爲應該在Python使IPython的「魔法」與它幫助之前得到解決的東西。這是經常要求的,我們不是肯定會找到應該做什麼和要求的妥協。
做pip凍結在Windows上工作? –
我沒有線索,如果它。 – Matt
有一個稱爲version_information的魔術包完成了這個。用pip install version_information
安裝。
%load_ext version_information
%version_information pandas, numpy, seaborn
輸出:
你也可以使用該解決方案從How to list imported modules?與!pip freeze
共同完成類似的東西。
#find the names of the imported modules
import types
def imports():
for name, val in globals().items():
if isinstance(val, types.ModuleType):
yield val.__name__
#exclude all modules not listed by `!pip freeze`
excludes = ['__builtin__', 'types', 'IPython.core.shadowns', 'sys', 'os']
imported_modules = [module for module in imports() if module not in excludes]
pip_modules = !pip freeze #you could also use `!conda list` with anaconda
#print the names and versions of the imported modules
for module in pip_modules:
name, version = module.split('==')
if name in imported_modules:
print(name + '\t' + version)
輸出:
pandas 0.16.2
numpy 1.9.2
seaborn 0.5.1
我無法弄清楚如何通過與進口模塊列表(例如modulenames
)到%version_information
魔命令(所有引號需要被移除),所以也許有人可以通過添加該信息來改善這個答案。
可能重複的[如何列出導入的模塊?](http://stackoverflow.com/questions/4858100/how-to-list-imported-modules) –
可能,但它不提供版本,操作系統,或python版本 –
@hlm沒有內建/標準方式。但是,你可以嘗試這個https://gist.github.com/tahajahangir/5275848#file-pyinfo-py – thefourtheye