Python ImportError:没有名为 wx 的模块

发布于 2024-12-22 13:42:58 字数 341 浏览 5 评论 0 原文

很抱歉再次问这个问题。我在 stackoverflow 和一般谷歌搜索上搜索并发现了无数重复的内容。不幸的是,我无法对我的系统进行排序。

我有以下内容:

C:\Python27\Lib\site-packages\wx-2.8-msw-unicode

此文件夹包含 wx 文件夹以及 wx & wxPython 文件夹,每个文件夹包含 _init_.py 文件

当我导入 wx 时,收到错误消息 “没有名为 wx 的模块”

我需要做什么才能让 Python 找到相关文件让我成功“导入wx”

Im sorry to ask this question again. I have searched and found endles repeats of it both on stackoverflow and also on general google search. Unfortunatly I just cant get my system sorted.

I have the following:

C:\Python27\Lib\site-packages\wx-2.8-msw-unicode

this folder contains the wx folder and also wx & wxPython folders which each contain the
_init_.py files

When I import wx I get the error message "no module named wx"

What do I need to do in order to get Python to find the relevant files to allow me to "import wx" succesfully

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(16

草莓味的萝莉 2024-12-29 13:42:59

确保在编译器中选择正确的项目解释器。我使用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.

巾帼英雄 2024-12-29 13:42:59

通常,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 to site-packages\wx.

Or you could add C:\Python27\Lib\site-packages\wx-2.8-msw-unicode to your PYTHONPATH environment variable.

待天淡蓝洁白时 2024-12-29 13:42:58

乌班图:

sudo apt-get install python-wxtools

Ubuntu:

sudo apt-get install python-wxtools
何时共饮酒 2024-12-29 13:42:58

对于 Windows 和 MacOS,只需使用 pip 安装即可

pip install -U wxPython

参考:官方网站

For Windows and MacOS, Simply install it with pip

pip install -U wxPython

Reference: Official site

眼眸印温柔 2024-12-29 13:42:58

Windows:

  1. 转到 C:\Python27\Lib\site-packages\ 找到文件夹 wx--msw 或类似的

  2. 移动 wx来自将上述文件夹移动到 C:\Python27\Lib\site-packages\

Windows:

  1. Go to C:\Python27\Lib\site-packages\ find the folder wx-<version>-msw or similar

  2. Move the wx from the above folder to C:\Python27\Lib\site-packages\

蓝眼泪 2024-12-29 13:42:58

这对我有用

pip install --user -U wxPython

This worked for me

pip install --user -U wxPython
枫林﹌晚霞¤ 2024-12-29 13:42:58

我今天遇到了同样的错误,但我尝试了一些方法,令人惊讶的是它有效。在站点包文件夹中会有一个名为 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...

薄凉少年不暖心 2024-12-29 13:42:58

对于需要 wx 模块的 PyMOL 插件,我遇到了同样的问题,尽管我通过从此处下载其软件包来安装 wxpython (Python 扩展包的非官方 Windows 二进制文件)并使用以下命令安装它:

pip install .\wxPython-3.0.2.0-cp27-none-win_amd64.whl

出于某种原因,它给了我这个错误,为此我用以下命令卸载了它:

pip uninstall wxPython

然后我下载了它从这里(wxPython 4.0.0a1)并重新安装:

pip install .\wxPython-4.0.0a1-cp27-cp27m-win_amd64.whl

此时的错误已不再呈现。

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:

pip install .\wxPython-3.0.2.0-cp27-none-win_amd64.whl

For some reason it gave me that error, for which I uninstalled it with:

pip uninstall wxPython

and then I downloaded it from here (wxPython 4.0.0a1) and reinstalled:

pip install .\wxPython-4.0.0a1-cp27-cp27m-win_amd64.whl

The error at this point has not been presented anymore.

深居我梦 2024-12-29 13:42:58

在fedora中你可以使用以下命令来安装wx

pip install -U \
  -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-16.04 \
  wxPython

In fedora you can use following command to install wx

pip install -U \
  -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-16.04 \
  wxPython
七禾 2024-12-29 13:42:58

我也面临同样的问题,我想分享我遇到的问题,这样对任何人都有帮助。就我而言,我已经安装了 python2. 7和python3,并在我使用的一些分析后测试了python3中的应用程序

pip 显示 wxpython-common

查找 wx 的位置

/usr/lib/python2.7/dist-packages

所以我明白在我的例子中 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

pip show wxpython-common

to find the location of wx which was in

/usr/lib/python2.7/dist-packages

so i understood in my case wx will work only in python2.7 environment

难理解 2024-12-29 13:42:58

我使用的是 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.

眼眸里的那抹悲凉 2024-12-29 13:42:58

从此链接下载 .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 and
wxPython‑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

半﹌身腐败 2024-12-29 13:42:58

只需打开终端并运行适用于 Windows 用户的命令
pip install -U wxPython

对于 Ubuntu 用户,你可以使用这个

pip install -U \
-f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-16.04 \
wxPython

Just open your terminal and run this command thats for windows users
pip install -U wxPython

for Ubuntu user you can use this

pip install -U \
-f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-16.04 \
wxPython
一抹淡然 2024-12-29 13:42:58

你可以检查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.

成熟的代价 2024-12-29 13:42:58

如果您没有在 Windows 上安装 wx,您可以使用:

 pip install wx

If you do not have wx installed on windows you can use :

 pip install wx
北陌 2024-12-29 13:42:58

我重新启动 IDLE 并为我工作!

I restart the IDLE and works for me!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文