ImportError: No module named 'Queue'

后端 未结 7 1690
再見小時候
再見小時候 2020-12-02 16:35

I am trying to import requests module, but I got this error my python version is 3.4 running on ubuntu 14.04

>>> import requests
Traceb         


        
相关标签:
7条回答
  • 2020-12-02 16:52

    I run into the same problem and learn that queue module defines classes and exceptions, that defines the public methods (Queue Objects).

    Ex.

    workQueue = queue.Queue(10)
    
    0 讨论(0)
  • 2020-12-02 16:57

    You need install Queuelib either via the Python Package Index (PyPI) or from source.

    To install using pip:-

    $ pip install queuelib
    

    To install using easy_install:-

    $ easy_install queuelib
    

    If you have downloaded a source tarball you can install it by running the following (as root):-

    python setup.py install
    
    0 讨论(0)
  • 2020-12-02 17:00

    import queue is lowercase q in Python 3.

    Change Q to q and it will be fine.

    (See code in https://stackoverflow.com/a/29688081/632951 for smart switching.)

    0 讨论(0)
  • 2020-12-02 17:10

    It's because of the Python version. In Python 3 it's import Queue as queue; on the contrary in Python 2.x it's import queue. If you want it for both environments you may use something below as mentioned here

    try:
       import queue
    except ImportError:
       import Queue as queue
    
    0 讨论(0)
  • 2020-12-02 17:10

    In my case it should be:

    from multiprocessing import JoinableQueue

    Since in python2, Queue has methods like .task_done(), but in python3 multiprocessing.Queue doesn't have this method, and multiprocessing.JoinableQueue does.

    0 讨论(0)
  • 2020-12-02 17:17

    Queue is in the multiprocessing module so:

    from multiprocessing import Queue
    
    0 讨论(0)
提交回复
热议问题