本文介绍了Ubuntu - 找不到适用于 python2 的 PySide 模块,但适用于 python3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我让 PyQt4 在 Ubuntu 12.04 上使用 python2 运行良好.然后我安装了 python-PySide.但是安装测试会给我一个找不到模块的错误.然后我安装了 python3-PySide,它工作正常.所以显然与我的环境路径有关,但我不确定我需要做什么.我猜 PySide 会自动检查 python3 是否存在,如果存在,那么无论如何它都会使用它.由于 Qt4.8 兼容性问题,我需要 PySide 来使用 python2.7.有什么建议吗?

关于我的系统的一些信息:

哪个蟒蛇

/usr/bin/local/python

哪个python3

/usr/bin/python3

关于安装测试的更多细节.
安装后,我调出python控制台,尝试导入PySide,如下:

蟒蛇

导入 PySide

导入错误:没有模块名称 PySide

但它适用于python3:

python3

导入 PySide

PySide.版本

'1.1.2'

解决方案

您有两个独立的 Python 2.7 安装,一个在/usr 中,一个在/usr/local 中.(这是在您还安装的 Python 3.x 之上.)

这势必会引起混乱,尤其是对于新手而言.并且它引起了它必然会引起的那种迷惑.

您已将 PySide 安装到/usr 安装中,因此它最终位于/usr/lib/python2.7/dist-packages 中.如果您运行/usr/bin/python,那个 import PySide 可能会正常工作.(如果没有,请参见下文.)

但是在您的 PATH 中,默认的 pythonpython2.7 是/usr/local 安装,因此 which python 说/usr/local/bin/python,所以根本看不到PySide.因此,您还需要为 other Python 安装它.

除非您知道出于某种原因需要在/usr/local 中安装第二个 Python 2.7,否则最简单的方法就是废弃它.不要卸载它并重新安装它;只需卸载它.您已经在/usr 中安装了一个 Python 2.7,您不需要其中的两个.

如果你真的需要让 PySide 与第二个 2.7 一起工作......

尽管被反复询问,您仍然没有解释您是如何安装 PySide 的,因此我无法确切地告诉您如何做到这一点.但一般来说,关键是确保对所有必须运行的 Python 程序(python 本身、python-config、pip、easy_install 等)使用显式路径.例如,如果您头脑中的文档或博客或声音告诉您在某个步骤运行 easy_install,请改为运行/usr/local/bin/easy_install.如果没有这样的程序,那么你需要安装它.您已经拥有/usr/bin/easy_install 的事实并没有帮助——事实上,它很痛苦.

如果您可以摆脱第二个 Python,但这还不能修复 PySide,请卸载、重建并重新安装 PySide.或者,甚至更简单…… PySide 已经为所有具有 Ubuntu 软件包的主要 Python 版本预先制作了可运行的二进制 Ubuntu 软件包.就这样安装.

I had PyQt4 running fine with python2 on Ubuntu 12.04. I then installed python-PySide. But the installation test would give me a module not found error. Then I installed python3-PySide and it works fine. So obviously something to do with my environment paths, but I'm not sure what I need to do. I'm guessing PySide is automatically checking if python3 exists and if it does then it'll use it regardless. I need PySide to work with python2.7 because of Qt4.8 compatibility issues. Any suggestions?

some info about my system:

which python

which python3

EDIT:

More details about installation test.
After installation, I bring up the python console and try import PySide, as follows:

python

ImportError: No module name PySide

But it works fine for python3:

python3

'1.1.2'

解决方案

You have two independent Python 2.7 installations, one in /usr and one in /usr/local. (And that's on top of the Python 3.x installation you also have.)

This is bound to cause confusion, especially for novices. And it has caused exactly the kind of consuion it was bound to cause.

You've installed PySide into the /usr installation, so it ended up in /usr/lib/python2.7/dist-packages. If you run /usr/bin/python, that import PySide will probably work fine. (If not, see below.)

But the default thing called python and python2.7 on your PATH is the /usr/local installation, hence which python says /usr/local/bin/python, so it can't see PySide at all. So you need to get it installed for the other Python as well.


Unless you know that you need a second Python 2.7 in /usr/local for some reason, the simplest thing to do would be to scrap it. Don't uninstall it and reinstall it; just uninstall it. You've already got a Python 2.7 in /usr, and you don't need two of them.


If you really need to get PySide working with the second 2.7…

Since you still haven't explained how you've been installing PySide despite being asked repeatedly, I can't tell you exactly how to do that. But generally, the key is to make sure to use explicit paths for all Python programs (python itself, python-config, pip, easy_install, etc.) that you have to run. For example, if the docs or blog or voices in your head tell you to run easy_install at some step, run /usr/local/bin/easy_install instead. If there is no such program, then you need to install that. The fact that you already have /usr/bin/easy_install doesn't help—in fact, it hurts.


If you can get rid of the second Python, but that doesn't fix PySide yet, uninstall, rebuild, and reinstall PySide. Or, even simpler… PySide has pre-made, working binary Ubuntu packages for all of the major Python versions that have Ubuntu packages. Just install it that way.

这篇关于Ubuntu - 找不到适用于 python2 的 PySide 模块,但适用于 python3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 21:37