安装Python
MacOS
1 2 3 4
| brew install python3
brew install python-tk@3.13 brew install tcl-tk
|
下载pkg文件安装
https://www.python.org/downloads/macos/
1 2
| wget https://www.python.org/ftp/python/3.13.1/python-3.13.1-macos11.pkg
|
运行安装pkg文件
镜像源
1 2 3
| pip install -i https://mirrors.ustc.edu.cn/pypi/simple pip -U pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/simple
|
虚拟环境管理
创建虚拟环境
切换虚拟环境
Windows
1
| .\math\Scripts\activate.bat
|
macOS
1 2 3 4
| source ~/math/bin/activate
. ~/math/bin/activate
|
安装包
查看已安装的包
退出环境
Windows
1
| .\math\Scripts\deactivate.bat
|
macOS
删除环境
打包
Windows
运行命令
1
| pyinstaller -F -w -i favicon.ico mathapp.py
|
参数说明:
--onefile 或 -F:将所有文件打包成一个独立的可执行文件
--windowed 或 -w:为 Windows
创建一个窗口化的应用程序(不显示命令行窗口)
--icon 或 -i:为你的 EXE 文件指定一个 ICO 图标文件(可选)
MacOS
编辑setup.py文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| """ This is a setup.py script generated by py2applet
Usage: python setup.py py2app """
from setuptools import setup
APP = ['mathapp.py'] DATA_FILES = ['favicon.png'] OPTIONS = {"iconfile" : "favicon.png"}
setup( app=APP, data_files=DATA_FILES, options={'py2app': OPTIONS}, setup_requires=['py2app'], )
|
运行命令: