Python ImportError:没有名为 wx 的模块
很抱歉再次问这个问题。我在 stackoverflow 和一般谷歌搜索上搜索并发现了无数重复的内容。不幸的是,我无法对我的系统进行排序。
我有以下内容:
C:\Python27\Lib\site-packages\wx-2.8-msw-unicode
此文件夹包含 wx 文件夹以及 wx & wxPython 文件夹,每个文件夹包含
_init_.py
文件
当我导入 wx 时,收到错误消息 “没有名为 wx 的模块”
我需要做什么才能让 Python 找到相关文件让我成功“导入wx”
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(16)
确保在编译器中选择正确的项目解释器。我使用Pycharm,也遇到了同样的问题。通过选择正确的解释器解决了这个问题。
此视频可能会对您有所帮助。
Make sure you choose the right project intepreter in the compiler. I used the Pycharm, and I encountered the same problem. And it was solved by choose the right intepreter.
Thisvideo may help you.
通常,site-packages 文件夹中的包名称旨在使用模块或子文件夹的确切名称导入。
如果我的 site-packages 文件夹有一个名为“foobar”的子文件夹,我将通过输入
import foobar
导入该包。一种解决方案可能是将
site-packages\wx-2.8-msw-unicode
重命名为site-packages\wx
。或者您可以将 C:\Python27\Lib\site-packages\wx-2.8-msw-unicode 添加到 PYTHONPATH 环境变量中。
Generally, package names in the site-packages folder are intended to be imported using the exact name of the module or subfolder.
If my site-packages folder has a subfolder named "foobar", I would import that package by typing
import foobar
.One solution might be to rename
site-packages\wx-2.8-msw-unicode
tosite-packages\wx
.Or you could add
C:\Python27\Lib\site-packages\wx-2.8-msw-unicode
to your PYTHONPATH environment variable.乌班图:
Ubuntu:
对于 Windows 和 MacOS,只需使用 pip 安装即可
参考:官方网站
For Windows and MacOS, Simply install it with pip
Reference: Official site
Windows:
转到
C:\Python27\Lib\site-packages\
找到文件夹wx--msw
或类似的移动
wx来自将上述文件夹移动到
C:\Python27\Lib\site-packages\
Windows:
Go to
C:\Python27\Lib\site-packages\
find the folderwx-<version>-msw
or similarMove the
wx
from the above folder toC:\Python27\Lib\site-packages\
这对我有用
This worked for me
我今天遇到了同样的错误,但我尝试了一些方法,令人惊讶的是它有效。在站点包文件夹中会有一个名为 wx.pth 的文件。使用记事本打开它,其内容类似于“wx-2.8-msw-unicode”,
它基本上是包含
wxpython
的文件夹的名称。使用 Ctrl + A 删除它,并从站点包中复制文件夹的名称并将其粘贴到此处,即使它是相同的。听起来很奇怪,但也许原始文件包含一个隐藏的字符......
I had the same error today but I tried something and surprisingly it worked. In the site packages folder there will be a file named wx.pth. Open it using notepad and its contents would be like "wx-2.8-msw-unicode"
It is basically the name of the folder containing
wxpython
. Delete this using Ctrl + A and copy the name of the folder from the site packages and paste it here even if it is the same.Sounds weird but maybe the original file contained a hidden character...
对于需要 wx 模块的 PyMOL 插件,我遇到了同样的问题,尽管我通过从此处下载其软件包来安装 wxpython (Python 扩展包的非官方 Windows 二进制文件)并使用以下命令安装它:
出于某种原因,它给了我这个错误,为此我用以下命令卸载了它:
然后我下载了它从这里(wxPython 4.0.0a1)并重新安装:
此时的错误已不再呈现。
I had the same problem for a PyMOL plugin that required the wx module, though I installed wxpython by downloading its package from here (Unofficial Windows Binaries for Python Extension Packages) and installing it with the command:
For some reason it gave me that error, for which I uninstalled it with:
and then I downloaded it from here (wxPython 4.0.0a1) and reinstalled:
The error at this point has not been presented anymore.
在fedora中你可以使用以下命令来安装wx
In fedora you can use following command to install wx
我也面临同样的问题,我想分享我遇到的问题,这样对任何人都有帮助。就我而言,我已经安装了 python2. 7和python3,并在我使用的一些分析后测试了python3中的应用程序
查找 wx 的位置
所以我明白在我的例子中 wx 只能在 python2.7 环境中工作
I too face the same problem, I like to share which I was faced so it can be helpful for anyone. In my case I have installed both python2. 7 and python3, and tested the application in python3 after some analysis I used
to find the location of wx which was in
so i understood in my case wx will work only in python2.7 environment
我使用的是 64 位 Windows 7,访问:
https://wxpython.org/
然后下载了 exe对于我的系统,安装了它,它对我有用。
I'm on 64-bit Windows 7 and went to:
https://wxpython.org/
Then downloaded the exe for my system, installed it, and it worked for me.
从此链接下载 .whl 文件。
该文件的名称是:
wxPython-3.0.2.0-cp27-none-win32.whl
适用于 Windows 32 位和 python 2.7 以及wxPython-3.0.2.0-cp27-none-win_amd64.whl
适用于 Windows 64 位和 python 2.7。然后在命令提示符中:
pip install location-of-the-above-saved-file
Download the .whl file from this link.
The name of the file is:
wxPython‑3.0.2.0‑cp27‑none‑win32.whl
for Windows 32 bit and python 2.7 andwxPython‑3.0.2.0‑cp27‑none‑win_amd64.whl
for Windows 64 bit and python 2.7.Then in the command prompt:
pip install location-of-the-above-saved-file
只需打开终端并运行适用于 Windows 用户的命令
pip install -U wxPython
对于 Ubuntu 用户,你可以使用这个
Just open your terminal and run this command thats for windows users
pip install -U wxPython
for Ubuntu user you can use this
你可以检查Windows上的Path变量中是否有Python包所在的目录(在我的机器上,这个目录是C:\Python27\lib\site-packages)。如果Python的path环境变量没有这个目录,你将找不到这些包。
You may check if you have the directory where are the packages of Python (in my machine, this dir is C:\Python27\lib\site-packages) in the Path variable on Windows. If Python's path environment variable does not have this directory, you will not find the packages.
如果您没有在 Windows 上安装 wx,您可以使用:
If you do not have wx installed on windows you can use :
我重新启动 IDLE 并为我工作!
I restart the IDLE and works for me!