python和pip斷網/隔離/離線批量安裝常用命令

//搜索python項目包
https://pypi.org/project/

//在有網環境準備好get-pip.py, 到pypi網站上搜索並下載wheel, setuptools, pip的wheel文件然後到離線環境通過--find-links安裝pip
wget https://bootstrap.pypa.io/get-pip.py
wget https://files.pythonhosted.org/packages/d8/f3/413bab4ff08e1fc4828dfc59996d721917df8e8583ea85385d51125dceff/pip-19.0.3-py2.py3-none-any.whl
wget https://files.pythonhosted.org/packages/d1/6a/4b2fcefd2ea0868810e92d519dacac1ddc64a2e53ba9e3422c3b62b378a6/setuptools-40.8.0-py2.py3-none-any.whl
wget https://files.pythonhosted.org/packages/96/ba/a4702cbb6a3a485239fbe9525443446203f00771af9ac000fa3ef2788201/wheel-0.33.1-py2.py3-none-any.whl
python get-pip.py --no-index --find-links=./

//build和安裝whl
python setup.py bdist_wheel
pip install dist/xxx.whl

//查看已安裝的包和版本,將txt中所列的包build爲wheel文件並存入wheelhouse目錄
pip freeze > requirements.txt
pip wheel --trusted-host pypi.douban.com -i http://pypi.douban.com/simple -r requirements.txt -w wheelhouse

//下載所列庫到packs目錄,目錄中爲whl和tar.gz格式的文件,此方法不推薦,因爲tar.gz還要經過編譯我whl格式再安裝,依賴gcc,所以推薦用pip wheel的方式直接把所有包全部下載爲wheel格式。
pip download --trusted-host pypi.douban.com -i http://pypi.douban.com/simple -r python-dependencies.txt -d packs/

//以packs目錄中的庫編譯包作爲源安裝txt文件中所列的庫。
pip install --no-index --find-links ./packs -r python-dependencies.txt

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章