pip使用详解 pipdeptree使用详解 python安装管理器 python虚拟环境

2015-03-25 16:32:00
admin
原创 329
摘要:pip使用详解 pipdeptree使用详解 python安装管理器 python虚拟环境

一、pip使用详解

1、帮助文档:https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments

2、帮助文档:https://pip.pypa.io/en/latest/user_guide

3、requirements帮助:https://pip.pypa.io/en/latest/user_guide/#requirements-files

4、requirements帮助:https://pip.pypa.io/en/latest/reference/requirement-specifiers

5、requirements帮助:https://pip.pypa.io/en/latest/reference/requirements-file-format

6、PyPI:Python Package Index,python官方的软件仓库;


配置默认源:

%APPDATA%\pip\pip.ini

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple


pip升级:

1、py -m pip install --upgrade pip
2、py -m pip --version


pip安装模块:

1、安装模块:py -m pip install requests

2、安装模块:py -m pip install "requests==2.18.4"

3、安装模块:py -m pip install "requests>=2.0.0,<3.0.0"

4、升级模块:py -m pip install --upgrade requests

5、安装多个模块:py -m pip install -r requirements.txt

6、查看本地模块详情(包含依赖):py -m pip show requests

7、显示安装的模块(可使用格式):py -m pip freeze

8、显示安装的模块(仅用于查看):py -m pip list


离线安装模块:

1、py -m pip download requests -i https://pypi.tuna.tsinghua.edu.cn/simple,从清华源下载模块;
2、py -m pip install --no-index --find-links=file:requests requests,安装下载到本地的模块;


二、pipx使用详解

1、代码仓库:https://github.com/pypa/pipx

2、官方文档:https://pipx.pypa.io/stable

3、使用说明:使用虚拟环境安装命令行软件,避免影响正式环境;

4、使用说明:命令行软件的安装目录位于%USERPROFILE%\pipx

5、使用说明:命令行软件启动器位于%USERPROFILE%\.local\bin

6、使用说明:临时运行的软件位于%USERPROFILE%\pipx\.cache

7、安装工具:scoop install pipx

8、安装工具:pip install pipx

9、安装工具:pipx ensurepath


pipx管理命令行软件:

1、安装软件:pipx install httpie

2、升级软件:pipx upgrade httpie
3、卸载软件:pipx uninstall httpie

4、查看安装软件:pipx list --short

5、临时运行软件:pipx run pycowsay moo

6、临时运行软件(参数存在歧义):pipx run -- pycowsay --py

7、临时运行软件(包名和执行文件不一致):pipx run --spec PACKAGE APP


三、pipdeptree使用详解

1、官方文档:https://pipdeptree.readthedocs.io/en/latest

2、命令帮助:https://pipdeptree.readthedocs.io/en/latest/reference/cli.html

3、入门帮助:https://pipdeptree.readthedocs.io/en/latest/tutorial/getting-started.html

4、安装工具:pip install pipdeptree

5、查看依赖:pipdeptree -p pdfplumber

6、查看被哪些组件依赖:pipdeptree -r -p pdfminer.six


四、python安装管理器

1、帮助文档:https://docs.python.org/zh-cn/3/using/windows.html

2、使用说明:用于管理多个版本python,需要用户手动安装python;

3、使用说明:py和pymanager是同一命令,参数与python完全一致;

4、启动python:py -V:2、py -V:3、py -V:X.Y

5、启动python:py -2、py -3、py -X.Y

6、列出运行时:py -0p | --list-paths

7、列出运行时:py -0 | --list


配置默认python(python启动器):

%LOCALAPPDATA%\py.ini
[defaults]
python=3.12


五、python虚拟环境

1、帮助文档:https://docs.python.org/zh-cn/3/library/venv.html

2、帮助文档:https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments

3、虚拟环境安装的软件包与基础环境安装的软件包隔离,防止项目之间相互干扰;

4、虚拟环境包含在一个目录中,一般命令为.venv、venv、.virtualenv;

5、不可以迁入Git,被认为是可以丢弃的,可以简单地从头创建;

6、基础环境:sys.prefix指向基础环境,sys.base_prefix指向基础环境;

7、虚拟环境:sys.prefix指向虚拟环境,sys.base_prefix指向基础环境;

8、include-system-site-packages = true,允许使用基础环境的软件包;


虚拟环境使用:

1、创建环境:python -m venv .venv

2、创建环境:python -m venv --system-site-packages .venv

3、激活环境:.venv\Scripts\activate

4、取消激活:deactivate

发表评论
评论通过审核之后才会显示。