0

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.

Hano
  • 1
  • 1
  • 5
  • Can you try getting mido from https://anaconda.org/roebel/mido ? I wouldn't be surprised if the fact that they're being installed using pip is at least part of the problem. – AMC Mar 18 '20 at 22:31
  • I couldn't find `keyboard` install under `conda`. I created a new virtual env with `conda` then installed `mido` using the link you sent me (which works only with python 3, no problem), then installed `keyboard` using `pip`. When I ran `sudo python my_code.py` I still get `No module named 'mido'` – Hano Mar 18 '20 at 23:22
  • Can you check from within the script which Python installation is being used? – AMC Mar 18 '20 at 23:37
  • I wrote the script myself and I am using python 2.7, but this is not a problem, I can change it to 3.7 if needed. I hope I can get this issue fixed – Hano Mar 19 '20 at 00:08

0 Answers0