Linux系统教程:修复“ImportError: No module named wxversion

问题 我试着在[某某 Linux 发行版]上运行一个 Python 应用,但是我得到了这个错误“ImportError: No module named wxversion.”。我怎样才能解决 Python 程序中的这个错误呢?

  1. <span class="typ">Looking</span><span class="kwd">for</span><span class="pln"> python</span><span class="pun">...</span><span class="lit">2.7</span><span class="pun">.</span><span class="lit">9</span><span class="pun">-</span><span class="typ">Traceback</span><span class="pun">(</span><span class="pln">most recent call </span><span class="kwd">last</span><span class="pun">):</span>
  2. <span class="typ">File</span><span class="str">"/home/dev/playonlinux/python/check_python.py"</span><span class="pun">,</span><span class="pln"> line </span><span class="lit">1</span><span class="pun">,</span><span class="kwd">in</span>
  3. <span class="kwd">import</span><span class="pln"> os</span><span class="pun">,</span><span class="pln"> wxversion</span>
  4. <span class="typ">ImportError</span><span class="pun">:</span><span class="typ">No</span><span class="kwd">module</span><span class="pln"> named wxversion</span>
  5. <span class="pln">failed tests</span>

该错误表明,你的Python应用是基于GUI的,依赖于一个名为wxPython的缺失模块。wxPython是一个用于wxWidgets GUI库的Python扩展模块,普遍被C++程序员用来设计GUI应用。该wxPython扩展允许Python开发者在任何Python应用中方便地设计和整合GUI。

Linux系统教程:修复“ImportError: No module named wxversion

摇解决这个 import 错误,你需要在你的 Linux 上安装 wxPython,如下:

 

安装wxPython到Debian,Ubuntu或Linux Mint

  1. <span class="pln">$ sudo apt</span><span class="pun">-</span><span class="kwd">get</span><span class="pln"> install python</span><span class="pun">-</span><span class="pln">wxgtk2</span><span class="pun">.</span><span class="lit">8</span>

 

安装wxPython到Fedora

  1. <span class="pln">$ sudo yum install wxPython</span>

 

安装wxPython到CentOS/RHEL

wxPython可以在CentOS/RHEL的EPEL仓库中获取到,而基本仓库中则没有。因此,首先要在你的系统中启用EPEL仓库,然后使用yum命令来安装。

  1. <span class="pln">$ sudo yum install wxPython </span>

 

安装wxPython到Arch Linux

  1. <span class="pln">$ sudo pacman </span><span class="pun">-</span><span class="pln">S wxpython </span>

 

安装wxPython到Gentoo

  1. <span class="pln">$ emerge wxPython </span>

via: How to fix “ImportError: No module named wxversion” on Linux

作者:Dan Nanni 译者:GOLinux 校对:wxy

本文由 LCTT 原创翻译,Linux中国 荣誉推出

相关推荐