本文整理汇总了Python中spyder.utils.programs.is_module_installed函数的典型用法代码示例。如果您正苦于以下问题:Python is_module_installed函数的具体用法?Python is_module_installed怎么用?Python is_module_installed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_module_installed函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_page
def setup_page(self):
# Connections group
connections_group = QGroupBox(_("Automatic connections"))
connections_label = QLabel(_("This pane can automatically "
"show an object's help information after "
"a left parenthesis is written next to it. "
"Below you can decide to which plugin "
"you want to connect it to turn on this "
"feature."))
connections_label.setWordWrap(True)
editor_box = self.create_checkbox(_("Editor"), 'connect/editor')
rope_installed = programs.is_module_installed('rope')
jedi_installed = programs.is_module_installed('jedi', '>=0.8.1')
editor_box.setEnabled(rope_installed or jedi_installed)
if not rope_installed and not jedi_installed:
editor_tip = _("This feature requires the Rope or Jedi libraries.\n"
"It seems you don't have either installed.")
editor_box.setToolTip(editor_tip)
ipython_box = self.create_checkbox(_("IPython Console"),
'connect/ipython_console')
connections_layout = QVBoxLayout()
connections_layout.addWidget(connections_label)
connections_layout.addWidget(editor_box)
connections_layout.addWidget(ipython_box)
connections_group.setLayout(connections_layout)
# Features group
features_group = QGroupBox(_("Additional features"))
math_box = self.create_checkbox(_("Render mathematical equations"),
'math')
req_sphinx = programs.is_module_installed('sphinx', '>=1.1')
math_box.setEnabled(req_sphinx)
if not req_sphinx:
sphinx_ver = programs.get_module_version('sphinx')
sphinx_tip = _("This feature requires Sphinx 1.1 or superior.")
sphinx_tip += "\n" + _("Sphinx %s is currently installed.") % sphinx_ver
math_box.setToolTip(sphinx_tip)
features_layout = QVBoxLayout()
features_layout.addWidget(math_box)
features_group.setLayout(features_layout)
# Source code group
sourcecode_group = QGroupBox(_("Source code"))
wrap_mode_box = self.create_checkbox(_("Wrap lines"), 'wrap')
sourcecode_layout = QVBoxLayout()
sourcecode_layout.addWidget(wrap_mode_box)
sourcecode_group.setLayout(sourcecode_layout)
# Final layout
vlayout = QVBoxLayout()
vlayout.addWidget(connections_group)
vlayout.addWidget(features_group)
vlayout.addWidget(sourcecode_group)
vlayout.addStretch(1)
self.setLayout(vlayout)
示例2: is_qtconsole_installed
def is_qtconsole_installed():
pyzmq_installed = programs.is_module_installed('zmq', version=ZMQ_REQVER)
pygments_installed = programs.is_module_installed('pygments')
qtconsole_installed = programs.is_module_installed('qtconsole',
version=QTCONSOLE_REQVER)
if pyzmq_installed and pygments_installed and qtconsole_installed:
return True
else:
return False
示例3: import_test
def import_test(self):
"""Raise ImportError if feature is not supported."""
from spyder.utils import programs
if not programs.is_module_installed('psutil', '>=0.2.0'):
# The `interval` argument in `psutil.cpu_percent` function
# was introduced in v0.2.0
raise ImportError
示例4: long_banner
def long_banner(self):
"""Banner for IPython widgets with pylab message"""
# Default banner
from IPython.core.usage import quick_guide
banner_parts = [
"Python %s\n" % self.interpreter_versions["python_version"],
'Type "copyright", "credits" or "license" for more information.\n\n',
"IPython %s -- An enhanced Interactive Python.\n" % self.interpreter_versions["ipython_version"],
quick_guide,
]
banner = "".join(banner_parts)
# Pylab additions
pylab_o = self.additional_options["pylab"]
autoload_pylab_o = self.additional_options["autoload_pylab"]
mpl_installed = programs.is_module_installed("matplotlib")
if mpl_installed and (pylab_o and autoload_pylab_o):
pylab_message = "\nPopulating the interactive namespace from " "numpy and matplotlib"
banner = banner + pylab_message
# Sympy additions
sympy_o = self.additional_options["sympy"]
if sympy_o:
lines = """
These commands were executed:
>>> from __future__ import division
>>> from sympy import *
>>> x, y, z, t = symbols('x y z t')
>>> k, m, n = symbols('k m n', integer=True)
>>> f, g, h = symbols('f g h', cls=Function)
"""
banner = banner + lines
return banner
示例5: load_plugin
def load_plugin(self):
"""Load the Jedi introspection plugin"""
if not programs.is_module_installed('jedi', JEDI_REQVER):
raise ImportError('Requires Jedi %s' % JEDI_REQVER)
jedi.settings.case_insensitive_completion = False
for lib in ['numpy', 'matplotlib']:
jedi.preload_module(lib)
示例6: set_umr_namelist
def set_umr_namelist(self):
"""Set UMR excluded modules name list"""
arguments, valid = QInputDialog.getText(self, _('UMR'),
_("Set the list of excluded modules as "
"this: <i>numpy, scipy</i>"),
QLineEdit.Normal,
", ".join(self.get_option('umr/namelist')))
if valid:
arguments = to_text_string(arguments)
if arguments:
namelist = arguments.replace(' ', '').split(',')
fixed_namelist = [module_name for module_name in namelist
if programs.is_module_installed(module_name)]
invalid = ", ".join(set(namelist)-set(fixed_namelist))
if invalid:
QMessageBox.warning(self, _('UMR'),
_("The following modules are not "
"installed on your machine:\n%s"
) % invalid, QMessageBox.Ok)
QMessageBox.information(self, _('UMR'),
_("Please note that these changes will "
"be applied only to new Python/IPython "
"consoles"), QMessageBox.Ok)
else:
fixed_namelist = []
self.set_option('umr/namelist', fixed_namelist)
示例7: setup_page
def setup_page(self):
ar_group = QGroupBox(_("Autorefresh"))
ar_box = self.create_checkbox(_("Enable autorefresh"),
'autorefresh')
ar_spin = self.create_spinbox(_("Refresh interval: "),
_(" ms"), 'autorefresh/timeout',
min_=100, max_=1000000, step=100)
filter_group = QGroupBox(_("Filter"))
filter_data = [
('exclude_private', _("Exclude private references")),
('exclude_capitalized', _("Exclude capitalized references")),
('exclude_uppercase', _("Exclude all-uppercase references")),
('exclude_unsupported', _("Exclude unsupported data types")),
]
filter_boxes = [self.create_checkbox(text, option)
for option, text in filter_data]
display_group = QGroupBox(_("Display"))
display_data = [('truncate', _("Truncate values"), '')]
if programs.is_module_installed('numpy'):
display_data.append(('minmax', _("Show arrays min/max"), ''))
display_data.append(
('remote_editing', _("Edit data in the remote process"),
_("Editors are opened in the remote process for NumPy "
"arrays, PIL images, lists, tuples and dictionaries.\n"
"This avoids transfering large amount of data between "
"the remote process and Spyder (through the socket)."))
)
display_boxes = [self.create_checkbox(text, option, tip=tip)
for option, text, tip in display_data]
ar_layout = QVBoxLayout()
ar_layout.addWidget(ar_box)
ar_layout.addWidget(ar_spin)
ar_group.setLayout(ar_layout)
filter_layout = QVBoxLayout()
for box in filter_boxes:
filter_layout.addWidget(box)
filter_group.setLayout(filter_layout)
display_layout = QVBoxLayout()
for box in display_boxes:
display_layout.addWidget(box)
display_group.setLayout(display_layout)
vlayout = QVBoxLayout()
vlayout.addWidget(ar_group)
vlayout.addWidget(filter_group)
vlayout.addWidget(display_group)
vlayout.addStretch(1)
self.setLayout(vlayout)
示例8: set_umr_namelist
def set_umr_namelist(self):
"""Set UMR excluded modules name list"""
arguments, valid = QInputDialog.getText(self, _('UMR'),
_("Set the list of excluded modules as "
"this: <i>numpy, scipy</i>"),
QLineEdit.Normal,
", ".join(self.get_option('umr/namelist')))
if valid:
arguments = to_text_string(arguments)
if arguments:
namelist = arguments.replace(' ', '').split(',')
fixed_namelist = []
non_ascii_namelist = []
for module_name in namelist:
if PY2:
if all(ord(c) < 128 for c in module_name):
if programs.is_module_installed(module_name):
fixed_namelist.append(module_name)
else:
QMessageBox.warning(self, _('Warning'),
_("You are working with Python 2, this means that "
"you can not import a module that contains non-"
"ascii characters."), QMessageBox.Ok)
non_ascii_namelist.append(module_name)
elif programs.is_module_installed(module_name):
fixed_namelist.append(module_name)
invalid = ", ".join(set(namelist)-set(fixed_namelist)-
set(non_ascii_namelist))
if invalid:
QMessageBox.warning(self, _('UMR'),
_("The following modules are not "
"installed on your machine:\n%s"
) % invalid, QMessageBox.Ok)
QMessageBox.information(self, _('UMR'),
_("Please note that these changes will "
"be applied only to new Python/IPython "
"consoles"), QMessageBox.Ok)
else:
fixed_namelist = []
self.set_option('umr/namelist', fixed_namelist)
示例9: register_plugin
def register_plugin(self):
"""Register plugin in Spyder's main window"""
self.pylint.treewidget.sig_edit_goto.connect(self.main.editor.load)
self.pylint.redirect_stdio.connect(
self.main.redirect_internalshell_stdio)
self.main.add_dockwidget(self)
pylint_act = create_action(self, _("Run static code analysis"),
triggered=self.run_pylint)
pylint_act.setEnabled(is_module_installed('pylint'))
self.register_shortcut(pylint_act, context="Pylint",
name="Run analysis")
self.main.source_menu_actions += [MENU_SEPARATOR, pylint_act]
self.main.editor.pythonfile_dependent_actions += [pylint_act]
示例10: load_plugin
def load_plugin(self):
"""Load the Rope introspection plugin"""
if not programs.is_module_installed('rope', ROPE_REQVER):
raise ImportError('Requires Rope %s' % ROPE_REQVER)
self.project = None
self.create_rope_project(root_path=get_conf_path())
submods = get_preferred_submodules()
actual = []
for submod in submods:
try:
imp.find_module(submod)
actual.append(submod)
except ImportError:
pass
if self.project is not None:
self.project.prefs.set('extension_modules', actual)
示例11: find_return_types
def find_return_types(module_context, func):
"""
Determines a set of potential return types for `func` using docstring hints
:type evaluator: jedi.evaluate.Evaluator
:type param: jedi.parser.tree.Param
:rtype: list
>>> from jedi.evaluate.docstrings import * # NOQA
>>> from jedi.evaluate.docstrings import _search_param_in_docstr
>>> from jedi.evaluate.docstrings import _evaluate_for_statement_string
>>> from jedi.evaluate.docstrings import _search_return_in_gooogledocstr
>>> from jedi.evaluate.docstrings import _search_return_in_numpydocstr
>>> from jedi._compatibility import builtins
>>> source = open(jedi.evaluate.docstrings.__file__.replace('.pyc', '.py'), 'r').read()
>>> script = jedi.Script(source)
>>> evaluator = script._evaluator
>>> func = script._get_module().names_dict['find_return_types'][0].parent
>>> types = find_return_types(evaluator, func)
>>> print('types = %r' % (types,))
>>> assert len(types) == 1
>>> assert types[0].base.obj is builtins.list
"""
def search_return_in_docstr(docstr):
# Check for Sphinx/Epydoc return hint
for p in DOCSTRING_RETURN_PATTERNS:
match = p.search(docstr)
if match:
return [_strip_rst_role(match.group(1))]
found = []
if not found:
# Check for numpy style return hint
found = _search_return_in_numpydocstr(docstr)
return found
try:
docstr = u(func.raw_doc)
except AttributeError:
docstr = u(func.doc)
types = []
for type_str in search_return_in_docstr(docstr):
if is_module_installed('jedi', '>=0.10.0;<0.11'):
type_ = _evaluate_for_statement_string(module_context, type_str)
else:
module = func.get_parent_until()
type_ = _evaluate_for_statement_string(module_context,
type_str, module)
types.extend(type_)
return types
示例12: create_module_bookmark_actions
def create_module_bookmark_actions(parent, bookmarks):
"""
Create bookmark actions depending on module installation:
bookmarks = ((module_name, url, title), ...)
"""
actions = []
for key, url, title in bookmarks:
# Create actions for scientific distros only if Spyder is installed
# under them
create_act = True
if key == 'xy' or key == 'winpython':
if not programs.is_module_installed(key):
create_act = False
if create_act:
act = create_bookmark_action(parent, url, title)
actions.append(act)
return actions
示例13: long_banner
def long_banner(self):
"""Banner for IPython widgets with pylab message"""
# Default banner
try:
from IPython.core.usage import quick_guide
except Exception:
quick_guide = ''
banner_parts = [
'Python %s\n' % self.interpreter_versions['python_version'],
'Type "copyright", "credits" or "license" for more information.\n\n',
'IPython %s -- An enhanced Interactive Python.\n' % \
self.interpreter_versions['ipython_version'],
quick_guide
]
banner = ''.join(banner_parts)
# Pylab additions
pylab_o = self.additional_options['pylab']
autoload_pylab_o = self.additional_options['autoload_pylab']
mpl_installed = programs.is_module_installed('matplotlib')
if mpl_installed and (pylab_o and autoload_pylab_o):
pylab_message = ("\nPopulating the interactive namespace from "
"numpy and matplotlib\n")
banner = banner + pylab_message
# Sympy additions
sympy_o = self.additional_options['sympy']
if sympy_o:
lines = """
These commands were executed:
>>> from __future__ import division
>>> from sympy import *
>>> x, y, z, t = symbols('x y z t')
>>> k, m, n = symbols('k m n', integer=True)
>>> f, g, h = symbols('f g h', cls=Function)
"""
banner = banner + lines
if (pylab_o and sympy_o):
lines = """
Warning: pylab (numpy and matplotlib) and symbolic math (sympy) are both
enabled at the same time. Some pylab functions are going to be overrided by
the sympy module (e.g. plot)
"""
banner = banner + lines
return banner
示例14: setup_option_actions
def setup_option_actions(self, exclude_private, exclude_uppercase,
exclude_capitalized, exclude_unsupported):
"""Setup the actions to show in the cog menu."""
self.setup_in_progress = True
self.exclude_private_action = create_action(self,
_("Exclude private references"),
tip=_("Exclude references which name starts"
" with an underscore"),
toggled=lambda state:
self.sig_option_changed.emit('exclude_private', state))
self.exclude_private_action.setChecked(exclude_private)
self.exclude_uppercase_action = create_action(self,
_("Exclude all-uppercase references"),
tip=_("Exclude references which name is uppercase"),
toggled=lambda state:
self.sig_option_changed.emit('exclude_uppercase', state))
self.exclude_uppercase_action.setChecked(exclude_uppercase)
self.exclude_capitalized_action = create_action(self,
_("Exclude capitalized references"),
tip=_("Exclude references which name starts with an "
"uppercase character"),
toggled=lambda state:
self.sig_option_changed.emit('exclude_capitalized', state))
self.exclude_capitalized_action.setChecked(exclude_capitalized)
self.exclude_unsupported_action = create_action(self,
_("Exclude unsupported data types"),
tip=_("Exclude references to unsupported data types"
" (i.e. which won't be handled/saved correctly)"),
toggled=lambda state:
self.sig_option_changed.emit('exclude_unsupported', state))
self.exclude_unsupported_action.setChecked(exclude_unsupported)
self.actions = [
self.exclude_private_action, self.exclude_uppercase_action,
self.exclude_capitalized_action, self.exclude_unsupported_action]
if is_module_installed('numpy'):
self.actions.extend([MENU_SEPARATOR, self.editor.minmax_action])
self.setup_in_progress = False
示例15: _shape_text
def _shape_text(self, text, colsep=u"\t", rowsep=u"\n",
transpose=False, skiprows=0, comments='#'):
"""Decode the shape of the given text"""
assert colsep != rowsep
out = []
text_rows = text.split(rowsep)[skiprows:]
for row in text_rows:
stripped = to_text_string(row).strip()
if len(stripped) == 0 or stripped.startswith(comments):
continue
line = to_text_string(row).split(colsep)
line = [try_to_parse(to_text_string(x)) for x in line]
out.append(line)
# Replace missing elements with np.nan's or None's
if programs.is_module_installed('numpy'):
from numpy import nan
out = list(zip_longest(*out, fillvalue=nan))
else:
out = list(zip_longest(*out, fillvalue=None))
# Tranpose the last result to get the expected one
out = [[r[col] for r in out] for col in range(len(out[0]))]
if transpose:
return [[r[col] for r in out] for col in range(len(out[0]))]
return out