【问题标题】:ImportError: No module named PySideImportError:没有名为 PySide 的模块
【发布时间】:2020-12-10 22:43:52
【问题描述】:

我已经在我的 Ubuntu 12.04 中安装了 PySide。当我尝试在 python 控制台中使用 import 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']

如何解决这个问题?

【问题讨论】:

  • 你是如何安装 Pyside 你是如何尝试解决你自己的问题的?
  • 我按照此处指定的步骤进行操作 [qt-project.org/wiki/PySide_Binaries_Linux]
  • 我想我找到了问题,我安装了 python3-pyside 但我使用的是 python2.7。删除 python3-pyside 后,我安装了 python-pyside,它工作正常。

标签: python pyside


【解决方案1】:

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

https://wiki.qt.io/PySide_Binaries_Linux

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

sudo apt-get install python3-pyside

【讨论】:

    【解决方案2】:

    PySide 的最新构建和安装说明在这里:

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

    【讨论】:

    • 但它们仅指 python 2.7,而(至少在理论上)PySide 应该适用于 Python 3.2
    • 说明适用于所有 python 版本(从 2.7 到 3.4)只需将 2.7 替换为 3.2 或您正在使用的任何 python 版本。
    【解决方案3】:

    现在,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
    

    然后,我最初尝试在我现在的Python 3.9.0 - 环境中安装古老的pyside,导致出现以下错误:

    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
    

    【讨论】:

      猜你喜欢
      • 2013-03-11
      • 2012-12-07
      • 2012-05-23
      • 2019-07-29
      • 2015-07-04
      • 2014-03-15
      • 2017-12-29
      • 2014-09-12
      • 2017-05-09
      相关资源
      最近更新 更多