mido
在 Ubuntu 18.04 上,我正在尝试创建一个安装了模块的 conda 虚拟环境keyboard
。这是使用conda create -n my_env python=2.7
and pip install
for mido
and成功完成的keyboard
。当我从 conda 虚拟环境中运行 python 然后键入import mido
和import keyboard
.
问题是当我尝试运行我在单独线程中编写的keyboard.on_press(keyboard_thread)
调用keyboard_thread
函数时,我收到此错误:
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.
我尝试运行sudo python my_code.py
,没有错误出现 keyboard.on_press(keyboard_thread)
,但随后import mido
返回ImportError: No module named mido
有没有办法让我有一个虚拟环境可以让两个模块正常运行?
我感谢您的帮助。