Python: from import error

I am running Python 2.6.6 on Ubuntu 10.10.

I understand that we can import a module and associate this module with a different name, for example.

import spam as eggs

and

from eggs import spam as foo

My problem is that when running PySide examples, the following import code does not start:

import PySide as PyQt4
from PyQt4 import QtCore, QtGui

It generates an import error:

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

Clearly, according to the Python interpreter, the above code is incorrect, my question is why is it incorrect or, rather, why does this not work?

+3
source share
2 answers

importand from- special syntax.

They look for the name of the module, which means the file in sys.path, which begins with the name of the module.

And it looks like you don't have PyQt4, so it will fail.

, PyQt4 import PySide as PyQt4 , Python - PyQt4, from PyQt4 import QtCore, QtGui.

import PySide as PyQt4
QtCore = PyQt4.QtCore
QtGui = PyQt4.QtGui

import PySide as PyQt4
from PySide import QtCore, QtGui

.

+4

PySide , PyQt4. PyQt4 PySide, -, :

1) , , , python, python, :

>>> import sys

>>> print sys.path

2) PySide cd'd (nb It /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages macports PySide python 2.7 Mac OSX Leopard 10.5.8).

3) ln, sudo:

sudo ln -s PySide PyQt4

, :

from PyQt4 import QtGui

- !

, - PyQt4, PyQt4. : , , / - Python, . YMMV . , - : ", !" ", , .."

+2
source

Source: https://habr.com/ru/post/1794304/


All Articles