简体   繁体   中英

How to install wxpython in Xubuntu 17.10

I have been trying for two days to get wxpython installed and working for python3, to no avail. I have tried a range of installation methods, including building from source.

It appears to be installed ok for python2, but in python3 I cannot import wx .

Here's my most recent attempt. I wonder what I am missing...

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)

[edit...] Tried pip3 install wxpython' as suggested. This failed:

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.

So now I want to try the idea of @ravnsgaard but am unsure (a) Whether I need to revert the changes made by the above failed install? (b) Exactly which dependencies I need, eg what exactly is the name of the gtk+ package I need...

You want to create a virtualenv and then use pip3 to install. Like Rolf of Saxony said, try pip3 install wxpython inside your virtualenv. It will download six (dependency) and the newest wxPython (currently 4.0.1) and build it from source.

For all the usual reasons you generally do not want to install wxPython at system level.

You will also need to make sure you have the development packages installed needed to build wxWidgets itself: gtk-dev, gstreamer, et al. If the build fails you can check the log file for details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM