设为首页 收藏本站
查看: 937|回复: 0

[经验分享] 使用国内镜像源来加速python pypi包的安装

[复制链接]

尚未签到

发表于 2015-11-30 12:34:10 | 显示全部楼层 |阅读模式
  pipy国内镜像目前有:
  
  http://pypi.douban.com/  豆瓣
  http://pypi.hustunique.com/  华中理工大学
  http://pypi.sdutlinux.org/  山东理工大学
  http://pypi.mirrors.ustc.edu.cn/  中国科学技术大学
  
  对于pip这种在线安装的方式来说,很方便,但网络不稳定的话很要命。使用国内镜像相对好一些,
  
  如果想手动指定源,可以在pip后面跟-i 来指定源,比如用豆瓣的源来安装web.py框架:
  pip install web.py -i http://pypi.douban.com/simple
  
  注意后面要有/simple目录!!!
  
  要配制成默认的话,需要创建或修改配置文件(linux的文件在~/.pip/pip.conf,windows在%HOMEPATH%\pip\pip.ini),修改内容为:
  code:
  [global]
  index-url = http://pypi.douban.com/simple
  
  这样在使用pip来安装时,会默认调用该镜像。
  更多配置参数见:http://www.pip-installer.org/en/latest/configuration.html
  
  
  



Configuration



Config file
  pip allows you to set all command line option defaults in a standard ini style config file.
  The names and locations of the configuration files vary slightly across platforms.


  • On Unix and Mac OS X the configuration file is: $HOME/.pip/pip.conf
  • On Windows, the configuration file is: %HOME%\pip\pip.ini
  You can set a custom path location for the config file using the environment variable PIP_CONFIG_FILE.
  The names of the settings are derived from the long command line option, e.g. if you want to use a different package index (--index-url) and set the HTTP timeout (--default-timeout) to 60 seconds your config file would look like this:





[global]
timeout = 60
index-url = http://download.zope.org/ppix

  Each subcommand can be configured optionally in its own section so that every global setting with the same name will be overridden; e.g. decreasing the timeout to 10 seconds when running the freeze(Freezing Requirements) command and using 60 seconds for all other commands is possible with:





[global]
timeout = 60
[freeze]
timeout = 10

  Boolean options like --ignore-installed or --no-dependencies can be set like this:





[install]
ignore-installed = true
no-dependencies = yes

  Appending options like --find-links can be written on multiple lines:





[global]
find-links =
    http://download.example.com
[install]
find-links =
    http://mirror1.example.com
    http://mirror2.example.com




Environment Variables
  pip’s command line options can be set with environment variables using the formatPIP_<UPPER_LONG_NAME> . Dashes (-) have to replaced with underscores (_).
  For example, to set the default timeout:



export PIP_DEFAULT_TIMEOUT=60
  This is the same as passing the option to pip directly:





pip --default-timeout=60 [...]

  To set options that can be set multiple times on the command line, just add spaces in between values. For example:



export PIP_FIND_LINKS="http://mirror1.example.com http://mirror2.example.com"
  is the same as calling:



pip install --find-links=http://mirror1.example.com --find-links=http://mirror2.example.com


Config Precedence
  Command line options have precedence over environment variables, which have precedence over the config file.
  Within the config file, command specific sections have precedence over the global section.
  Examples:


  • --host=foo overrides PIP_HOST=foo
  • PIP_HOST=foo overrides a config file with [global] host = foo
  • A command specific section in the config file [<command>] host = bar overrides the option with same name in the [global] config file section



Command Completion
  pip comes with support for command line completion in bash and zsh.
  To setup for bash:



$ pip completion --bash >> ~/.profile
  To setup for zsh:



$ pip completion --zsh >> ~/.zprofile
  Alternatively, you can use the result of the completion command directly with the eval function of you shell, e.g. by adding the following to your startup file:



eval "`pip completion --bash`"


Next  Previous  
Window 需要修改:
  %PYTHON_HOME%\Lib\site-packages\pip\cmdoptions.py






Java代码   DSC0000.png

  • index_url = OptionMaker(
  •     '-i', '--index-url', '--pypi-url',  
  •     dest='index_url',  
  •     metavar='URL',  
  •     #default='https://pypi.python.org/simple/',  
  •      default='http://mirrors.bistu.edu.cn/pypi/',  
  •     help='Base URL of Python Package Index (default %default).')  
  
  %PYTHON_HOME%\Lib\site-packages\pip\commands\search.py
  






Java代码  

  • class SearchCommand(Command):  
  •     """Search for PyPI packages whose name or summary contains <query>."""  
  •     name = 'search'  
  •     usage = """  
  •       %prog [options] <query>"""  
  •     summary = 'Search PyPI for packages.'  

  •     def __init__(self, *args, **kw):
  •         super(SearchCommand, self).__init__(*args, **kw)  
  •         self.cmd_opts.add_option(
  •             '--index',  
  •             dest='index',  
  •             metavar='URL',  
  •             #default='https://pypi.python.org/pypi',  
  •             default='http://mirrors.bistu.edu.cn/pypi/',  
  •             help='Base URL of Python Package Index (default %default)')  

  •         self.parser.insert_option_group(0, self.cmd_opts)  
  

[Linux]修改easy_install和pip的镜像地址
  使用easy_install和pip会让Pyhthon的模块安装和管理变得非常简单,但是,如果你身在国内的话,从官方的镜像下载的速度是很令人抓狂的事情,如同修改apt-get或yum的镜像地址一样,easy_install和pip也需要修改镜像地址。修改easy_install和pip的镜像地址通常可以有以下两种方法,可以分别使用命令和配置方式实现。
  方法1:命令方式临时修改
easy_install:




1


easy_install -i http://e.pypi.python.org/simple fabric
  pip:




1


pip -i http://e.pypi.python.org/simple install fabric
  
  方法2:配置方式修改
easy_install:
1.打开pydistutils.cfg




1


vi ~/.pydistutils.cfg
  2.写入以下内容




1
2


[easy_install]
index_url = http://e.pypi.python.org/simple
  pip:
1.打开pip.conf




1


vi ~/.pip/pip.conf
  2.写入以下内容




1
2


[global]
index-url = http://e.pypi.python.org/simple
  速度比较快的国内镜像,都来自清华大学,服务器在北京。公网的服务器为官方镜像
公网:http://e.pypi.python.org/simple
教育网:http://pypi.tuna.tsinghua.edu.cn/simple

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-145364-1-1.html 上篇帖子: Python一个有意思的地方:reduce、map、filter 下篇帖子: Python 学习笔记13:Python + wsgi + django 配置。坑爹的python3和wsgi不兼容的解决
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表