安装detectron2一堆的错误. 为啥一定要编译呢??凡是编译的就没有一次顺顺利利的. 烦死了, 浪费我生命. 最后放弃了

博主尝试在Windows下从源码编译detectron2,过程中状况不断,编译命令报错且难寻解决方案,即便解决编译问题,运行识别命令仍找不到包。尝试多种方法后仍无法解决,最终因detectron2对Windows支持不佳,且自身C++功底不足,放弃在Windows编译,建议改用Ubuntu。

凡是想在windows下从源码编译detectron2的,没有深厚的c++功底, 我劝你还是放弃吧. 改用Ubuntu 去编译轻松又方便.

昨天还能编译成功的, 今天就编译不成功了.
编译命令如下

git clone https://github.com/facebookresearch/detectron2.git
python -m pip install -e detectron2

结果报了一大堆的错误… 而且怎么都搜不到解决方案…

 ERROR: Command errored out with exit status 1:
     command: 'D:\Anaconda3\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'F:\\PySlowFast\\pyslowfast\\detectron2_repo\\setup.py'"'"'; __file__='"'"'F:\\PySlowFast\\pyslowfast\\detectron2_repo\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps
         cwd: F:\PySlowFast\pyslowfast\detectron2_repo\
    Complete output (47 lines):
    No CUDA runtime is found, using CUDA_HOME='C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2'
    running develop
    running egg_info
    writing detectron2.egg-info\PKG-INFO
    writing dependency_links to detectron2.egg-info\dependency_links.txt
    writing requirements to detectron2.egg-info\requires.txt
    writing top-level names to detectron2.egg-info\top_level.txt
    adding license file 'LICENSE' (matched pattern 'LICEN[CS]E*')
    reading manifest file 'detectron2.egg-info\SOURCES.txt'
    writing manifest file 'detectron2.egg-info\SOURCES.txt'
    running build_ext
    buil
经过分析,鼠标操作没有被正确录制的原因可能在于以下几点: 1. **事件监听未生效**:`keyboard.hook` 可能没有正确捕获鼠标事件。 2. **事件类型不匹配**:当前代码中使用了 `keyboard` 模块来捕获鼠标事件,但该模块主要设计用于键盘事件,可能对鼠标事件的支持不够全面。 3. **缺少鼠标移动事件**:如果需要记录鼠标移动行为,则需要额外的逻辑。 --- ### 解决方案 #### 1. 使用 `pynput` 替代 `keyboard` 捕获鼠标事件 `pynput` 是一个专门用于捕获鼠标和键盘事件的库,功能更强大且稳定。以下是修正后的代码。 ```python import pynput class ActionRecorder: def __init__(self): # 初始化鼠标监听器 self.mouse_listener = pynput.mouse.Listener(on_click=self.on_mouse_click, on_scroll=self.on_mouse_scroll) self.mouse_listener.start() def on_mouse_click(self, x, y, button, pressed): if not self.recording: return action_type = "mousedown" if pressed else "mouseup" self.actions.append({ "type": action_type, "button": str(button).split('.')[1], # 提取按钮名称 "x": x, "y": y, "time": time.time() }) self.log_message(f"{'按下' if pressed else '释放'} 鼠标 {button} 键 位置: ({x}, {y})") def on_mouse_scroll(self, x, y, dx, dy): if not self.recording: return self.actions.append({ "type": "wheel", "delta": dy, # 滚轮方向 "x": x, "y": y, "time": time.time() }) self.log_message(f"滚轮滚动: {'上' if dy > 0 else '下'} 位置: ({x}, {y})") ``` --- ### 给出解释 1. **`pynput.mouse.Listener` 的使用**: - `pynput.mouse.Listener` 提供了 `on_click` 和 `on_scroll` 回调函数,分别用于捕获鼠标点击和滚轮滚动事件。 - `on_click` 回调函数接收参数 `x`, `y`, `button`, `pressed`,其中: - `x`, `y` 表示鼠标点击的坐标。 - `button` 表示鼠标按键(如 `Button.left`、`Button.right`)。 - `pressed` 表示是否为按下事件。 - `on_scroll` 回调函数接收参数 `x`, `y`, `dx`, `dy`,其中: - `dx`, `dy` 表示滚轮滚动的方向和幅度。 2. **事件过滤**: - 在回调函数中,我们通过 `if not self.recording: return` 确保只在录制状态下捕获事件。 3. **数据结构优化**: - 每个事件都被存储为字典形式,包含类型 (`type`)、按钮 (`button`)、位置 (`x`, `y`) 和时间戳 (`time`)。 4. **日志记录**: - 每次捕获事件时,都会生成详细的日志信息,便于调试和验证。 --- ###
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值