Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

binding_helper fails when "future" package is installed #24

Closed
John-Nagle opened this issue Jun 8, 2015 · 7 comments
Closed

binding_helper fails when "future" package is installed #24

John-Nagle opened this issue Jun 8, 2015 · 7 comments

Comments

@John-Nagle
Copy link

Ubuntu 14.04 LTS / 64 bit. ROS/Gazebo Jade installed per instructions at "http://wiki.ros.org/jade/Installation/Ubuntu"

I'm working through the tutorials, in order. Everything went well until the first use of "rqt_graph" in the turtle tutorial. This produced the error:

rosrun rqt_graph rqt_graph
Traceback (most recent call last):
  File "/opt/ros/jade/lib/rqt_graph/rqt_graph", line 8, in <module>
    sys.exit(main.main(sys.argv, standalone='rqt_graph.ros_graph.RosGraph'))
  File "/opt/ros/jade/lib/python2.7/dist-packages/rqt_gui/main.py", line 59, in main
    return super(Main, self).main(argv, standalone=standalone, plugin_argument_provider=plugin_argument_provider, plugin_manager_settings_prefix=str(hash(os.environ['ROS_PACKAGE_PATH'])))
  File "/opt/ros/jade/lib/python2.7/dist-packages/qt_gui/main.py", line 336, in main
    from python_qt_binding import QT_BINDING
  File "/opt/ros/jade/lib/python2.7/dist-packages/python_qt_binding/__init__.py", line 55, in <module>
    from .binding_helper import loadUi, QT_BINDING, QT_BINDING_MODULES, QT_BINDING_VERSION  # @UnusedImport
  File "/opt/ros/jade/lib/python2.7/dist-packages/python_qt_binding/binding_helper.py", line 265, in <module>
    getattr(sys, 'SELECT_QT_BINDING_ORDER', None),
  File "/opt/ros/jade/lib/python2.7/dist-packages/python_qt_binding/binding_helper.py", line 84, in _select_qt_binding
    QT_BINDING_VERSION = binding_loader(required_modules, optional_modules)
  File "/opt/ros/jade/lib/python2.7/dist-packages/python_qt_binding/binding_helper.py", line 139, in _load_pyqt
    _named_import('PyQt4.%s' % module_name)
  File "/opt/ros/jade/lib/python2.7/dist-packages/python_qt_binding/binding_helper.py", line 106, in _named_import
    module = builtins.__import__(name)
AttributeError: 'module' object has no attribute '__import__'

For Python 2.7.6, that's a standard error. There is no

builtins.__import__

in Python 2.7.6. It's there in 2.7.9, and 3.x, but not 2.7.6. So, with the stock Python of Ubuntu 14.04 LTS, ROS won't work.

From the Python documentation:

"__import__ is an advanced function that is not needed in everyday Python programming, unlike importlib.import_module()." 

It's an internal function which changes between Python releases. Using it in binding_helper created a bug. Importlib should be used instead.

See also "http://answers.ros.org/question/210762/rqt_graph-not-finding-qt4/"

@dirk-thomas
Copy link
Contributor

The current code base uses a conditional import to address the different location of this function in different Python versions:

try:
import builtins
except ImportError:
import __builtin__ as builtins

Can you please post the version number of the python_qt_binding package you are using? If you are not using 0.2.15 or newer please update the package.

Or may be you have a custom builtins module on your PYTHONPATH?

@John-Nagle
Copy link
Author

Yes, I saw that. That conditional import approach doesn't work with Python 2.7.6. "import builtins" succeeds. But "builtins" in Python 2.7.6 doesn't have

builtins.__import__

So

module =  builtins.__import__(name)

at line 106 fails.

As ROS sets it up,

PYTHONPATH="/opt/ros/jade/lib/python2.7/dist-packages"

That internal symbol isn't in Python 2.7.6.
See below.

Try using the supported approach, "importlib". Thanks.

Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import builtins
>>> dir(builtins)
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BufferError', 'BytesWarning', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'None', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'ReferenceError', 'RuntimeError', 'RuntimeWarning', 'StandardError', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'ZeroDivisionError', '__builtins__', '__doc__', '__file__', '__future_module__', '__name__', '__package__', '__path__', 'abs', 'absolute_import', 'all', 'any', 'apply', 'ascii', 'basestring', 'bin', 'bool', 'buffer', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'cmp', 'coerce', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'execfile', 'exit', 'file', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'intern', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'long', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'raw_input', 'reduce', 'reload', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'sys', 'tuple', 'type', 'unichr', 'unicode', 'vars', 'xrange', 'zip']

@dirk-thomas
Copy link
Contributor

I am using Python 2.7.6 on Trusty and for me the following line raises an ImportError:

python -c "import builtins"

What path does the following command output for you:

python -c "import builtins; print builtins.__file__"

@John-Nagle
Copy link
Author

>python -c "import builtins; print builtins.__file__"
/usr/local/lib/python2.7/dist-packages/builtins/__init__.pyc

Here's the __init__.py being used:

from __future__ import absolute_import
import sys
__future_module__ = True

if sys.version_info[0] < 3:
    from __builtin__ import *
    # Overwrite any old definitions with the equivalent future.builtins ones:
    from future.builtins import *
else:
    raise ImportError('This package should not be accessible on Python 3. '
                      'Either you are trying to run from the python-future src folder '
                      'or your installation of python-future is corrupted.')`

pip shows "future (0.14.3)" as installed.

@dirk-thomas dirk-thomas changed the title binding_helper fails on Python 2.7.6 binding_helper fails when future package is installed Jun 9, 2015
@dirk-thomas dirk-thomas changed the title binding_helper fails when future package is installed binding_helper fails when "future" package is installed Jun 9, 2015
dirk-thomas added a commit that referenced this issue Jun 9, 2015
@dirk-thomas
Copy link
Contributor

Thanks for looking into your configuration. That clarifies why it didn't fail on my machine.

I have created PR #25 to swap the import order for now. That worked for me - with and without the future package installed. Can you please try the proposed patch and confirm that it works for you too?

I might update the code to use importlib in another iteration. Thanks for the suggestion.

@John-Nagle
Copy link
Author

rqt_graph_fixed

That works. Replaced the version of binding_helper.py with the one from PR #25, and rqt_graph displays properly. See attached screenshot of it working. Thanks.

I'd suggest using importlib in future. "import" is deprecated. Using importlib, you don't have to keep up with internal changes in Python.

@dirk-thomas
Copy link
Contributor

Thanks for confirming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants