2022-09-03 05:28:20 +00:00
|
|
|
|
---
|
2022-09-03 10:06:05 +00:00
|
|
|
|
title: Python 环境搭建
|
2022-09-03 09:45:34 +00:00
|
|
|
|
categories:
|
|
|
|
|
- Python
|
|
|
|
|
keywords:
|
|
|
|
|
- Python
|
|
|
|
|
- pip
|
|
|
|
|
- pypi
|
|
|
|
|
- pipenv
|
|
|
|
|
tags:
|
|
|
|
|
- Python
|
2022-09-03 05:28:20 +00:00
|
|
|
|
date: 2022-09-03 12:13:10
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# 安装 Python
|
|
|
|
|
|
|
|
|
|
只有 Windows 用户需要注意一点,用安装程序安装时一定要记得勾选 `Add Python to PATH`。
|
|
|
|
|
|
|
|
|
|
# pip
|
|
|
|
|
|
|
|
|
|
Python 包管理器 pip 的配置文件在 `$HOME/.config/pip/pip.conf`
|
|
|
|
|
|
|
|
|
|
执行以下语句,可以为当前用户设置 pypi 安装源:
|
|
|
|
|
|
|
|
|
|
``` sh
|
|
|
|
|
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
执行完毕后,`pip.conf` 中会添加如下设置:
|
|
|
|
|
|
|
|
|
|
``` conf pip.conf
|
|
|
|
|
[global]
|
|
|
|
|
index-url = https://mirrors.ustc.edu.cn/pypi/web/simple
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
pip 常用的命令:
|
|
|
|
|
|
|
|
|
|
``` sh
|
|
|
|
|
pip install <package> --user # 为当前用户安装指定的包
|
|
|
|
|
pip list --user # 列出为当前用户安装的包
|
|
|
|
|
pip show <package> # 显示指定包的详情
|
|
|
|
|
pip install <package> --upgrade # 升级指定的包,或可用短参数-U
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
当前用户安装的包保存在 `$HOME/.local/lib/python3.xx/site-packages` 中。
|
|
|
|
|
|
|
|
|
|
# pipenv
|
|
|
|
|
|
|
|
|
|
一个 Python 虚拟环境管理器,安装方法 `pip install pipenv --user` 。
|
|
|
|
|
|
|
|
|
|
添加将以下环境参数,pipenv 就可以在当前路径中创建 Python 虚拟环境了:
|
|
|
|
|
|
|
|
|
|
``` conf env
|
|
|
|
|
PIPENV_VENV_IN_PROJECT=enabled
|
|
|
|
|
PIPENV_IGNORE_VIRTUALENVS=1
|
|
|
|
|
PIPENV_VERBOSITY=-1
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
# vscode
|
|
|
|
|
|
|
|
|
|
在 VS Code 中的配置 Python 开发环境,待续...
|