运行Python文件时终端错误
规格: Macos Monterey,没有可用的更新,Python 3.10.4
问题: 我会收到错误ZSH:分割故障sudo python3
当我尝试运行此命令sudo python3'/users/users/cyberstorm/document/document/visual Studio code/terminal Adventure/maincode.py'时
此命令正在尝试使用绝对路径在管理员中运行Python文件maincode.py。我无法理解为什么我会遇到这个错误。
我要做的事情: 我为Python安装了键盘模块,以便可以使用键盘输入。我完成了编码并使用了模块。我相信我的代码是正确的。当我尝试正常运行文件时,我会收到此错误
Exception in thread Thread-1 (listen):
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 1009, in _bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 946, in run
self._target(*self._args, **self._kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/keyboard/__init__.py", line 294, in listen
_os_keyboard.listen(self.direct_callback)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/keyboard/_darwinkeyboard.py", line 430, in listen
raise OSError("Error 13 - Must be run as administrator")
OSError: Error 13 - Must be run as administrator
,因此我想使用sudo命令并使用sudo python3 maincode.py
不起作用,因为显然该文件不存在。因此,我尝试了绝对的道路,这将我带到这里。
Specs:
MacOS Monterey, no available updates, Python 3.10.4
Problem:
I'm getting the error zsh: segmentation fault sudo python3
when I try to run this command sudo python3 '/Users/cyberstorm/Documents/Visual Studio Code/Terminal Adventure/mainCode.py'
This command is trying to run the python file mainCode.py as in administrator using the absolute path. I'm unable to understand why I'm getting this error.
What I'm trying to do:
I installed the keyboard module for python so I could use keyboard inputs. I finished coding and using the module. I believe my code is correct. When I tried running the file normally, I got this error
Exception in thread Thread-1 (listen):
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 1009, in _bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 946, in run
self._target(*self._args, **self._kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/keyboard/__init__.py", line 294, in listen
_os_keyboard.listen(self.direct_callback)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/keyboard/_darwinkeyboard.py", line 430, in listen
raise OSError("Error 13 - Must be run as administrator")
OSError: Error 13 - Must be run as administrator
Thus I wanted to use the sudo command and using sudo python3 mainCode.py
didn't work because apparently the file didn't exist. So I tried the absolute path, which brings me here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决问题的方法!我不太确定发生了什么事,还有更多运气。我所做的是运行命令(在终端)
python3 -m Pip install键盘
。我还确保使用此站点。一旦我运行了代码,请确保没有错误,它就可以了!感谢所有帮助,包括我上一篇文章!I found a way to fix the issue! I'm not too sure on what happened, more of luck. What I did was run the command (in terminal)
python3 -m pip install keyboard
. I also made sure to properly install and checkpip
using this site. Once I ran the code, making sure there were no errors, it worked! Thanks to all that helped, including on my previous post!