我已经尝试了两天来安装wxpython并为python3工作,但无济于事。我尝试了一系列安装方法,包括从源代码构建。
对于python2似乎安装正常,但在python3中我不能import wx
。
这是我最近的尝试。我想知道我错过了什么......
15 Feb 15:20 /~ ⋄ lsb_release -r
Release: 17.10
15 Feb 15:20 /~ ⋄ uname -a
Linux j-asus 4.13.0-32-generic #35-Ubuntu SMP Thu Jan 25 09:13:46 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
15 Feb 15:21 /~ ⋄ sudo apt install python-wxgtk3.0
[sudo] password for john:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
linux-headers-4.10.0-19 linux-headers-4.10.0-19-generic linux-image-4.10.0-19-generic linux-image-extra-4.10.0-19-generic
linux-signed-image-4.10.0-19-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
libwxbase3.0-0v5 libwxgtk3.0-0v5 python-wxversion
Suggested packages:
wx3.0-doc
The following NEW packages will be installed
libwxbase3.0-0v5 libwxgtk3.0-0v5 python-wxgtk3.0 python-wxversion
0 to upgrade, 4 to newly install, 0 to remove and 0 not to upgrade.
Need to get 10.2 MB of archives.
After this operation, 49.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://gb.archive.ubuntu.com/ubuntu artful/universe amd64 libwxbase3.0-0v5 amd64 3.0.3.1+dfsg2-1 [954 kB]
Get:2 http://gb.archive.ubuntu.com/ubuntu artful/universe amd64 libwxgtk3.0-0v5 amd64 3.0.3.1+dfsg2-1 [4,180 kB]
Get:3 http://gb.archive.ubuntu.com/ubuntu artful/universe amd64 python-wxversion all 3.0.2.0+dfsg-5 [12.4 kB]
Get:4 http://gb.archive.ubuntu.com/ubuntu artful/universe amd64 python-wxgtk3.0 amd64 3.0.2.0+dfsg-5 [5,068 kB]
Fetched 10.2 MB in 15s (672 kB/s)
Selecting previously unselected package libwxbase3.0-0v5:amd64.
(Reading database ... 229424 files and directories currently installed.)
Preparing to unpack .../libwxbase3.0-0v5_3.0.3.1+dfsg2-1_amd64.deb ...
Unpacking libwxbase3.0-0v5:amd64 (3.0.3.1+dfsg2-1) ...
Selecting previously unselected package libwxgtk3.0-0v5:amd64.
Preparing to unpack .../libwxgtk3.0-0v5_3.0.3.1+dfsg2-1_amd64.deb ...
Unpacking libwxgtk3.0-0v5:amd64 (3.0.3.1+dfsg2-1) ...
Selecting previously unselected package python-wxversion.
Preparing to unpack .../python-wxversion_3.0.2.0+dfsg-5_all.deb ...
Unpacking python-wxversion (3.0.2.0+dfsg-5) ...
Selecting previously unselected package python-wxgtk3.0.
Preparing to unpack .../python-wxgtk3.0_3.0.2.0+dfsg-5_amd64.deb ...
Unpacking python-wxgtk3.0 (3.0.2.0+dfsg-5) ...
Setting up python-wxversion (3.0.2.0+dfsg-5) ...
Setting up libwxbase3.0-0v5:amd64 (3.0.3.1+dfsg2-1) ...
Processing triggers for libc-bin (2.26-0ubuntu2.1) ...
Setting up libwxgtk3.0-0v5:amd64 (3.0.3.1+dfsg2-1) ...
Setting up python-wxgtk3.0 (3.0.2.0+dfsg-5) ...
update-alternatives: using /usr/lib/wx/python/wx3.0.pth to provide /usr/lib/wx/python/wx.pth (wx.pth) in auto mode
Processing triggers for libc-bin (2.26-0ubuntu2.1) ...
15 Feb 15:25 /~ ⋄ sudo apt install wx3.0-doc
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
linux-headers-4.10.0-19 linux-headers-4.10.0-19-generic linux-image-4.10.0-19-generic linux-image-extra-4.10.0-19-generic
linux-signed-image-4.10.0-19-generic
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed
wx3.0-doc
0 to upgrade, 1 to newly install, 0 to remove and 0 not to upgrade.
Need to get 14.4 MB of archives.
After this operation, 168 MB of additional disk space will be used.
Get:1 http://gb.archive.ubuntu.com/ubuntu artful/universe amd64 wx3.0-doc all 3.0.3.1+dfsg2-1 [14.4 MB]
Fetched 14.4 MB in 25s (574 kB/s)
Selecting previously unselected package wx3.0-doc.
(Reading database ... 229961 files and directories currently installed.)
Preparing to unpack .../wx3.0-doc_3.0.3.1+dfsg2-1_all.deb ...
Unpacking wx3.0-doc (3.0.3.1+dfsg2-1) ...
Processing triggers for doc-base (0.10.7) ...
Processing 1 added doc-base file...
Setting up wx3.0-doc (3.0.3.1+dfsg2-1) ...
15 Feb 15:26 /~ ⋄ python3
Python 3.6.3 (default, Oct 3 2017, 21:45:48)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'wx'
>>>
15 Feb 15:32 /~ ⋄ python
Python 2.7.14 (default, Sep 23 2017, 22:06:14)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> print wx.version()
3.0.2.0 gtk2 (classic)
[编辑...] 按照建议尝试pip3安装wxpython'。这失败了:
checking for GTK+ - version >= 3.0.0... Package gtk+-3.0 was not found in the pkg-config search path.
No package 'gtk+-3.0' found
Package gthread-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gthread-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gthread-2.0' found
no
*** Could not run GTK+ test program, checking why...
*** The test program failed to compile or link. See the file config.log for the
*** exact error that occured. This usually means GTK+ is incorrectly installed.
configure: error:
The development files for GTK+ were not found. For GTK+ 2, please
ensure that pkg-config is in the path and that gtk+-2.0.pc is
installed. For GTK+ 1.2 please check that gtk-config is in the path,
and that the version is 1.2.3 or above. Also check that the
libraries returned by 'pkg-config gtk+-2.0 --libs' or 'gtk-config
--libs' are in the LD_LIBRARY_PATH or equivalent.
Error running configure
ERROR: failed building wxWidgets
Traceback (most recent call last):
File "build.py", line 1295, in cmd_build_wx
wxbuild.main(wxDir(), build_options)
File "/tmp/pip-build-4grsohuv/wxpython/buildtools/build_wxwidgets.py", line 374, in main
"Error running configure")
File "/tmp/pip-build-4grsohuv/wxpython/buildtools/build_wxwidgets.py", line 85, in exitIfError
raise builder.BuildError(msg)
buildtools.builder.BuildError: Error running configure
Finished command: build_wx (0m3.672s)
Finished command: build (0m3.672s)
Command '"/usr/bin/python3" -u build.py build' failed with exit code 1.
所以现在我想尝试@ravnsgaard的想法,但我不确定 (a)我是否需要恢复上述安装失败所做的更改? (b)我需要哪些依赖项,例如我需要的gtk +包的名称究竟是什么......
答案 0 :(得分:1)
您想创建virtualenv,然后使用pip3进行安装。就像萨克森的罗尔夫所说的那样,试试你的virtualenv中的pip3 install wxpython
。它将下载六个(依赖项)和最新的wxPython(目前为4.0.1)并从源代码构建它。
对于all the usual reasons,您通常不希望在系统级安装wxPython。
您还需要确保安装了构建wxWidgets所需的开发包:gtk-dev,gstreamer等。如果构建失败,您可以检查日志文件以获取详细信息。