为什么当我导入 pynput 并使用它时它会删除我的 python 文件?
发生了一些奇怪的事情。
简而言之 - 当我使用 pynput
lib
时,我的 .py 文件会被自动删除 详细解释- 我创建了一个名为 keylog.py
的文件 我已经安装了 ->pip install pynput
,
当我运行代码时:
import logging
logging.basicConfig(filename=("keylog.txt"), level=logging.DEBUG, format=" %(asctime)s - %(message)s")
def onPress(key):
logging.info(str(key))
一切正常。
But when I add:
# from pynput.keyboard import Key, Listener
import logging
logging.basicConfig(filename=("keylog.txt"), level=logging.DEBUG, format=" %(asctime)s - %(message)s")
def onPress(key):
logging.info(str(key))
# with Listener(on_press=onPress) as listener:
# listener.join()
即使 pynput 导入被注释掉,keylog.py
文件也会自动删除。
我不知道为什么会发生这种情况,我尝试删除 PyCharm 并重新安装,我尝试在 VScode 中工作,同样的事情发生。
我没有配置任何特殊的东西。
我需要一些帮助和解释为什么会发生这种情况,谢谢。
something weird is happening.
In short explanation - my .py file gets deleted automatically when I use pynput
lib
Detailed explanation -
I create a file called keylog.py
I have installed ->pip install pynput
,
when I run the code:
import logging
logging.basicConfig(filename=("keylog.txt"), level=logging.DEBUG, format=" %(asctime)s - %(message)s")
def onPress(key):
logging.info(str(key))
Everything is ok.
But when I add:
# from pynput.keyboard import Key, Listener
import logging
logging.basicConfig(filename=("keylog.txt"), level=logging.DEBUG, format=" %(asctime)s - %(message)s")
def onPress(key):
logging.info(str(key))
# with Listener(on_press=onPress) as listener:
# listener.join()
Even if the pynput import is commented out the keylog.py
file gets deleted automatically.
I have no idea why this happen, I tried to delete PyCharm and re-install, I tried working in VScode, same thing happening.
I didn't configure something special.
I would like some help and explanation why this happen, Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
发现问题以后是否有人遇到同样的问题。
当我由于某种原因打开一个项目时,它没有问我是否要信任这个项目。
因此,Windows Defender 将
pynput
视为可能是恶意的,因此它会阻止这些文件,直到我将它们设置为信任为止。Found the issue if anyone in the future will have the same problem.
when I opened a project for some reason it didn't ask me if I want to trust this project.
therefore, the windows defender sees
pynput
as maybe malicious so it blocked these files, until I made them trusted.基本上 pynput 用于记录击键,这在 Windows 安全中被称为恶意。尝试禁用它!
Basically pynput is used to record keystrokes which is termed as Malicious in Windows Security. Try Disabling it!