【问题标题】:Python: installation of wx fails on MacPython:在 Mac 上安装 wx 失败
【发布时间】:2020-07-11 07:39:15
【问题描述】:

我正在 MacBook 上运行一个使用 wx 的 python2 包。我正在运行 python 2.7.10。当我运行包时:

con@company_computer:~/dir/pasta$ python run_pasta_gui.py 
Traceback (most recent call last):
  File "run_pasta_gui.py", line 27, in <module>
    import wx
ImportError: No module named wx

所以我尝试按照Python ImportError: No module named wx 的建议安装 wx

我尝试按照https://wxpython.org/pages/downloads/index.html 上的建议通过 pip 安装:

pip install -U wxPython

&

sudo pip install wxPython

&

sudo -H pip install wxPython

但所有这些都说它已经安装了:

Requirement already satisfied: wxPython in /usr/local/lib/python2.7/site-packages (4.0.7.post2)
Requirement already satisfied: pillow in /usr/local/lib/python2.7/site-packages (from wxPython) (6.2.2)
Requirement already satisfied: six in /usr/local/lib/python2.7/site-packages (from wxPython) (1.11.0)
Requirement already satisfied: numpy<1.17; python_version <= "2.7" in /usr/local/lib/python2.7/site-packages (from wxPython) (1.14.2)

但当我尝试运行 run_pasta_gui.py 时,我得到了原来的错误

我可以通过 sudo apt-get install python-wxtools 在我的 Ubuntu 虚拟机上完成这项工作,但这显然不适用于 Mac。

Unable to import a module that is definitely installed 之后,我已经尝试过sudo chmod -R ugo+rX /usr/local/lib/python2.7/site-packages/,但我仍然无法访问wx 包。

如何让wx 为我的python2 安装工作?

【问题讨论】:

  • 您确定您正在使用正确的 Python 安装运行脚本吗?你能明确指定安装吗?您没有使用虚拟环境吗?
  • @AMC python is 2.7.10 如何判断 pip 直接使用该版本?本地不应该有任何其他 python 版本。我没有使用虚拟环境
  • 本地不应该有任何其他 python 版本。 那么这不是问题。很奇怪。

标签: python macos pip wxpython python-2.x


【解决方案1】:

我在 venv 中运行了安装,我能够导入并列出模块

(venv) air:~ yo$ pip install wxPython Collecting wxPython Downloading https://files.pythonhosted.org/packages/17/b0/3a39e3fbea922e2f1bf2a48d5ed14d7eb1173ec8dbd3a1187f105ae06355/wxPython-4.0.7.post2-cp27-cp27m-macosx_10_9_x86_64.whl (16.9MB) |████████████████████████████████| 16.9MB 3.4MB/s Collecting pillow Downloading https://files.pythonhosted.org/packages/d1/6a/41719faa7421602a85941867059f53787ac40c85c8fe9e6bb48809e3246e/Pillow-6.2.2-cp27-cp27m-macosx_10_6_intel.whl (3.9MB) |████████████████████████████████| 3.9MB 2.7MB/s Collecting numpy<1.17; python_version <= "2.7" Downloading https://files.pythonhosted.org/packages/09/96/84cf406fe7d589f3dba9fc0f737e65985a3526c6d8c783f02d4b5a10825d/numpy-1.16.6-cp27-cp27m-macosx_10_9_x86_64.whl (13.9MB) |████████████████████████████████| 13.9MB 301kB/s Requirement already satisfied: six in ./work/virtualenvs/venv/lib/python2.7/site-packages (from wxPython) (1.13.0) Installing collected packages: pillow, numpy, wxPython Successfully installed numpy-1.16.6 pillow-6.2.2 wxPython-4.0.7.post2

Python 2.7.16 (default, Feb 29 2020, 01:55:37) [GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc- on darwin Type "help", "copyright", "credits" or "license" for more information. import wx print(dir()) ['__builtins__', '__doc__', '__name__', '__package__', 'wx']

【讨论】:

猜你喜欢
  • 2019-05-07
  • 2010-09-23
  • 2020-09-16
  • 2014-09-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-06
相关资源
最近更新 更多