我正在使用Eclipse和为PyPy解释器(2.7 python)配置的PyDev插件。 我无法将Tkinter包含在我的项目中。 我在Eclipse中遇到的错误如下:
File "C:\PyPy\lib-python\2.7\lib-tk\Tkinter.py", line 39, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
我尝试使用easy_install来安装tkinter但是它失败并引用了vcvarsall.bat文件(我的计算机上安装了VS 2010)
我尝试应用此帖python - How do I point easy_install to vcvarsall.bat中的解决方案 我用GCC(C ++)编译器安装了MinGW。导出的DLL但仍然无法编译... 我的tkinter编译失败,出现以下错误:
src/_tkinter.c:74:17: fatal error: tcl.h: No such file or directory
compilation terminated.
error: Setup script exited with error: command 'gcc' failed with exit status 1
我将ActiveTcl Community Edition安装到Tcl文件夹,其中包含所有需要的文件...
有没有办法将gcc'指向'ActiveTcl才能完成编译?
答案 0 :(得分:1)
我已经在Windows上编译了tkinter(在Windows 8 64位上测试过,但我相信它也可以在Windows 7上运行)。
以下是我采取的步骤:
安装Microsoft Visual Studio C ++ 2008 SP1 Express Edition
** KS:此处可用:http://go.microsoft.com/?linkid=7729279
安装TclTk 8.5(ActiveTcl Community Edition 8.5.13)
** KS:如果您安装了32位pypy,请务必安装32位版本。
解压缩pypy-c-jit-latest-win32(或其中一个2.0测试版)
下载http://python-distribute.org/distribute_setup.py
运行pypy.exe distribute_setup.py
下载并解包https://bitbucket.org/pypy/tkinter/get/default.zip
修改pypy-tkinter / setup.py,如下所示:
将“c:/ tcl”替换为用于ActiveTcl的安装位置,将“c:/ pypy-c-jit-latest-win32”替换为pypy的安装位置
更改库以使用其Windows文件名,并引用pypy附带的“python27”库: (我的参赛作品如下所示)
library_dirs=["c:/tcl/lib", "c:/pypy-c-jit-latest-win32/include"]
include_dirs=["c:/tcl/include", "c:/pypy-c-jit-latest-win32/include"]
libraries=["tk85", "tcl85", "python27"]
从pypy-tkinter目录运行pypy.exe setup.py install。它应该编译并安装site-packages \ tkinter_pypy-0.1-py2.7-win32.egg。
注意:我还将我的Python 2.7.3(CPython)安装中的'tcl'文件夹复制到包含pypy.exe可执行文件的文件夹中。
我刚刚在我的pypy安装上运行了lib-tk \ test \ runtktests.py,结果如下:
testLoadTk (test_tkinter.test_loadtk.TkLoadTest) ... skipped 'No $DISPLAY set.'
testLoadTkFailure (test_tkinter.test_loadtk.TkLoadTest) ... ok
test_search (test_tkinter.test_text.TextTest) ... ok
test_horizontal_range (test_ttk.test_extensions.LabeledScaleTest) ... ok
test_initialization (test_ttk.test_extensions.LabeledScaleTest) ... ok
test_resize (test_ttk.test_extensions.LabeledScaleTest) ... ok
test_variable_change (test_ttk.test_extensions.LabeledScaleTest) ... ok
test_widget_destroy (test_ttk.test_extensions.LabeledScaleTest) ... FAIL
test_initialization (test_ttk.test_extensions.OptionMenuTest) ... ok
test_menu (test_ttk.test_extensions.OptionMenuTest) ... ok
test_widget_destroy (test_ttk.test_extensions.OptionMenuTest) ... FAIL
test_convert_stringval (test_ttk.test_functions.InternalFunctionsTest) ... ok
test_dict_from_tcltuple (test_ttk.test_functions.InternalFunctionsTest) ... ok
test_format_elemcreate (test_ttk.test_functions.InternalFunctionsTest) ... ok
test_format_layoutlist (test_ttk.test_functions.InternalFunctionsTest) ... ok
test_format_mapdict (test_ttk.test_functions.InternalFunctionsTest) ... ok
test_format_optdict (test_ttk.test_functions.InternalFunctionsTest) ... ok
test_list_from_layouttuple (test_ttk.test_functions.InternalFunctionsTest) ... ok
test_list_from_statespec (test_ttk.test_functions.InternalFunctionsTest) ... ok
test_script_from_settings (test_ttk.test_functions.InternalFunctionsTest) ... ok
test_val_or_dict (test_ttk.test_functions.InternalFunctionsTest) ... ok
test_multivalues (test_ttk.test_functions.TclObjsToPyTest) ... ok
test_nosplit (test_ttk.test_functions.TclObjsToPyTest) ... ok
test_unicode (test_ttk.test_functions.TclObjsToPyTest) ... ok
test_configure (test_ttk.test_style.StyleTest) ... ok
test_layout (test_ttk.test_style.StyleTest) ... ok
test_lookup (test_ttk.test_style.StyleTest) ... ok
test_map (test_ttk.test_style.StyleTest) ... ok
test_theme_use (test_ttk.test_style.StyleTest) ... ok
test_identify (test_ttk.test_widgets.WidgetTest) ... ok
test_widget_state (test_ttk.test_widgets.WidgetTest) ... ok
test_invoke (test_ttk.test_widgets.ButtonTest) ... ok
test_invoke (test_ttk.test_widgets.CheckbuttonTest) ... ok
test_invoke (test_ttk.test_widgets.RadiobuttonTest) ... ok
test_postcommand (test_ttk.test_widgets.ComboboxTest) ... ok
test_values (test_ttk.test_widgets.ComboboxTest) ... ok
test_virtual_event (test_ttk.test_widgets.ComboboxTest) ... ok
test_bbox (test_ttk.test_widgets.EntryTest) ... ok
test_identify (test_ttk.test_widgets.EntryTest) ... ok
test_revalidation (test_ttk.test_widgets.EntryTest) ... ok
test_validation (test_ttk.test_widgets.EntryTest) ... ok
test_validation_options (test_ttk.test_widgets.EntryTest) ... ok
test_add (test_ttk.test_widgets.PanedwindowTest) ... ok
test_forget (test_ttk.test_widgets.PanedwindowTest) ... ok
test_insert (test_ttk.test_widgets.PanedwindowTest) ... ok
test_pane (test_ttk.test_widgets.PanedwindowTest) ... ok
test_sashpos (test_ttk.test_widgets.PanedwindowTest) ... ok
test_custom_event (test_ttk.test_widgets.ScaleTest) ... ok
test_get (test_ttk.test_widgets.ScaleTest) ... ok
test_set (test_ttk.test_widgets.ScaleTest) ... FAIL
test_add_and_hidden (test_ttk.test_widgets.NotebookTest) ... ok
test_forget (test_ttk.test_widgets.NotebookTest) ... ok
test_index (test_ttk.test_widgets.NotebookTest) ... ok
test_insert (test_ttk.test_widgets.NotebookTest) ... ok
test_select (test_ttk.test_widgets.NotebookTest) ... ok
test_tab (test_ttk.test_widgets.NotebookTest) ... ok
test_tab_identifiers (test_ttk.test_widgets.NotebookTest) ... ok
test_tabs (test_ttk.test_widgets.NotebookTest) ... ok
test_traversal (test_ttk.test_widgets.NotebookTest) ... ok
test_bbox (test_ttk.test_widgets.TreeviewTest) ... ok
test_children (test_ttk.test_widgets.TreeviewTest) ... ok
test_column (test_ttk.test_widgets.TreeviewTest) ... ok
test_delete (test_ttk.test_widgets.TreeviewTest) ... ok
test_detach_reattach (test_ttk.test_widgets.TreeviewTest) ... ok
test_exists (test_ttk.test_widgets.TreeviewTest) ... ok
test_focus (test_ttk.test_widgets.TreeviewTest) ... ok
test_heading (test_ttk.test_widgets.TreeviewTest) ... ok
test_heading_callback (test_ttk.test_widgets.TreeviewTest) ... skipped 'skipping pending resolution of Issue #10734'
test_index (test_ttk.test_widgets.TreeviewTest) ... ok
test_insert_item (test_ttk.test_widgets.TreeviewTest) ... ok
test_set (test_ttk.test_widgets.TreeviewTest) ... ok
test_tag_bind (test_ttk.test_widgets.TreeviewTest) ... ok
test_tag_configure (test_ttk.test_widgets.TreeviewTest) ... ok
======================================================================
FAIL: test_widget_destroy (test_ttk.test_extensions.LabeledScaleTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\pypy-c-jit-latest-win32\lib-python\2.7\lib-tk\test\test_ttk\test_extensions.py", line 25, in test_widget_destroy
self.assertRaises(Tkinter.TclError, x.tk.globalgetvar, var)
AssertionError: TclError not raised
======================================================================
FAIL: test_widget_destroy (test_ttk.test_extensions.OptionMenuTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\pypy-c-jit-latest-win32\lib-python\2.7\lib-tk\test\test_ttk\test_extensions.py", line 202, in test_widget_destroy
self.assertRaises(Tkinter.TclError, optmenu.tk.globalgetvar, name)
AssertionError: TclError not raised
======================================================================
FAIL: test_set (test_ttk.test_widgets.ScaleTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\pypy-c-jit-latest-win32\lib-python\2.7\lib-tk\test\test_ttk\test_widgets.py", line 522, in test_set
self.assertEqual(self.scale.get(), max + 10)
AssertionError: 6.0 != 11.0
----------------------------------------------------------------------
Ran 73 tests in 2.214s
答案 1 :(得分:0)
tkinter本身不附带pypy, 有一个包可以让它在pypi上运行