IOError: [Errno 1] Operation not permitted: '/dev/uinput' - macos

I seem to have some problems let python read key event, I wrote this piece of code
for recording while i have space down and stop when i've release it..
import pyaudio
import wave
import keyboard
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "output.wav"
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
print("* recording")
frames = []
while keyboard.is_pressed('space'):
data = stream.read(CHUNK)
frames.append(data)
print("* done recording")
stream.stop_stream()
stream.close()
p.terminate()
wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
wf.close()
But when running this code, I get this error message.
python sound_record.py
* recording
Traceback (most recent call last):
File "sound_record.py", line 24, in <module>
while keyboard.is_pressed('space'):
File "/usr/local/lib/python2.7/site-packages/keyboard/__init__.py", line 162, in is_pressed
_listener.start_if_necessary()
File "/usr/local/lib/python2.7/site-packages/keyboard/_generic.py", line 36, in start_if_necessary
self.init()
File "/usr/local/lib/python2.7/site-packages/keyboard/__init__.py", line 112, in init
_os_keyboard.init()
File "/usr/local/lib/python2.7/site-packages/keyboard/_nixkeyboard.py", line 110, in init
build_device()
File "/usr/local/lib/python2.7/site-packages/keyboard/_nixkeyboard.py", line 106, in build_device
ensure_root()
File "/usr/local/lib/python2.7/site-packages/keyboard/_nixcommon.py", line 163, in ensure_root
raise ImportError('You must be root to use this library on linux.')
ImportError: You must be root to use this library on linux.
And when i do it using sudo:
sudo !!
sudo python sound_record.py
Password:
* recording
Traceback (most recent call last):
File "sound_record.py", line 24, in <module>
while keyboard.is_pressed('space'):
File "/usr/local/lib/python2.7/site-packages/keyboard/__init__.py", line 162, in is_pressed
_listener.start_if_necessary()
File "/usr/local/lib/python2.7/site-packages/keyboard/_generic.py", line 36, in start_if_necessary
self.init()
File "/usr/local/lib/python2.7/site-packages/keyboard/__init__.py", line 112, in init
_os_keyboard.init()
File "/usr/local/lib/python2.7/site-packages/keyboard/_nixkeyboard.py", line 110, in init
build_device()
File "/usr/local/lib/python2.7/site-packages/keyboard/_nixkeyboard.py", line 107, in build_device
device = aggregate_devices('kbd')
File "/usr/local/lib/python2.7/site-packages/keyboard/_nixcommon.py", line 141, in aggregate_devices
uinput = make_uinput()
File "/usr/local/lib/python2.7/site-packages/keyboard/_nixcommon.py", line 27, in make_uinput
uinput = open("/dev/uinput", 'wb')
IOError: [Errno 1] Operation not permitted: '/dev/uinput'
So why am I getting this error message?

You appear to be using the Python package keyboard, whose description is:
Hook and simulate keyboard events on Windows and Linux
If you want to do work with keyboard events on MacOS, you'll need to find a package that does that.

Related

unable to create executable using Py2exe, throwing error as mentioned below

Hi I'm trying to make an executable using py2exe, I checked my script but cannot find the actual issue why below error is keep getting pop-up during building of exe
Building 'dist\py.exe'.
Traceback (most recent call last):
File "C:\Users\User\PycharmProjects\Test\pyexe\setup.py", line 15, in <module>
freeze(
File "C:\Python39\lib\site-packages\py2exe\__init__.py", line 176, in freeze
builder.build()
File "C:\Python39\lib\site-packages\py2exe\runtime.py", line 254, in build
self.build_archive(exe_path)
File "C:\Python39\lib\site-packages\py2exe\runtime.py", line 479, in build_archive
base = dist_path.rsplit('\\', 1)[0]
AttributeError: 'NoneType' object has no attribute 'rsplit'
Below is my setup.py script
from py2exe import freeze
from py_version import VERSION, DESCRIPTION # This is my own script
freeze(
console=[{"script": "py.py"}],
options={
"py2exe": {
"dist_dir": "dist",
"bundle_files": 1, # bundle as much as possible
"compressed": True,
}},
version_info={"version":VERSION,
"description":DESCRIPTION,
"company_name":"Priyanshu Kumar",
"copyright":"Opensource, credit goes to David Manthey",
"product_name":"Stand-Alone Python3 Interpreter",
"product_version":VERSION},
zipfile=None)
UPDATE:
I was searching on google for help and found that it should be <<<zipfile="None">>> instead of <<<zipfile=None>>>.
I changed it in my code but now got new error
Traceback (most recent call last):
File "C:\Users\User\PycharmProjects\Test\pyexe\setup.py", line 29, in <module>
options={
File "C:\Python39\lib\site-packages\py2exe\__init__.py", line 176, in freeze
builder.build()
File "C:\Python39\lib\site-packages\py2exe\runtime.py", line 273, in build
self.build_archive(libpath, delete_existing_resources=True)
File "C:\Python39\lib\site-packages\py2exe\runtime.py", line 397, in build_archive
resource.add(type=os.path.basename(pydll), name=1, value=pydll_bytes)
File "C:\Python39\lib\site-packages\py2exe\resources.py", line 49, in add
raise WindowsError(details) from None
OSError: [WinError 87] The parameter is incorrect.
Press any key to continue . . .

how to read from h5py in multiprocessing without errors

I have code like:
def get_df(path, key):
with h5py.File(path) as hdf:
df = pd.DataFrame(np.array(hdf[key]))
return df
def f(key):
df = get_df(path, key)
...transform df...
return df
with multiprocessing.Pool(n_cpus) as pool:
rvals = pool.map(f, keys)
And I'm getting this error many times:
terminate called after throwing an instance of 'std::system_error'
what(): Resource temporarily unavailable
and one copy of this error:
Exception in thread Thread-1:
Traceback (most recent call last):
File "/home/lenail/.conda/envs/py38/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/home/lenail/.conda/envs/py38/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/home/lenail/.conda/envs/py38/lib/python3.8/multiprocessing/pool.py", line 513, in _handle_workers
cls._maintain_pool(ctx, Process, processes, pool, inqueue,
File "/home/lenail/.conda/envs/py38/lib/python3.8/multiprocessing/pool.py", line 337, in _maintain_pool
Pool._repopulate_pool_static(ctx, Process, processes, pool,
File "/home/lenail/.conda/envs/py38/lib/python3.8/multiprocessing/pool.py", line 326, in _repopulate_pool_static
w.start()
File "/home/lenail/.conda/envs/py38/lib/python3.8/multiprocessing/process.py", line 121, in start
self._popen = self._Popen(self)
File "/home/lenail/.conda/envs/py38/lib/python3.8/multiprocessing/context.py", line 277, in _Popen
return Popen(process_obj)
File "/home/lenail/.conda/envs/py38/lib/python3.8/multiprocessing/popen_fork.py", line 19, in __init__
self._launch(process_obj)
File "/home/lenail/.conda/envs/py38/lib/python3.8/multiprocessing/popen_fork.py", line 70, in _launch
self.pid = os.fork()
BlockingIOError: [Errno 11] Resource temporarily unavailable
any ideas why this might be or how to fix it? I had read that h5py supports multiprocessing.
Python 3.8.13 | packaged by conda-forge
>>> h5py.__version__
'3.6.0'

Timeout when trying to install Qiskit on macOS

I am trying to install Qiskit 0.20.0 on my machine running macOS and seeing the below error
pip install qiskit
Collecting qiskit
Using cached qiskit-0.20.0.tar.gz (4.0 kB)
Collecting qiskit-terra==0.15.1
Downloading qiskit_terra-0.15.1-cp38-cp38-macosx_10_9_x86_64.whl (7.6 MB)
|██▏ | 522 kB 7.7 kB/s eta 0:15:22ERROR: Exception:
Traceback (most recent call last):
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_vendor/urllib3/response.py", line 437, in _error_catcher
yield
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_vendor/urllib3/response.py", line 519, in read
data = self._fp.read(amt) if not fp_closed else b""
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_vendor/cachecontrol/filewrapper.py", line 62, in read
data = self.__fp.read(amt)
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/http/client.py", line 458, in read
n = self.readinto(b)
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/http/client.py", line 502, in readinto
n = self.fp.readinto(b)
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/socket.py", line 669, in readinto
return self._sock.recv_into(b)
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/ssl.py", line 1241, in recv_into
return self.read(nbytes, buffer)
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/ssl.py", line 1099, in read
return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_internal/cli/base_command.py", line 216, in _main
status = self.run(options, args)
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_internal/cli/req_command.py", line 182, in wrapper
return func(self, options, args)
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_internal/commands/install.py", line 324, in run
requirement_set = resolver.resolve(
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_internal/resolution/legacy/resolver.py", line 183, in resolve
discovered_reqs.extend(self._resolve_one(requirement_set, req))
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_internal/resolution/legacy/resolver.py", line 388, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install)
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_internal/resolution/legacy/resolver.py", line 340, in _get_abstract_dist_for
abstract_dist = self.preparer.prepare_linked_requirement(req)
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_internal/operations/prepare.py", line 467, in prepare_linked_requirement
local_file = unpack_url(
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_internal/operations/prepare.py", line 255, in unpack_url
file = get_http_url(
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_internal/operations/prepare.py", line 129, in get_http_url
from_path, content_type = _download_http_url(
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_internal/operations/prepare.py", line 282, in _download_http_url
for chunk in download.chunks:
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_internal/cli/progress_bars.py", line 168, in iter
for x in it:
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_internal/network/utils.py", line 64, in response_chunks
for chunk in response.raw.stream(
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_vendor/urllib3/response.py", line 576, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_vendor/urllib3/response.py", line 541, in read
raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/contextlib.py", line 131, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/local/anaconda3/envs/qiskit_env/lib/python3.8/site-packages/pip/_vendor/urllib3/response.py", line 442, in _error_catcher
raise ReadTimeoutError(self._pool, None, "Read timed out.")
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
The anaconda version on my machine is 4.8.4 and Python version is 3.8.5.
I have followed the instructions mentioned here and created a virtual environment before running
pip install qiskit
This looks like it's just a network issue. The error is a timeout trying to read from files.pythonhosted.org when pip was downloading the qiskit-terra package from PyPI. There isn't really anything you can do except to try again in such cases. If you're on a slow and/or unreliable internet connection it might take several tries take a few tries for the download of all the qiskit packages (and their dependencies) to succeed.

Celery not starting in OS X - dbm.error: db type is dbm.gnu, but the module is not available

I'm trying to run celery worker in OS X (Mavericks). I activated virtual environment (python 3.4) and tried to start Celery with this argument:
celery worker --app=scheduling -linfo
Where scheduling is my celery app.
But I ended up with this error: dbm.error: db type is dbm.gnu, but the module is not available
Complete stacktrace:
Traceback (most recent call last):
File "/Users/other/PhoenixEnv/lib/python3.4/site-packages/kombu/utils/__init__.py", line 320, in __get__
return obj.__dict__[self.__name__]
KeyError: 'db'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/other/PhoenixEnv/bin/celery", line 9, in <module>
load_entry_point('celery==3.1.9', 'console_scripts', 'celery')()
File "/Users/other/PhoenixEnv/lib/python3.4/site-packages/celery/__main__.py", line 30, in main
main()
File "/Users/other/PhoenixEnv/lib/python3.4/site-packages/celery/bin/celery.py", line 80, in main
cmd.execute_from_commandline(argv)
File "/Users/other/PhoenixEnv/lib/python3.4/site-packages/celery/bin/celery.py", line 768, in execute_from_commandline
super(CeleryCommand, self).execute_from_commandline(argv)))
File "/Users/other/PhoenixEnv/lib/python3.4/site-packages/celery/bin/base.py", line 308, in execute_from_commandline
return self.handle_argv(self.prog_name, argv[1:])
File "/Users/other/PhoenixEnv/lib/python3.4/site-packages/celery/bin/celery.py", line 760, in handle_argv
return self.execute(command, argv)
File "/Users/other/PhoenixEnv/lib/python3.4/site-packages/celery/bin/celery.py", line 692, in execute
).run_from_argv(self.prog_name, argv[1:], command=argv[0])
File "/Users/other/PhoenixEnv/lib/python3.4/site-packages/celery/bin/worker.py", line 175, in run_from_argv
return self(*args, **options)
File "/Users/other/PhoenixEnv/lib/python3.4/site-packages/celery/bin/base.py", line 271, in __call__
ret = self.run(*args, **kwargs)
File "/Users/other/PhoenixEnv/lib/python3.4/site-packages/celery/bin/worker.py", line 209, in run
).start()
File "/Users/other/PhoenixEnv/lib/python3.4/site-packages/celery/worker/__init__.py", line 100, in __init__
self.setup_instance(**self.prepare_args(**kwargs))
File "/Users/other/PhoenixEnv/lib/python3.4/site-packages/celery/worker/__init__.py", line 141, in setup_instance
self.blueprint.apply(self, **kwargs)
File "/Users/other/PhoenixEnv/lib/python3.4/site-packages/celery/bootsteps.py", line 221, in apply
step.include(parent)
File "/Users/other/PhoenixEnv/lib/python3.4/site-packages/celery/bootsteps.py", line 347, in include
return self._should_include(parent)[0]
File "/Users/other/PhoenixEnv/lib/python3.4/site-packages/celery/bootsteps.py", line 343, in _should_include
return True, self.create(parent)
File "/Users/other/PhoenixEnv/lib/python3.4/site-packages/celery/worker/components.py", line 220, in create
w._persistence = w.state.Persistent(w.state, w.state_db, w.app.clock)
File "/Users/other/PhoenixEnv/lib/python3.4/site-packages/celery/worker/state.py", line 161, in __init__
self.merge()
File "/Users/other/PhoenixEnv/lib/python3.4/site-packages/celery/worker/state.py", line 169, in merge
self._merge_with(self.db)
File "/Users/other/PhoenixEnv/lib/python3.4/site-packages/kombu/utils/__init__.py", line 322, in __get__
value = obj.__dict__[self.__name__] = self.__get(obj)
File "/Users/other/PhoenixEnv/lib/python3.4/site-packages/celery/worker/state.py", line 238, in db
return self.open()
File "/Users/other/PhoenixEnv/lib/python3.4/site-packages/celery/worker/state.py", line 165, in open
self.filename, protocol=self.protocol, writeback=True,
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/shelve.py", line 239, in open
return DbfilenameShelf(filename, flag, protocol, writeback)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/shelve.py", line 223, in __init__
Shelf.__init__(self, dbm.open(filename, flag), protocol, writeback)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/dbm/__init__.py", line 91, in open
"available".format(result))
dbm.error: db type is dbm.gnu, but the module is not available
Please help.
I switched to python3.5 and got the same error. On Ubuntu I could fix it with
aptitude install python3.5-gdbm
I got the same error. On Macbook I could fix it with
brew install gdb

Google Apis Client Generator Python Not Running

I'm trying to execute Google APIs Client Generator to build new ADMIN-SDK for Java Language however I'm stuck in the generator, I've tried step by step using python2.6 and python2.7 both had similar outputs.
$ python $(/bin/pwd)/googleapis/codegen/generate_library.py --api_name=plus --api_version=v1 --language=java --output_dir=/tmp/gen --language=java
Traceback (most recent call last): File
"/Users/alejacquet/Development/git/google-apis-client-generator/src/googleapis/codegen/generate_library.py",
line 245, in
app.run() File "/Library/Python/2.7/site-packages/google_apputils-0.3.0-py2.7.egg/google/apputils/app.py",
line 216, in run
return _actual_start() File "/Library/Python/2.7/site-packages/google_apputils-0.3.0-py2.7.egg/google/apputils/app.py",
line 244, in _actual_start
really_start() File "/Library/Python/2.7/site-packages/google_apputils-0.3.0-py2.7.egg/google/apputils/app.py",
line 203, in really_start
sys.exit(main(argv)) File "/Users/alejacquet/Development/git/google-apis-client-generator/src/googleapis/codegen/generate_library.py",
line 152, in main
language_variant=FLAGS.language_variant) File "/Users/alejacquet/Development/git/google-apis-client-generator/src/googleapis/codegen/generate_library.py",
line 179, in Generate
language_variations = Targets().VariationsForLanguage(language) File
"/Users/alejacquet/Development/git/google-apis-client-generator/src/googleapis/codegen/targets.py",
line 68, in init
files.GetFileContents(self.targets_path)) File "/Users/alejacquet/Development/git/google-apis-client-generator/src/googleapis/codegen/json_with_comments.py",
line 54, in Loads
return json.loads(stripped, **kw) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/init.py",
line 326, in loads
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py",
line 366, in decode File
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py",
line 382, in raw_decode ValueError: Expecting property name: line 9
column 9 (char 198)
Any ideas?
You may have to specify --language_variant=XXX, where XXX is one of the directory names under .../templates/java

Resources