gpt4 book ai didi

python - Tcl 错误 : no display name and no $DISPLAY environment variable on Windows 10 Bash

转载 作者:太空狗 更新时间:2023-10-30 00:43:30 27 4
gpt4 key购买 nike

我尝试在 Windows 10 Bash shell 上安装 matplotlib。

之后,我运行了以下几行:

$ ipython3

然后

In[1]: %pylab

然后它给了我以下错误:

---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-1-4ab7ec3413a5> in <module>()
----> 1 get_ipython().magic('pylab')

/usr/lib/python3/dist-packages/IPython/core/interactiveshell.py in magic(self, arg_s)
2164 magic_name, _, magic_arg_s = arg_s.partition(' ')
2165 magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2166 return self.run_line_magic(magic_name, magic_arg_s)
2167
2168 #-------------------------------------------------------------------------

/usr/lib/python3/dist-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line)
2085 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
2086 with self.builtin_trap:
-> 2087 result = fn(*args,**kwargs)
2088 return result
2089

/usr/lib/python3/dist-packages/IPython/core/magics/pylab.py in pylab(self, line)

/usr/lib/python3/dist-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
190 # but it's overkill for just that one bit of state.
191 def magic_deco(arg):
--> 192 call = lambda f, *a, **k: f(*a, **k)
193
194 if isinstance(arg, collections.Callable):

/usr/lib/python3/dist-packages/IPython/core/magics/pylab.py in pylab(self, line)
129 import_all = not args.no_import_all
130
--> 131 gui, backend, clobbered = self.shell.enable_pylab(args.gui, import_all=import_all)
132 self._show_matplotlib_backend(args.gui, backend)
133 print ("Populating the interactive namespace from numpy and matplotlib")

/usr/lib/python3/dist-packages/IPython/core/interactiveshell.py in enable_pylab(self, gui, import_all, welcome_message)
2918 from IPython.core.pylabtools import import_pylab
2919
-> 2920 gui, backend = self.enable_matplotlib(gui)
2921
2922 # We want to prevent the loading of pylab to pollute the user's

/usr/lib/python3/dist-packages/IPython/core/interactiveshell.py in enable_matplotlib(self, gui)
2879 gui, backend = pt.find_gui_and_backend(self.pylab_gui_select)
2880
-> 2881 pt.activate_matplotlib(backend)
2882 pt.configure_inline_support(self, backend)
2883

/usr/lib/python3/dist-packages/IPython/core/pylabtools.py in activate_matplotlib(backend)
244 matplotlib.rcParams['backend'] = backend
245
--> 246 import matplotlib.pyplot
247 matplotlib.pyplot.switch_backend(backend)
248

/usr/local/lib/python3.4/dist-packages/matplotlib/pyplot.py in <module>()
2510 # are no-ops and the registered function respect `mpl.is_interactive()`
2511 # to determine if they should trigger a draw.
-> 2512 install_repl_displayhook()
2513
2514 ################# REMAINING CONTENT GENERATED BY boilerplate.py ##############

/usr/local/lib/python3.4/dist-packages/matplotlib/pyplot.py in install_repl_displayhook()
163 ipython_gui_name = backend2gui.get(get_backend())
164 if ipython_gui_name:
--> 165 ip.enable_gui(ipython_gui_name)
166 else:
167 _INSTALL_FIG_OBSERVER = True

/usr/lib/python3/dist-packages/IPython/terminal/interactiveshell.py in enable_gui(gui, app)
306 from IPython.lib.inputhook import enable_gui as real_enable_gui
307 try:
--> 308 return real_enable_gui(gui, app)
309 except ValueError as e:
310 raise UsageError("%s" % e)

/usr/lib/python3/dist-packages/IPython/lib/inputhook.py in enable_gui(gui, app)
526 e = "Invalid GUI request %r, valid ones are:%s" % (gui, list(guis.keys()))
527 raise ValueError(e)
--> 528 return gui_hook(app)
529

/usr/lib/python3/dist-packages/IPython/lib/inputhook.py in enable_tk(self, app)
322 if app is None:
323 import tkinter
--> 324 app = tkinter.Tk()
325 app.withdraw()
326 self._apps[GUI_TK] = app

/usr/lib/python3.4/tkinter/__init__.py in __init__(self, screenName, baseName, className, useTk, sync, use)
1852 baseName = baseName + ext
1853 interactive = 0
-> 1854 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1855 if useTk:
1856 self._loadtk()

TclError: no display name and no $DISPLAY environment variable

如果有人能指出如何消除此错误,我将不胜感激。谢谢。

最佳答案

Windows 上没有官方的bash 显示环境。

  • 您需要安装非官方显示环境,即xming ( https://sourceforge.net/projects/xming/ )
  • 安装 xming 后,您需要导出为 DISPLAY=:0
  • 您还需要安装 qtconsole。 sudo apt-get install qtconsole

但是,我不建议采用这种方式,在 Windows 上使用 ipython 有一种更简单的方法。您可以在 Windows 上安装 Anaconda 并且可以使用 ipython 而不会出现像这样的任何问题 (https://www.continuum.io/downloads)

关于python - Tcl 错误 : no display name and no $DISPLAY environment variable on Windows 10 Bash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39804366/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com