ImportError: No module named PySide

问题描述 投票:0回答:3

我已经在我的 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']

如何解决这个问题?

python pyside
3个回答
4
投票

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

https://wiki.qt.io/PySide_Binaries_Linux

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

sudo apt-get install python3-pyside

1
投票

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

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


1
投票

现在,

ModuleNotFoundError: No module named 'PySide'
- 问题可以解决
python
版本> 3.4x与
pip install [pyside<most-recent-version>][1]
(当前版本6)像这样:

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

编辑: 请注意,pyside 的最新版本可能有所不同,目前是 version 6.

© www.soinside.com 2019 - 2024. All rights reserved.