pip

pip <command> [options]

Commands 包括 install、download、uninstall、list 等

options 一般有 -h 、-V 等

前置知识

PyPi 是 Python Package Index 的首字母简写,表示的是 Python 的官方索引

pip install

[options]
-r, --requirement <file> 从给定的需求文件安装

比如:pip install -r requirements.txt ,表示从 requirements.txt 中下载全部包

-e, --editable <path/url> 从本地项目路径或 VCS url 安装项目

比如:pip install -e . ,表示从 set.py 中下载全部包

-U, --upgrade 将所有指定的软件包升级到最新的可用版本

比如:pip install pip -U ,表示升级 pip 到最新的版本

-i, --index-url <url> Python 包索引的基本 URL(默认为 https://pypi.org/simple

比如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package ,表示从清华源镜像下载包

注意:

  1. 当从本地目录下载时,必须要有 set.py
  2. 关于 setup.pyrequirements.txt 区别,参考文章
    个人理解:还是不太懂二者的区别,最好都写上吧~
  3. 关于 setup.pysetup.cfg ,比如 manim 项目中使用到了,参考文章
    个人理解:在 manim 项目中,setup.pysetup.cfgrequirements.txt 分别如下:
# setup.py

import setuptools
setuptools.setup()

# setup.cfg

[metadata]
name = manimgl
version = 1.1.1
author = Grant Sanderson
author_email= grant@3blue1brown.com
description = Animation engine for explanatory math videos
long_description = file: README.md
long_description_content_type = text/markdown; charset=UTF-8
home_page = https://github.com/3b1b/manim
project_urls =
    Bug Tracker = https://github.com/3b1b/manim/issues
    Documentation = https://3b1b.github.io/manim/
    Source Code = https://github.com/3b1b/manim
license = MIT

[options]
packages = find:
include_package_data=True
install_requires = 
    argparse
    colour
    numpy
    Pillow
    scipy
    sympy
    tqdm
    mapbox-earcut
    matplotlib
    moderngl
    moderngl_window
    pydub
    pyyaml
    screeninfo
    pyreadline; sys_platform == 'win32'
    validators
    ipython
    PyOpenGL
    manimpango>=0.2.0,<0.4.0

[options.entry_points]
console_scripts =
    manimgl = manimlib.__main__:main
    manim-render = manimlib.__main__:main

# requirements.txt

argparse
colour
numpy
Pillow
scipy
sympy
tqdm
mapbox-earcut
matplotlib
moderngl
moderngl_window
pydub
pygments
pyyaml
screeninfo
pyreadline; sys_platform == 'win32'
validators
ipython
PyOpenGL
manimpango>=0.2.0,<0.4.0

可以看出 setup.py 就短短两行,这实际上是 SETUP.CFG-ONLY 项目 的方法,可以使具体内容都放在 setup.cfg 中,而 setup.cfg 原本的作用就是对 setup.py 的修订与补充;同时可以看出 requirements.txtsetup.cfg 的 install_requires 一模一样,这就说明 setup.pyrequirements.txt 本质没什么区别,在实际项目中也最好这样写;至于每种文件的格式就自行查询

  1. 下载 Github 上的项目,最好把整个项目 clone 到本地,再执行 pip install -e . ,这样可以有效避免直接 pip 导致所需环境可能没成型
上一篇:vue3新增


下一篇:setup中使用计算属性