ImportError:没有名为PySide的模块

时间:2015-01-06 12:35:16

标签: python pyside

我在我的Ubuntu 12.04中安装了PySide。当我尝试在python控制台中使用导入PySide时,我收到以下错误。

import PySide
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named PySide

我的Python路径是:

print sys.path ['', '/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PIL',
'/usr/lib/python2.7/dist-packages/gst-0.10',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.7',
'/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
'/usr/lib/python2.7/dist-packages/ubuntuone-client',
'/usr/lib/python2.7/dist-packages/ubuntuone-control-panel',
'/usr/lib/python2.7/dist-packages/ubuntuone-couch',
'/usr/lib/python2.7/dist-packages/ubuntuone-installer',
'/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol']

如何解决这个问题?

3 个答案:

答案 0 :(得分:2)

要使用python 3,只需按照此处的说明操作:

https://wiki.qt.io/PySide_Binaries_Linux

在ubuntu 12.04中意味着只需在控制台中键入一行:

sudo apt-get install python3-pyside

答案 1 :(得分:1)

PySide的最新版本和安装说明如下:

http://pyside.readthedocs.org/en/latest/building/linux.html

答案 2 :(得分:1)

现在,ModuleNotFoundError: No module named 'PySide'-可以使用python解决大于3.4x的pip install pyside2版本的问题,如下所示:

andylu@andylu-Lubuntu-PC:~$ pip install pyside2
Collecting pyside2
  Downloading PySide2-5.15.2-5.15.2-cp35.cp36.cp37.cp38.cp39-abi3-manylinux1_x86_64.whl (164.3 MB)
     |████████████████████████████████| 164.3 MB 2.4 kB/s 
Collecting shiboken2==5.15.2
  Downloading shiboken2-5.15.2-5.15.2-cp35.cp36.cp37.cp38.cp39-abi3-manylinux1_x86_64.whl (956 kB)
     |████████████████████████████████| 956 kB 2.7 MB/s 
Installing collected packages: shiboken2, pyside2
Successfully installed pyside2-5.15.2 shiboken2-5.15.2

对我来说,尝试从终端启动jupyter qtconsole时发生了错误:

andylu@andylu-Lubuntu-PC:~$ jupyter qtconsole
Traceback (most recent call last):
  File "/home/andylu/.pyenv/versions/3.9.0/lib/python3.9/site-packages/qtpy/__init__.py", line 204, in <module>
    from PySide import __version__ as PYSIDE_VERSION  # analysis:ignore
ModuleNotFoundError: No module named 'PySide'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/andylu/.pyenv/versions/3.9.0/bin/jupyter-qtconsole", line 5, in <module>
    from qtconsole.qtconsoleapp import main
  File "/home/andylu/.pyenv/versions/3.9.0/lib/python3.9/site-packages/qtconsole/qtconsoleapp.py", line 60, in <module>
    from qtpy import QtCore, QtGui, QtWidgets
  File "/home/andylu/.pyenv/versions/3.9.0/lib/python3.9/site-packages/qtpy/__init__.py", line 210, in <module>
    raise PythonQtError('No Qt bindings could be found')
qtpy.PythonQtError: No Qt bindings could be found

然后,我最初尝试在当前的pyside-环境中安装旧的Python 3.9.0,这导致了以下错误:

andylu@andylu-Lubuntu-PC:~$ pip install pyside
Collecting pyside
  Downloading PySide-1.2.4.tar.gz (9.3 MB)
     |████████████████████████████████| 9.3 MB 389 kB/s 
    ERROR: Command errored out with exit status 1:
     command: /home/andylu/.pyenv/versions/3.9.0/bin/python3.9 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-kbfhpmbj/pyside_d579850ca35442f99958b51deaf6e16b/setup.py'"'"'; __file__='"'"'/tmp/pip-install-kbfhpmbj/pyside_d579850ca35442f99958b51deaf6e16b/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-07ab3csm                      
         cwd: /tmp/pip-install-kbfhpmbj/pyside_d579850ca35442f99958b51deaf6e16b/        
    Complete output (1 lines):                                                          
    only these python versions are supported: [(2, 6), (2, 7), (3, 2), (3, 3), (3, 4)]  
    ----------------------------------------                                            
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.  

                                                           

解决方案如前所述,是安装pyside2而不是pyside

pip install pyside2