我是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中运行时:
>>> 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']
当我在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']
答案 0 :(得分:3)
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。
前进的道路取决于您是否要使用系统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-packages
。
自制Python:您需要将/usr/local/bin
添加到PATH
,可能在~/.bashrc
。
答案 1 :(得分:1)
对于windows用户情况几乎相同,当您安装了多个python解释器并且您在一个安装中安装了PySide2并尝试使用其他安装运行您的代码时会遇到这种错误安装。 为您的项目创建一个虚拟环境并在该虚拟环境中安装所有模块。它会避免这个问题。 希望它有效:)