我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用IPython.version_info()。
def get_ipython_version(): """Returns the current IPython version""" import IPython v = None if hasattr(IPython, "version_info"): v = '.'.join(map(str, IPython.version_info[:3])) else: try: try: v = IPython.Release.version except: try: v = IPython.release.version except: pass except: pass return StrictVersion(v) # PyTango utilities
def test_for(item, min_version=None, callback=extract_version): """Test to see if item is importable, and optionally check against a minimum version. If min_version is given, the default behavior is to check against the `__version__` attribute of the item, but specifying `callback` allows you to extract the value you are interested in. e.g:: In [1]: import sys In [2]: from IPython.testing.iptest import test_for In [3]: test_for('sys', (2,6), callback=lambda sys: sys.version_info) Out[3]: True """ try: check = import_item(item) except (ImportError, RuntimeError): # GTK reports Runtime error if it can't be initialized even if it's # importable. return False else: if min_version: if callback: # extra processing step to get version to compare check = callback(check) return check >= min_version else: return True # Global dict where we can store information on what we have and what we don't # have available at test run time
def install(): """Register `rlipython` as the default interactive interface for IPython. When you run this inside IPython, the preference gets applied to the current IPython profile. When run using plain Python, the preference gets applied to the default profile. Run `uninstall()` if you ever change your mind and want to revert to the default IPython behavior. """ if ipython_version < (5,4): print("`rliptyhon` will only work with IPython 5.4. or above. Aborting") return cfg, json_path = get_config() installed = cfg.get(app_key, {}).get(shell_key) == rl_config if installed: print ("Looks like rlipython is already installed.") return if get_ipython() is None: log.warning(DEFAULT_WARNING + json_path) with open(json_path, 'w') as f: cfg.update({app_key: {shell_key: rl_config}}) json.dump(cfg, f) print("Installation succeeded: enjoy rlipython the next time you run ipython!") if sys.platform == "darwin" and sys.version_info[:2] >= (3, 6): print(OSX_PY36_GNUREADLINE_WARNING)
def get_python_version(): return StrictVersion('.'.join(map(str, sys.version_info[:3]))) # IPython utilities