Using a local cache for pip packages[pip使用本地cache安装包]
2015-01-03 17:11
239 查看
I do a lot of development without an internet connection1, so being able to install packages into a virtual environment without a connection to PyPI is pretty useful.
I've got a couple of aliases in my .bashrc which help with this2:
alias pipcache='pip install --download ${HOME}/.pip-packages'
alias pipinstall='pip install --no-index --find-links=file://${HOME}/.pip-packages/'
The first downloads the packages to my local cache, the second installs them from the cache.
Usage is probably fairly obvious:
pipcache Django==1.5 # Put Django-1.5.tar.gz in ~/.pip-packages
pipinstall Django==1.5 # Install ~/.pip-packages/Django-1.5.tar.gz
pipcache -r requirements.txt # Cache all the requirements of a project
pipinstall -r requirements.txt # Install all requirements from the cache
It's perfectly possible to cache multiple versions of the same package3, which is useful for being able to test upgrading to newer releases, whilst still being able to revert to the previously pinned package if you find nothing works.
Since I mostly use a fairly small set of packages, this means I can start up a brand new virtualenv and I'm very likely to have everything I need without going to PyPI. Not having to download large packages makes installs quicker too4.
/////// 修改默认的cache路径
To take advantage of this, I've added the following to my ~/.bash_profile:
export PIP_DOWNLOAD_CACHE=$HOME/.pip_download_cache_dir
I've got a couple of aliases in my .bashrc which help with this2:
alias pipcache='pip install --download ${HOME}/.pip-packages'
alias pipinstall='pip install --no-index --find-links=file://${HOME}/.pip-packages/'
The first downloads the packages to my local cache, the second installs them from the cache.
Usage is probably fairly obvious:
pipcache Django==1.5 # Put Django-1.5.tar.gz in ~/.pip-packages
pipinstall Django==1.5 # Install ~/.pip-packages/Django-1.5.tar.gz
pipcache -r requirements.txt # Cache all the requirements of a project
pipinstall -r requirements.txt # Install all requirements from the cache
It's perfectly possible to cache multiple versions of the same package3, which is useful for being able to test upgrading to newer releases, whilst still being able to revert to the previously pinned package if you find nothing works.
Since I mostly use a fairly small set of packages, this means I can start up a brand new virtualenv and I'm very likely to have everything I need without going to PyPI. Not having to download large packages makes installs quicker too4.
/////// 修改默认的cache路径
To take advantage of this, I've added the following to my ~/.bash_profile:
export PIP_DOWNLOAD_CACHE=$HOME/.pip_download_cache_dir
相关文章推荐
- 使用FOR XML将查询结果以XML格式返回(Using the FOR XML Clause to Return Query Results as XML)
- 使用浏览器测试Web服务时出现提示“The test form is only available for requests from the local machine.”的解决办法
- 软件随想录(local.joelonsoftware.com/wiki)-2000年04月11日 使用介面设计手冊第二章 - User Interface Design for Programmers
- 软件随想录(local.joelonsoftware.com/wiki)-2000年04月26日 使用介面设计手册第六章 - User Interface Design for Programmers
- 软件随想录(local.joelonsoftware.com/wiki)-2000年04月22日 使用介面设计手册第五章 - User Interface Design for Programmers
- USING STATIC IMPORTS FOR CONSTANTS AND METHODS(使用静态导入引用常量与方法)
- UILocalNotification本地通知的使用方法
- centos 6.3 使用 vnc xrdp 远程登陆 不断弹出对话框“ Authentication is required to set the network proxy used for downloading packages ”
- ArcGIS For JavaScript API Show map using layer definitions(使用层定义显示地图)————(十三)
- 软件随想录(local.joelonsoftware.com/wiki)-2000年05月08日 使用介面设计手册第八章 - User Interface Design for Programmers
- Entity Framework 4.1 DbContext使用记之二——如何玩转本地实体? DbSet.Local属性的使用与实现
- Using CAR for Smurf Attack Mitigation,使用承诺速率控制预防smurf攻击
- iphone-使用TextField及关闭键盘(useing TextField for inputs、using the keyboard)
- 软件随想录(local.joelonsoftware.com/wiki)-2000年04月10日 使用介面设计手冊第一章 - User Interface Design for Programmers
- 使用ASIHTTPRequest和ASIDownloadCache实现本地缓存
- Entity Framework 4.1 DbContext使用记之二——如何玩转本地实体? DbSet.Local属性的使用与实现
- Using Local Database for Application
- Using Pythonbrew and Virtualenv(with pip) for creating sandboxed Python development environments.
- 软件随想录(local.joelonsoftware.com/wiki)-2000年04月18日 使用介面设计手冊第四章 - User Interface Design for Programmers
- 软件随想录(local.joelonsoftware.com/wiki)-2000年05月09日 使用介面设计手册第九章 - User Interface Design for Programmers