1.设置国内镜像源
设置主源(清华)
pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/
pip3 config set global.trusted-host pypi.tuna.tsinghua.edu.cn
设置备用源(阿里云)
pip3 config set global.extra-index-url https://mirrors.aliyun.com/pypi/simple/
为每个备用源的主机名单独设置 trusted-host
pip3 config set global.trusted-host mirrors.aliyun.com
2.使用venv 创建虚拟环境
python3 -m venv 项目名
3.激活虚拟环境
windows cmd命令: 进入项目/Script,输入activate会激活
windows emacs项目:
在项目根目录创建..dir-locals.el,内容为
((python-mode . ((python-shell-interpreter . "C:/你的项目路径/venv/Scripts/python.exe")
(python-shell-virtualenv-root . "C:/你的项目路径/venv"))))
这样使用emacs打开项目下的.py文件会自动激活虚拟环境
linux 项目可以统一使用direnv
4.安装包
pip3 install polars
5.关闭虚拟环境
进入项目/Script,输入deactivate会退出