Cheatsheet for pkg manager

Cheatsheet for package manager go mod pip apt ubuntu 20.04 pip pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package 升级 pip 到最新的版本 (>=10.0.0) 后进行配置: pip install pip -U pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple 如果您到 pip 默认源的网络连接较差,临时使用本镜像站来升级 pip: pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U apt ubuntu 20.04 # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse # 预发布软件源,不建议启用 # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse go mod GOPROXY=https://goproxy.io,direct ...

July 24, 2020 · 1 min · Peter

pdm

github, A modern Python package manager with PEP 582 support. 仅在__pypackages__/<major.minor>包含必要的依赖和bin文件,没有解释器相关文件 就算python解释器被删除了,但是只要有其他符合pyproject.yoml规定版本的解释器即可,项目目录下的__pypackages__不包含解释器相关的内容,venv则必须重新关联或者重新创建 $ tree -L 3 __pypackages__ __pypackages__ └── 3.10 ├── bin │ ├── django-admin │ └── sqlformat ├── include └── lib ├── Django-4.0.1.dist-info ├── anyio ├── anyio-3.5.0.dist-info ├── asgiref ├── asgiref-3.4.1.dist-info ├── django ... install brew install pdm demo mkdir pdm-demo cd pdm-demo pdm init Creating a pyproject.toml for PDM... Please enter the Python interpreter to use ... 12. /usr/local/Cellar/pdm/1.12.2/libexec/bin/python3.10 (3.10) Please select: [0]: 12 Using Python interpreter: /usr/local/Cellar/pdm/1.12.2/libexec/bin/python3.10 (3.10) Is the project a library that will be uploaded to PyPI? [y/N]: N License(SPDX name) [MIT]: Author name [26huitailang]: Author email [26huitailang@gmail.com]: Python requires('*' to allow any) [>=3.10]: Changes are written to pyproject.toml. PDM 1.12.2 is installed, while 1.12.6 is available. Please run $ brew upgrade pdm to upgrade. Run $ pdm config check_update false to disable the check. init files ...

July 22, 2020 · 2 min · Peter

pip 离线安装

pip 离线安装 打包 注意,要在同平台打包,否则有些包不能正确安装。 在已有的环境中,一般是一个虚拟环境: pip freeze > pip-requirements.txt pip download -d pip-packages -r pip-requirements.txt,将提取的包下载到pip-packages文件夹中 安装 将pip-requirements.txt和pip-packages文件夹,拷贝到目标环境的同目录下 pip install –no-index –find-links=pip-packages -r pip-requirements.txt 参考 断网环境下一键安装 python3 离线安装包及其依赖 下载依赖 pip-download example pip install pip-download pip-download -p win_amd64 -p none-any fabric

July 22, 2020 · 1 min · Peter

pipenv

pipenv pip和virtualenv的组合,使用Pipfile来替换旧的requirements.txt方式。 documentation zhihu 参考 segmentfault 参考 安装 安装到系统常用的python版本下,mac可以使用brew安装 $ pip install pipenv 创建虚拟环境 $ pipenv install --three django 创建一个python3的虚拟环境并安装django,随机生成一个和当前文件夹名有关的虚拟环境。也可以用过--python 3.7指定python版本。 TODO, 不能指定名称吗? 进入虚拟环境 $ pipenv shell 不过就算不进入环境,pipenv install依然可以正确安装包到对应的环境。 新环境依赖 自动识别Pipfile,然后安装。 $ pipenv install 一并安装开发环境的包: $ pipenv install --dev 区别开发环境 在安装包的时候添加一个--dev选项,会分类到开发依赖。 更换源 更换Pipfile中的source-url [[source]] url = "https://mirrors.aliyun.com/pypi/simple" verify_ssl = true name = "pypi" 设置环境变量 PIPENV_PYPI_MIRROR 效果相同。类似指定–pypi-mirror选项: $ pipenv install --pypi-mirror https://mirrors.aliyun.com/pypi/simple 查看安装的包 $ pipenv graph 不仅可以看到安装包,还可以看到依赖关系。 ...

July 22, 2020 · 1 min · Peter

wheel

wheel 提供给系统组的wheel包构建,要求none-any 以oss2包为例 pip download oss2 --platform=any --abi=none --no-deps 查看setup.py中的依赖,分别用上面的命令下载,获得所有的源码包。 打包wheel,universal选项可以打包忽略平台和架构的包;如果包里面含有c extension是不支持universal的,必须是纯python实现 python .\setup.py bdist_wheel --universal 如果遇到打包错误 error: invalid command 'bdist_wheel',可以修改setup.py使用setuptools的setup方法: # from distutils.core import setup from setuptools import setup

July 22, 2020 · 1 min · Peter