简体   繁体   中英

PyInstaller doesn't import Queue

I'm trying to compile some script with twisted and Queue.

pyinstaller sample.py --onefile
# -*- coding: utf-8 -*-#
from twisted import *
import queue as Queue
a = Queue.Queue()

Unfortunately, produced file fails with ImportError: No module named queue .

I don't think this is a PyInstaller or Twisted related issue at all. The Queue module is part of the standard library, and the issue is how you're naming it. In Python 2, it's Queue with a capital letter, but in Python 3, it's renamed queue to follow the more standard naming convention where modules have lowercase names.

Your script seems like it's a port of Python 2 code to Python 3 (thus the as Queue part of the import ), but you're running it with Python 2 still. That may fail in other more subtle ways than just the Queue import being wrong (eg its Unicode handling may be all wrong).

pip install twisted --upgrade

fixed everything.

update

also don't forget to use --hidden-import=queue in cmdline.

I get success by use this naming. I use Python 2.7

import Queue
queue = Queue.Queue()

and with pyinstaller pass this argument :

--hidden-import=Queue

and it works.

On windows using Python 2.7, pyinstaller up to 3.2 can be confused by the queue and Queue modules having similar names. https://github.com/pyinstaller/pyinstaller/issues/1935

This is fixed on the trunk of pyinstaller. I had to install pyinstaller from source to work around the bug.

git clone https://github.com/pyinstaller/pyinstaller
cd pyinstaller
python setup.py install

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM