ImportError: No module named 'queue' while running my app freezed with cx_freeze

user2678648 picture user2678648 · Nov 23, 2016 · Viewed 11.2k times · Source

I am using python 3.4. I am able to run my python script without any problem. But While running my freezed python script , following error have appeared. I am able to freeze my script successfully too with cx_freeze.

C:\Program Files (x86)\utils>utils.exe
Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\requests\packages\__init__.py", line 27, i
n <module>
    from . import urllib3
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\__init__.py", line 8, in <module>
    from .connectionpool import (
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 28, in <module>
    from .packages.six.moves.queue import LifoQueue, Empty, Full
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\packages\six.py", line 203, in load_module
    mod = mod._resolve()
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\packages\six.py", line 115, in _resolve
    return _import_module(self.mod)
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\packages\six.py", line 82, in _import_module
    __import__(name)
ImportError: No module named 'queue'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 12, in <module>
    __import__(name + "__init__")
  File "C:\Python34\lib\site-packages\cx_Freeze\initscripts\Console.py", line 21, in <module>
    scriptModule = __import__(moduleName)
  File "utils.py", line 3, in <module>
  File "C:\Python34\lib\site-packages\requests\__init__.py", line 63, in <module>
    from . import utils
  File "C:\Python34\lib\site-packages\requests\utils.py", line 24, in <module>
    from ._internal_utils import to_native_string
  File "C:\Python34\lib\site-packages\requests\_internal_utils.py", line 11, in <module>
    from .compat import is_py2, builtin_str
  File "C:\Python34\lib\site-packages\requests\compat.py", line 11, in <module>
    from .packages import chardet
  File "C:\Python34\lib\site-packages\requests\packages\__init__.py", line 29, in <module>
    import urllib3
  File "C:\Python34\lib\site-packages\urllib3\__init__.py", line 8, in <module>
    from .connectionpool import (
  File "C:\Python34\lib\site-packages\urllib3\connectionpool.py", line 28, in <module>
    from .packages.six.moves.queue import LifoQueue, Empty, Full
  File "C:\Python34\lib\site-packages\urllib3\packages\six.py", line 203, in load_module
    mod = mod._resolve()
  File "C:\Python34\lib\site-packages\urllib3\packages\six.py", line 115, in _resolve
    return _import_module(self.mod)
  File "C:\Python34\lib\site-packages\urllib3\packages\six.py", line 82, in _import_module
    __import__(name)
ImportError: No module named 'queue'

Even tried installing package 'six' with no help. My setup.py is from cx_Freeze import setup, Executable import requests.certs

setup(
name = "utils" ,
version = "0.1" ,
description = " utils for accounts" ,
executables = [Executable("utils.py")],
options = {"build_exe": {"packages": ["urllib", "requests"],"include_files":[(requests.certs.where(),'cacert.pem')]}},

)

script imports following module

import requests
import urllib.request
import uuid
import json
import http.client
from xml.dom import minidom

Any help will be highly appreciated. please see me as novice in python

Answer

Harald Nordgren picture Harald Nordgren · Jan 20, 2017

I had the same issues running on Ubuntu with Python 3.5. It seems that cx_freeze has problems with libraries that import other files or something like that.

Importing Queue together with requests worked for me, so:

import requests
from multiprocessing import Queue

And I don't think specifying urllib in "packages": ["urllib", "requests"] is necessary.