ImportError: No module named queue

ThomasCle picture ThomasCle · Aug 7, 2014 · Viewed 14.6k times · Source

I am trying to make my Python script run on my Synology. The application uses Oracle's MySQL framework Connector/Python which I have installed by running the python setup.py install on the Platform independent version of Connector/Python.

I have installed the Connector/Python on my Windows PC via the .msi installer. This runs perfectly fine. But every time I try to run it on my Synology I get this error:

File "MyApplication.py", line 3, in <module>
    from DatabaseConnection import DatabaseConnection
  File "/volume1/public/Python/MyApplication/DatabaseConnection.py", line 3, in <module>
    import mysql.connector
  File "/usr/local/lib/python2.7/site-packages/mysql/connector/__init__.py", line 42, in <module>
    from mysql.connector.pooling import (
  File "/usr/local/lib/python2.7/site-packages/mysql/connector/pooling.py", line 29, in <module>
    import queue
ImportError: No module named queue

I see two problems in this:

  • I need some kind of queue library. Where can I get that? My Windows PC just had it.
  • As far as I have googled me through, the queue library is supposed to be named Queue and not queue for Python 2.7. But the Platform Independent version of Connector/Python does not state which version it is supposed to run on.

Just to clarify, I do not have any version of the queue library (i.e. Queue.py or queue.py).

How to I solve this?

Answer

Burhan Khalid picture Burhan Khalid · Aug 7, 2014

The application you have downloaded is designed for Python 3, and you have Python 2 installed.

The platform independent zip archive has both Python 2 and Python 3 versions of the connector, and there is this check in metasetupinfo.py:

if sys.version_info >= (3, 1):
    sys.path = ['python3/'] + sys.path
    package_dir = { '': 'python3' }
elif sys.version_info >= (2, 6) and sys.version_info < (3, 0):
    sys.path = ['python2/'] + sys.path
    package_dir = { '': 'python2' }
else:
    raise RuntimeError(
        "Python v%d.%d is not supported" % sys.version_info[0:2])

For some reason this check on your platform defaulted to Python 3, and thus the incorrect version of the library was installed.

There are some unique features of the Oracle MySQL connector (for example, it provides an optimized driver for django), but if you don't need these features - installing mysql-python (the MySQLdb driver) will work perfectly well.