python -m SimpleHTTPServer mac报错

错误内容:

复制代码
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SimpleHTTPServer.py", line 235, in <module>
    test()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SimpleHTTPServer.py", line 231, in test
    BaseHTTPServer.test(HandlerClass, ServerClass)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/BaseHTTPServer.py", line 606, in test
    httpd = ServerClass(server_address, HandlerClass)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 420, in __init__
    self.server_bind()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/BaseHTTPServer.py", line 108, in server_bind
    SocketServer.TCPServer.server_bind(self)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 434, in server_bind
    self.socket.bind(self.server_address)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 228, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 48] Address already in use

错误原因:mac测试网速端口被占用

解决方法:

1)在命令行输入【lsof -i port】,获取占用进程的pid。

复制代码
#示例
lsof -i:8000

2)在命令行输入【kill -9 PID】,杀死进程。

复制代码
#示例
kill -9 78191

3)在命令行输入【python -m SimpleHTTPServer】,即可运行

参考:

mac端口号被占用怎么解决_mac 端口占用-CSDN博客

相关推荐
C^h1 小时前
python函数学习
人工智能·python·机器学习
Fanta丶1 小时前
4.Python set()集合、dict(字典、映射)、 数据容器的通用功能
python
决战灬1 小时前
langgraph之interrupt(理论篇)
人工智能·python·agent
兜客互动2 小时前
2026年AI关键词拓展挖掘软件,高效助力内容创作精准获流
人工智能·python
weixin_538601972 小时前
智能体测开Day30pytest测试框架
python
MC皮蛋侠客2 小时前
uv 系列(七):CI/CD、Docker 与私有索引——生产级交付
python·ci/cd·docker·uv
邪神与厨二病2 小时前
牛客周赛 Round 153
python·算法
yaoxin5211232 小时前
470. Java 反射 - Member 接口与 AccessFlag
java·开发语言·python
groundhappy3 小时前
idalib安装和codex ida-mcp配置
linux·开发语言·python
培之3 小时前
RTX 5090 安装 pytorch3d
人工智能·pytorch·python