Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 938
user2678648 Avatar asked Nov 23 '16 15:11

user2678648


2 Answers

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.

like image 86
Harald Nordgren Avatar answered Sep 19 '22 02:09

Harald Nordgren


There are Several options based on project packages:

Method1:

Answer: I solve the problem my issue was I had file named queue.py in the same directory

Method2: Queue is in the multiprocessing module so:

from multiprocessing import Queue

Method3: Updating pip from 1.5.6 to 8.1.2

`sudo python -m pip install -U pip`

Reboot system (don't know if necessary, but only after reboot new version of pip was listed) Method4:

from six.moves.queue import Queue //I don't know how u import six package

like image 32
bob marti Avatar answered Sep 18 '22 02:09

bob marti