开发Python

=== 安装篇 更新 2026.11 ===
PyManager 是 Python 官方推出的安装与管理工具,可用于安装、切换 Python 版本,并支持虚拟环境和进程管理。
在 Windows 上使用 PyManager 安装 Python,只需先安装 PyManager(推荐通过 Microsoft Store 或 winget install 9NQ7512CXL7T),然后运行 py install 3.x 即可安装指定版本的 Python。
1. 安装 PyManager(Python Install Manager)
PyManager 是 Python 官方推出的新一代 Windows 安装管理器,从 Python 3.16 起取代传统 .exe 安装包。

安装与初始化

下载与安装:访问 python.org 或 Microsoft Store 下载 PyManager 的 MSIX 安装包,双击安装即可。安装完成后,系统会自动注册 python、python3、py 和 pymanager 四个命令 洛谷洛谷+1。
启用别名:在 Windows 系统设置中开启 App Execution Aliases,确保 %LocalAppData%\Microsoft\WindowsApps 在 PATH 中,以便命令行识别 Python 命令 博客园博客园。
配置默认版本:通过配置文件 %AppData%\Python\PyManager.json 设置 “default”: “3.12” 来指定默认 Python 版本 洛谷洛谷。

Python 版本管理

查看已安装版本:运行 py list 或 pymanager list 查看当前管理的 Python 版本 51CTO51CTO。
安装指定版本:使用 py install 3.14 安装特定版本,支持离线安装和便携式安装 洛谷洛谷+1。
切换版本:通过 py -3.14 或在虚拟环境中激活后使用 python 命令即可自动指向虚拟环境的 Python 洛谷洛谷+1。
设置默认版本:在命令行中使用 py default 3.14 或修改配置文件实现全局默认版本 博客园博客园。

虚拟环境支持

PyManager 与 venv 完全兼容,激活虚拟环境后,python 命令会指向虚拟环境中的解释器,不影响全局版本 洛谷洛谷+1。
建议每个项目创建独立虚拟环境,避免包版本冲突。

进程管理功能(Python 进程管理器)

配置文件管理:通过 pymanager.json 定义进程启动规范,可通过 -f 或 –file 指定其他配置文件 CSDNCSDN。
守护进程模式:使用 -d 或 –daemon 参数将 PyManager 作为后台服务运行,持续监控进程状态 CSDNCSDN。
核心对象:包括 Process(进程)和 Validator(验证器),用于启动进程和检查状态,确保测试环境稳定 CSDNCSDN。
HTTP 接口管理:可通过 HTTP 接口重启进程或执行管理操作,未来版本可能提供命令行工具支持更复杂场景 CSDNCSDN。

常用命令速查

py list:列出已安装 Python 版本
py install :安装指定版本
py –:运行指定版本 Python
py default :设置默认版本
pymanager -f :指定配置文件运行
pymanager -d:以守护进程模式运行
通过以上操作,用户可以高效管理 Python 版本、虚拟环境以及测试环境中的进程,实现开发和测试流程的自动化与稳定性。

2. 使用 PyManager 安装 Python
PyManager 安装 Python 的核心命令是 py install。

✅ 安装最新稳定版
py install default

✅ 安装指定版本
py install 3.12
py install 3.14

✅ 安装精确版本
py install 3.12.5

✅ 查看可安装版本
py list –online

3. 切换与运行 Python 版本
✅ 使用指定版本运行脚本
py -3.12 script.py
py -V:3.14 script.py

✅ 查看已安装版本
py list

4. 升级与卸载 Python
✅ 升级所有版本
py install –upgrade

✅ 卸载指定版本
py uninstall 3.12

✅ 完全清理
py uninstall –purge

5. 设置默认 Python 版本
编辑配置文件:
%AppData%\Python\pymanager.json
示例:
{ “default_tag”: “3.14” }

6. 虚拟环境(推荐)
py -3.12 -m venv .venv
.\.venv\Scripts\activate

Python很热,广告一堆吹,听起来有点懵,不过,Python 项目确实很多,AI类的比较集中
=== 安装篇 ===

常规开发环境,anaconda
https://www.anaconda.com/products/individual 这个是个人版(免费)下载地址
https://docs.conda.io/en/latest/miniconda.html miniconda 精简版
下载地址https://www.anaconda.com/download/success

安装conda 后可执行,


查看源
conda config --show-sources
添加仓库
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
第三方源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
删除源
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

换回默认源:conda config --remove-key channels
清华曾停止服务, 而且有时也不一定能快
近期在装 conda install geopandas 就不能使用第三方源,换回默认源后即可正常安装

使用 SJTUG源


官方源
pkgs/free:   conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/free
pkgs/main:   conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main
pkgs/mro:    conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/mro
pkgs/msys2:  conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/msys2
pkgs/pro: (deprecated) conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/pro
pkgs/r: (empty) conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/r
第三方源:
cloud/bioconda: conda config --set custom_channels.bioconda https://mirrors.sjtug.sjtu.edu.cn/anaconda/cloud/
cloud/conda-forge: conda config --set custom_channels.conda-forge https://mirrors.sjtug.sjtu.edu.cn/anaconda/cloud/
cloud/menpo: conda config --set custom_channels.menpo https://mirrors.sjtug.sjtu.edu.cn/anaconda/cloud/
cloud/soumith: conda config --set custom_channels.soumith https://mirrors.sjtug.sjtu.edu.cn/anaconda/cloud/
cloud/viscid-hub: conda config --set custom_channels.viscid-hub https://mirrors.sjtug.sjtu.edu.cn/anaconda/cloud/
cloud/atztogo: conda config --set custom_channels.atztogo https://mirrors.sjtug.sjtu.edu.cn/anaconda/cloud/
cloud/pytorch: conda config --set custom_channels.pytorch https://mirrors.sjtug.sjtu.edu.cn/anaconda/cloud/
cloud/pytorch-test: conda config --set custom_channels.pytorch-test https://mirrors.sjtug.sjtu.edu.cn/anaconda/cloud/


安装目录参考 C:\cmdcons\Anaconda3

打开 Anaconda Prompt (Anaconda3)
执行
镜像地址可以考虑其他的,看喜好吧,


pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
pip config set global.trusted-host mirrors.aliyun.com
python --version

深圳马版本


pip config set global.index-url https://mirrors.cloud.tencent.com/pypi/simple
pip config set global.trusted-host mirrors.cloud.tencent.com
pip install pip -U
python --version


conda创建Python27的环境

 
python --version
conda create -n py27 python=2.7
conda activate py27
python --version
conda create -n py37 python=3.7
conda activate py37
python --version

常用科学计算的库

 
pip install numpy scipy pandas matplotlib scikit-learn

=== pytorch , cuda 南京大学镜像 ===
pip install torch torchvision torchaudio –index-url https://mirrors.nju.edu.cn/pytorch/whl/cu128

=== 错误篇===

AttributeError: type object ‘Callable’ has no attribute ‘_abc_registry’
错误:Rasa init –no-prompt 报错
原因:Python升级到3.7后会遇到该问题
解决:pip uninstall typing

=== 项目案例篇 ===

===
https://github.com/DLR-RM/stable-baselines3

pip install PyHamcrest cloudpickle numpy 
pip install stable-baselines3

编辑器pycharm
https://www.jetbrains.com/zh-cn/pycharm/download/download-thanks.html?platform=windows