On Ubuntu 18.04, I am trying to create a conda virtual env which has mido
and keyboard
modules installed. This is successfully done using conda create -n my_env python=2.7
and pip install
for mido
and keyboard
. No errors are raised when I run python from within the conda virtual env then type import mido
and import keyboard
.
The problem is when I try to run keyboard.on_press(keyboard_thread)
which calls keyboard_thread
function I wrote in a separate thread, I get this error:
Traceback (most recent call last):
File "my_code.py", line 361, in <module>
keyboard.on_press(keyboard_thread)
File "/home/hany/miniconda3/envs/conda_sika/lib/python2.7/site-packages/keyboard/__init__.py", line 474, in on_press
return hook(lambda e: e.event_type == KEY_UP or callback(e), suppress=suppress)
File "/home/hany/miniconda3/envs/conda_sika/lib/python2.7/site-packages/keyboard/__init__.py", line 461, in hook
append(callback)
File "/home/hany/miniconda3/envs/conda_sika/lib/python2.7/site-packages/keyboard/_generic.py", line 67, in add_handler
self.start_if_necessary()
File "/home/hany/miniconda3/envs/conda_sika/lib/python2.7/site-packages/keyboard/_generic.py", line 35, in start_if_necessary
self.init()
File "/home/hany/miniconda3/envs/conda_sika/lib/python2.7/site-packages/keyboard/__init__.py", line 196, in init
_os_keyboard.init()
File "/home/hany/miniconda3/envs/conda_sika/lib/python2.7/site-packages/keyboard/_nixkeyboard.py", line 113, in init
build_device()
File "/home/hany/miniconda3/envs/conda_sika/lib/python2.7/site-packages/keyboard/_nixkeyboard.py", line 109, in build_device
ensure_root()
File "/home/hany/miniconda3/envs/conda_sika/lib/python2.7/site-packages/keyboard/_nixcommon.py", line 174, 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.
I tried to run sudo python my_code.py
, no errors come from keyboard.on_press(keyboard_thread)
, but then import mido
returns ImportError: No module named mido
Is there a way I can have a virtual environment that has the two modules running without problems?
I appreciate your help.