包管理器 ********************************** * pip: https://gitee.com/luzhenxiong/bilibili-package/tree/master/pip * uv: https://docs.astral.sh/uv/ * npm: https://docs.npmjs.com/ * golang: https://go.dev/doc/modules/managing-dependencies .. hint:: uv跟npm的特性非常相似 源管理 =================================== 设置国内镜像源 ---------------------------------- .. tabs:: .. group-tab:: Python .. tabs:: .. tab:: pip .. code-block:: console $ pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple $ pip3 config set install.trusted-host mirrors.aliyun.com 配置文件位置: ``~/.config/pip/pip.conf`` .. tab:: uv 配置用户级别的配置文件 ``~/.config/uv/uv.toml`` 或者系统级别的配置文件 ``/etc/uv/uv.toml`` .. code-block:: toml [[index]] url = "http://mirrors.aliyun.com/pypi/simple/" default = true .. seealso:: 配置文件: https://docs.astral.sh/uv/configuration/files/#configuration-files .. group-tab:: Golang .. code-block:: console $ go env -w GOPROXY=https://goproxy.cn,direct $ ; 或者 $ go env -w GOPROXY=https://goproxy.io,direct .. group-tab:: Npm .. code-block:: console $ npm config set registry https://registry.npmmirror.com 获取源信息 ----------------------------- .. tabs:: .. tab:: Pip .. code-block:: console $ pip3 config get install.trusted-host mirrors.aliyun.com .. tab:: Golang .. code-block:: console $ go env GOPROXY https://goproxy.cn,direct .. tab:: Npm .. code-block:: console $ npm config get registry 项目初始化 ========================================== .. tabs:: .. group-tab:: Python https://docs.astral.sh/uv/guides/projects/#creating-a-new-project .. code-block:: console ; 在项目根目录执行 $ uv init .. group-tab:: Golang https://go.dev/ref/mod#go-mod-init .. code-block:: console $ go mod init example.com/m .. group-tab:: Npm https://docs.npmjs.com/cli/v11/commands/npm-init .. code-block:: console $ npm init 管理依赖包 =================================== * uv: https://docs.astral.sh/uv/guides/projects/#managing-dependencies 安装模块 ------------------------------------------- .. tabs:: .. group-tab:: Python .. tabs:: .. tab:: pip .. code-block:: console $ pip install requests==2.31.0 $ # 安装requirements.txt指定的包 $ pip install -r requirements.txt $ 安装whl文件 $ pip install somewhat.whl .. tab:: uv .. code-block:: console $ uv add requests==2.31.0 $ uv add --dev testcontainers==4.8.2 $ # 安装pyproject.toml指定的包 $ uv sync .. group-tab:: Golang .. code-block:: console $ go get gorm.io/gorm@v1.25.12 .. group-tab:: Npm https://docs.npmjs.com/cli/v11/commands/npm-install .. code-block:: console $ npm install sax $ # 开发环境依赖 $ npm i -D less $ # 全局安装 $ npm install -g nodemon $ # 安装指定版本的包 $ npm i jquery@1.11.2 卸载模块 ------------------------------------------------ .. tabs:: .. group-tab:: Python .. code-block:: console $ pip uninstall requests .. group-tab:: Nodejs .. code-block:: console $ npm remove uniq $ # 全局删除 $ npm r -g nodemon 查看模块 ------------------------------------------------- .. tabs:: .. group-tab:: Python .. code-block:: console $ # 查看已按照的模块及版本 $ pip freeze $ pip list $ # 查看可升级的模块 $ pip list -o