所谓的成功,就是用自己的方式度过人生。
一、环境
- go version:go version go1.23.5 windows/amd64
- python –version:Python 3.5.3
- pip –version:pip 20.3.4
- systeminfo:Microsoft Windows 11 专业版
二、代码
- Server.go
1 | package main |
- Client.py
1 | import sys, socket, random, _thread |
运行Server:go run Server.go
- go env -w CGO_ENABLED=0 GOOS=windows GOARCH=amd64
- go build Server.go,会生成Server.exe
- 双击运行Server.exe
运行Client.py
- pip install PyQt5
- python Client.py
- 打包为可执行文件
- 安装Pyinstaller库:pip install pyinstaller
- 打包为单独可执行文件:pyinstaller -F Client.py
- 其他参数:pyinstaller –help
- -w:不带控制台窗口
- -i:设置图标
- -name:可执行文件名称
- -add-data:将外部文件添加到可执行文件中
- -clean:清理上次构建过程中产生的临时文件
三、问题
Python执行报错
- ImportError: No module named ‘PyQt5’
- pip install PyQt5,继续报错
- error: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools”: https://visualstudio.microsoft.com/visual-cpp-build-tools/
- 下载安装Microsoft Visual C++ 14.0
- 再次执行:pip install PyQt5,正常运行
- pip install PyQt5,继续报错
- ImportError: No module named ‘PyQt5’
Windows打包Linux/Mac可执行文件
- go env -w CGO_ENABLED=0 GOOS=linux GOARCH=amd64
- 或者:
- SET CGO_ENABLED=0
- SET GOOS=linux
- SET GOARCH=amd64
- 或者:
- go env -w CGO_ENABLED=0 GOOS=darwin3 GOARCH=amd64
- 报错:go: unsupported GOOS/GOARCH pair darwin3/amd64
- 修改:go env -w CGO_ENABLED=0 GOOS=darwin GOARCH=amd64,正常
- 或者:
- SET CGO_ENABLED=0
- SET GOOS=darwin
- SET GOARCH=amd64
- 报错:go: unsupported GOOS/GOARCH pair darwin3/amd64
- go env -w CGO_ENABLED=0 GOOS=linux GOARCH=amd64