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

限于喜欢 提交于 2019-11-27 06:55:48

问题


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


回答1:


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.




回答2:


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




回答3:


In setup.py, options={"build_exe": {"packages": ["multiprocessing"]}} can also do the trick.




回答4:


In addition to

from multiprocessing import Queue

I rolled back to the older version of cx_freeze:

pip install cx-freeze==4.3.3

Besides, the "requests" library complained on absence of "urllib3" module. I upgraded this to requests==2.13.0 and all now works.

I'm using Python 3.4 on Win10. Hope this will help.



来源:https://stackoverflow.com/questions/40768570/importerror-no-module-named-queue-while-running-my-app-freezed-with-cx-freeze

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!