ZeroVM import error: No module named thread - python

When working on a small ZeroVM application that will run on ZeroCloud (that is, the ZeroVM integration with Swift), and trying to import the multiprocessing module, I get an error:
Traceback (most recent call last):
File "test.py", line 1, in <module>
import multiprocessing
File "/lib/python2.7/multiprocessing/__init__.py", line 65, in <module>
from multiprocessing.util import SUBDEBUG, SUBWARNING
File "/lib/python2.7/multiprocessing/util.py", line 38, in <module>
import threading # we want threading to install it's
File "/lib/python2.7/threading.py", line 6, in <module>
import thread
ImportError: No module named thread
Why is that?

There is currently no support for threading or multiprocessing in ZeroVM. The Python status document lists both modules as unsupported.
The ZeroVM platform is a single process, single threaded environment. However, there is a pthreads port available. Instead of normal premeptive multithreading, this port uses cooperative multitasking instead. It might be possible to use this to enable some form of threading in the ZeroVM Python port.

Related

What is a correct way to import "RPi.GPIO as GPIO" for use in a python thread?

I have a python program to which I am adding GPIO pin control functionality. It is a multi-threaded system that runs fine until I try to do an "import RPi.GPIO as GPIO". Then I get the error below:
Traceback (most recent call last):
File "/usr/local/System/main.py", line 20, in <module>
from LightUpAlarm import AlarmCli
File "/usr/local/System/LightUpAlarm/AlarmCli.py", line 26, in <module>
from AlarmManager import AlarmManager
ImportError: No module named AlarmManager
The module "AlarmManager" was available until I tried to import "RPi.GPIO". I would appreciate any help understanding what I am doing wrong. Thanks in advance.
Pastebin link to full python file generating error. AlarmThread.py

ImportError: No module named 'Queue' [duplicate]

This question already has answers here:
Importing installed package from script with the same name raises "AttributeError: module has no attribute" or an ImportError or NameError
(2 answers)
Closed last month.
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
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 10, in <module>
from queue import LifoQueue, Empty, Full
ImportError: cannot import name 'LifoQueue'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.4/dist-packages/requests/__init__.py", line 58, in <module>
from . import utils
File "/usr/local/lib/python3.4/dist-packages/requests/utils.py", line 26, in <module>
from .compat import parse_http_list as _parse_list_header
File "/usr/local/lib/python3.4/dist-packages/requests/compat.py", line 7, in <module>
from .packages import chardet
File "/usr/local/lib/python3.4/dist-packages/requests/packages/__init__.py", line 3, in <module>
from . import urllib3
File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/__init__.py", line 10, in <module>
from .connectionpool import (
File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 12, in <module>
from Queue import LifoQueue, Empty, Full
ImportError: No module named 'Queue'
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.)
Queue is in the multiprocessing module so:
from multiprocessing import Queue
I solve the problem my issue was I had file named queue.py in the same directory
It's because of the Python version. In Python 2.x it's import Queue as queue; on the contrary in Python 3 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
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.
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)
I just copy the file name Queue.py in the */lib/python2.7/ to queue.py and that solved my problem.

Creating a multiprocessing queue throws an error

I wrote a very simple program to try to demonstrate multiprocessing queues. However, it throws an error when the queue is created.
import multiprocessing as mp
q = mp.Queue() #error right here
q.put(1)
print(q.get())
I get this message.
Traceback (most recent call last):
File "C:\Users\User\Documents\python\mptest.py", line 2, in <module>
q = mp.Queue()
File "C:\Python33\lib\multiprocessing\__init__.py", line 200, in Queue
from multiprocessing.queues import Queue
File "C:\Python33\lib\multiprocessing\queues.py", line 22, in <module>
from multiprocessing.connection import Pipe
File "C:\Python33\lib\multiprocessing\connection.py", line 21, in <module>
import tempfile
File "C:\Python33\lib\tempfile.py", line 35, in <module>
from random import Random as _Random
ImportError: cannot import name Random
I've never seen this happen before and a google search yielded no results. It only happens when it's ran from the command line. It runs perfectly fine in IDLE. I'm using Python 3.3.2.
I think its more to do with the version of python installed. I tried your code on cmd line as well as IDE but I got no errors. I have python 2.7 and 3.2 installed. But just to replicate your problem, I installed 3.3.2. I got the same error as you as I probably have random.py file too.

Python 2.5.4 ImportError: No module named collections

I'm fairly new to Python, and I don't understand what is going on here.
C:\Users\Mike\Desktop>storytext testGui.py
Traceback (most recent call last):
File "C:\Python25\Scripts\storytext.py", line 19, in <module>
from storytext.cmdline import main
File "C:\Python25\lib\site-packages\storytext-3.7-py2.5.egg\storytext\cmdline.py", line 3, in <module>
import scriptengine, definitions
File "C:\Python25\lib\site-packages\storytext-3.7-py2.5.egg\storytext\scriptengine.py", line 4, in
<module>
import recorder, replayer
File "C:\Python25\lib\site-packages\storytext-3.7-py2.5.egg\storytext\recorder.py", line 6, in <module>
from replayer import ReplayScript
File "C:\Python25\lib\site-packages\storytext-3.7-py2.5.egg\storytext\replayer.py", line 5, in <module>
from threading import Thread, Timer
File "C:\Python25\lib\threading.py", line 13, in <module>
from collections import deque
ImportError: No module named collections
Ok, no Module named collections. Indeed, when I search my python25 folder for collections, it's not there. I've read that it's located at Modules/_collectionsmodule.c, which I also can't find.
The kicker to the whole thing is that I can import collections from the interpreter, and I can from threading import Time, Timer in the interpreter.
I do have both python 2.5 and 2.6 on this machine, and it's running Windows 7.
Can anyone point me in the right direction?

Can someone help me understand this error:

I never know how to read these. It would be helpful if someone could help me understand this one, and maybe give advice on how to read these in general?
D:\>python captain2.py
Traceback (most recent call last):
File "captain2.py", line 2, in <module>
from twisted.internet import reactor
File "c:\Python27\lib\site-packages\twisted\internet\reactor.py", line 37, in
<module>
from twisted.internet import default
File "c:\Python27\lib\site-packages\twisted\internet\default.py", line 50, in
<module>
install = _getInstallFunction(platform)
File "c:\Python27\lib\site-packages\twisted\internet\default.py", line 46, in
_getInstallFunction
from twisted.internet.selectreactor import install
File "c:\Python27\lib\site-packages\twisted\internet\selectreactor.py", line 1
4, in <module>
from zope.interface import implements
ImportError: No module named zope.interface
In a stack traceback, Python lists the current call stack, in the order the calls happened. So, first your code in captain2.py:
from twisted.internet import reactor
Then the reactor module did:
from twisted.internet import default
and so on, until selectreactor.py did:
from zope.interface import implements
and apparently there does not exist a zope.interface module on your system.

Categories

Resources