已安装 PySide 但无法导入:“没有名为 PySide 的模块"; [英] Installed PySide but can't import it: "no module named PySide"

查看:419
本文介绍了已安装 PySide 但无法导入:“没有名为 PySide 的模块";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Python 新手.我同时安装了 Python 2.7 和 Python 3.我刚刚尝试通过 Homebrew 安装 PySide 并收到此消息:

<块引用>

PySide 包成功安装在/usr/local/lib/python2.7/site-packages/PySide...

Python 版本和新安装的 PySide 都存储在/usr/local/Cellar/.

这个问题是,当我使用 Python 2.7 或 Python 3 并尝试导入 PySide 或运行包含 PySide 的测试程序时,我收到消息:没有名为 PySide 的模块".

这是在 OS X 10.9.3 上

任何帮助将不胜感激,我已经进行了广泛的搜索,并尝试以相同的结果重新安装几次.

完整的sys.path输出:

当我在 Python 3 中运行时:

<预><代码>>>>打印(系统路径)['', '/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/lib/python34.zip', '/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/lib/python3.4', '/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin', '/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload', '/usr/local/lib/python3.4/site-包']

当我在 Python 2 中运行时:

<预><代码>>>>打印 sys.path['', '/Library/Python/2.7/site-packages/distribute-0.6.49-py2.7.egg', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', '/Library/Python/2.7/site-packages', '/Library/Python/2.7/site-packages/setuptools-0.6c11-py2.7.鸡蛋信息']

解决方案

PySide 已安装到 /usr/local/lib/python2.7/site-packages,但 Python 不在那里;它在 /Library/Python/2.7/site-packages 中查找.另外,which python 给出了 /usr/bin/python 而不是 /usr/local/bin/python,所以你正在使用系统蟒蛇.

前进的道路取决于您是要使用系统 Python 还是 Homebrew Python:

  • 系统 Python: 您需要将 /usr/local/lib/python2.7/site-packages 添加到您的 sys.path(可能在 /Library/Python/2.7/site.py 中)或将 PySide 移动到 /Library/Python/2.7/site-包.

  • Homebrew Python:您需要将 /usr/local/bin 添加到您的 PATH,可能在 >~/.bashrc.

I'm new to Python. I have both Python 2.7 and Python 3 installed. I just tried installing PySide via Homebrew and got this message:

PySide package successfully installed in /usr/local/lib/python2.7/site-packages/PySide...

Both versions of Python and the newly installed PySide are all stored in /usr/local/Cellar/.

This issue is that when I'm in either Python 2.7 or Python 3 and try to import PySide or run a test program that includes PySide, I get the message: "no module named PySide".

This is on OS X 10.9.3

Any help would be greatly appreciated, I've searched far and wide and tried reinstalling a few times with the same results.

The full sys.path output:

When I run while in Python 3:

>>> print(sys.path)
['', '/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/lib/python34.zip', '/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/lib/python3.4', '/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin', '/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload', '/usr/local/lib/python3.4/site-packages']

When I run while in Python 2:

>>> print sys.path
['', '/Library/Python/2.7/site-packages/distribute-0.6.49-py2.7.egg', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', '/Library/Python/2.7/site-packages', '/Library/Python/2.7/site-packages/setuptools-0.6c11-py2.7.egg-info']

解决方案

PySide was installed to /usr/local/lib/python2.7/site-packages, but Python isn’t looking there; it’s looking in /Library/Python/2.7/site-packages. Additionally, which python gave /usr/bin/python rather than /usr/local/bin/python, so you’re using the system Python.

The path forward depends on whether you want to use the system Python or Homebrew Python:

  • System Python: You’ll need to either add /usr/local/lib/python2.7/site-packages to your sys.path (possibly in /Library/Python/2.7/site.py) or move PySide to /Library/Python/2.7/site-packages.

  • Homebrew Python: You’ll need to add /usr/local/bin to your PATH, probably in ~/.bashrc.

这篇关于已安装 PySide 但无法导入:“没有名为 PySide 的模块";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆