如何安装pypi 安装mirror

搭建PyPI及RubyGems镜像 - 推酷
搭建PyPI及RubyGems镜像
推荐使用bandersnatch搭建,bandersnatch是基于PEP381的一个分支,更推荐前者。
的安装配置看官方文档就可以搞定了,这里大概说下基本步骤:
1. 通过pip和easy_install安装bandersnatch,或者下载源码。
2. 你需要一个nginx,lighttpd,或apache之类的webserver,推荐前二者选其一。配置好webserver。
3. bandersnatch.conf位于/etc/下,按需修改该配置文件,对应条目都有说明,简单翻译如下:
; 同步内容存储的目录位置.
directory = /home/mirror/pypi
; 将同步的上有PyPI服务器,第一次同步可以选择清华,中科大,中大,豆瓣等国内服务器.
; 后期的同步再修改为官方服务器。
;master = https://testpypi.python.org
;master = http://pypi.mirrors.
master = https://pypi.python.org
;The network socket timeout to use for all connections. This is set to a
; somewhat aggressively low value: rather fail quickly temporarily and re-run
; the client soon instead of having a process hang infinitely and have TCP not
; catching up for ages.
timeout = 10
; 并行下载的线程数量.
; 建议的线程设置:
; - 保持默认设置3,以防止上游服务器过载
; - 数据中心的官方服务器可以设置为20
; - 50以上的设置可能不稳定,并会被bandersnatch禁止
workers = 3
;快速同步中遇到错误是否停止同步,如果是,将导致同步失败。
;第一次同步时候建议设置为 false,后续可更改为true。
; 值: &true& or &false&.
stop-on-error = false
;本地服务器是否删除上游服务器已经删除的包。
; 重要: 如果你的服务器是作为一个官方镜像提供给用户,请打开该选项。
delete-packages = true
[statistics]
; A glob pattern matching all access log files that should be processed to
; generate daily access statistics that will be aggregated on the master PyPI.
access-log-pattern = /var/log/nginx/*.pypi.python.org*access*
; vim: set ft=cfg:
4.设置cron任务,自动定时执行同步命令,将任务文件放在/etc/cron.d文件下时,注意命名规则。
LC_ALL=en_US.utf8
*/2 * * * * root bandersnatch mirror |& logger -t bandersnatch[mirror]
12 * * * * root bandersnatch update-stats |& logger -t bandersnatch[update-stats]
5.关于bandersnatch更多配置请参考官方文档,另外可以配置exim4和编写脚本分析日记文件进行监控和报警。
RubyGems的搭建,可参考
,按照huacnlee的步骤搭建即可,补充几点:
1. 据说RubyGems会根据中国用户的ip将请求
到日本的镜像站,这个很不错,但是我自己试用了几次都卡住不会跳,囧。日本的服务器地址是:http://tokyo-m.rubygems.org ,我曾经也将这个作为镜像站的上游进行同步,但是日本这个服务器不稳定,所以选择只能是与
或者将镜像服务器上FQ(proxychains,vpn等工具)。
2. 除了使用上面的同步工具搭建镜像站,也可
3. 初始同步可设置上游为淘宝,清华,中大等等。
4. 如果你是搭建一个公共的镜像站提供服务,不建议使用Geminabox 中WEBrick作为webserver,换用nginx或者lighttpd吧。
5. 将同步命令放入/etc/cron.d时除了要注意文件命名方式还可能遇到“rake aborted!”,这表明没设置PATH,参考如下(请按你的PATH进行配置):
PATH=...#查看PATH的命令:echo $PATH
#解释:10分钟一次,配置flock锁,执行rubygems中的同步,日记格式输出,邮件报警命令等。
*/10 * * * * flock -xn /var/lock/mirror/rubygems.lock -c & bash /root/scripts/bin/rubygems &
6: 注意需要配置同步锁。可用上例代码中的flock,也可以自己touch一个lock。
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致使用国内镜像源来加速python pypi包的安装 - 帅胡 - 博客园
pipy国内镜像目前有:
/ &华中理工大学
http://pypi.sdutlinux.org/ &山东理工大学
http://pypi.mirrors./ &中国科学技术大学
对于pip这种在线安装的方式来说,很方便,但网络不稳定的话很要命。使用国内镜像相对好一些,
如果想手动指定源,可以在pip后面跟-i 来指定源,比如用豆瓣的源来安装web.py框架:
pip install web.py -i /simple
注意后面要有/simple目录!!!
要配制成默认的话,需要创建或修改配置文件(linux的文件在~/.pip/pip.conf,windows在%HOMEPATH%\pip\pip.ini),修改内容为:
index-url = /simple
这样在使用pip来安装时,会默认调用该镜像。
更多配置参数见:
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:
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 nam e.g. decreasing the&timeout&to&10&seconds when running the&freeze() command and using&60&seconds for all other commands is possible with:
timeout = 60
timeout = 10
Boolean options like&--ignore-installed&or&--no-dependencies&can be set like this:
ignore-installed = true
no-dependencies = yes
Appending options like&--find-links&can be written on multiple lines:
find-links =
find-links =
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=" "
is the same as calling:
pip install --find-links= --find-links=
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.
--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`"
Window 需要修改:
%PYTHON_HOME%\Lib\site-packages\pip\cmdoptions.py
Java代码&&
index_url&=&OptionMaker(&&
&&&&'-i',&'--index-url',&'--pypi-url',&&
&&&&dest='index_url',&&
&&&&metavar='URL',&&
&&&&#default='https://pypi.python.org/simple/',&&
&&&&&default='http://mirrors./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./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:
easy_install -i http://e.pypi.python.org/simple fabric
pip -i http://e.pypi.python.org/simple install fabric
方法2:配置方式修改easy_install:1.打开pydistutils.cfg
vi ~/.pydistutils.cfg
2.写入以下内容
[easy_install]
index_url = http://e.pypi.python.org/simple
pip:1.打开pip.conf
vi ~/.pip/pip.conf
2.写入以下内容
index-url = http://e.pypi.python.org/simple
速度比较快的国内镜像,都来自清华大学,服务器在北京。公网的服务器为官方镜像公网:http://e.pypi.python.org/simple教育网:http://pypi.tuna./simple
随笔 - 502rfyiamcool 的BLOG
用户名:rfyiamcool
文章数:423
评论数:2193
访问量:1283807
注册日期:
阅读量:5863
阅读量:12276
阅读量:347046
阅读量:1046851
51CTO推荐博文
前言:大家用pip安装模块有没有遇见过这样的情况:对的,这就是抽风的timeout昨天看到一个朋友慢腾腾给所有节点搞tornado,他的源是官方的源,官方的源时不时的会抽风,会慢的。所以我推荐他用国内的源,或者是连接我们自己搭建的源。由此我就跟大家扯一下如何构建快速的python 模块的环境 ~其实国内很多大公司都有自己的pypi源的,只是好多都私有环境的下面都是国内速度比较快的节点指定pypi源的方法:pip install tornado -i http://pypi.sdutlinux.org/simple也可以是全局的模式在unix和macos,配置文件为:$HOME/.pip/pip.conf在windows上,配置文件为:%HOME%\pip\pip.ini需要在配置文件内加上:[global]
index-url=http://mirrors.tuna./pypi/simple以前我都是用豆瓣的源,现在豆瓣的源貌似有问题啦。。。哎,可惜啦提示:Downloading/unpacking tornado
Getting page /simple/tornado/
Could not fetch URL /simple/tornado/: &urlopen error [Errno -2] Name or service not known&
Will skip URL /simple/tornado/ when looking for download links for tornado
Getting page /simple/
Could not fetch URL /simple/: &urlopen error [Errno -2] Name or service not known&
Will skip URL /simple/ when looking for download links for tornado
Cannot fetch index base URL /simple/
URLs to search for versions for tornado:
* /simple/tornado/
Getting page /simple/tornado/
Could not fetch URL /simple/tornado/: &urlopen error [Errno -2] Name or service not known&
Will skip URL /simple/tornado/ when looking for download links for tornado
Could not find any downloads that satisfy the requirement tornado想用更多的源,到这里看看 可以看到好多的节点的运行情况和速度。我们的监控系统是python开发的,客户端当然也是python,时常需要大量的部署,最开始我们用的是反向代理做缓存,效果还是很不错的。我们在用puppet批量部署监控客户端的时候,会让pip指定我们已经反向缓存的pypi的地址、版本库 &比如: pip install -i 意思就是从清华那里搞到包。我想大家都应该熟悉缓存代理吧,大家自己加个location指定proxy_pass就行啦~一个例子:(我这里就不详细说明意思了,大家可以看看我写过的nginx反向代理的文章。。。)installulimit -SHn 65535
yum install pcre pcre-devel -y 安装pcre
wget /files/ngx_cache_purge-1.4.tar.gz
tar zxvf ngx_cache_purge-1.4.tar.gz
wget http://nginx.org/download/nginx-1.0.11.tar.gz
tar zxvf nginx-1.0.11.tar.gz
cd nginx-1.0.11/
./configure --user=www --group=www --add-module=../ngx_cache_purge-1.4 --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
cd ../关键配置proxy_cache_path
/var/lib/nginx/cache/ levels=1:1:2 inactive=24000h keys_zone=cache:100m;
access_log
/var/log/nginx/localhost.access.
#中间省略部分默认配置
location /guanfang {
proxy_pass http://pypi.python.org/
proxy_cache_valid
any 2400h;
location /douban {
proxy_pass /
proxy_cache_valid
any 24000h;
proxy_set_header Host $
proxy_cache cache_
proxy_cache_valid 200 302 1h;
proxy_cache_valid 301 1d;
expires 30d;
location /taiwan {
proxy_pass http://mirrors.tuna./pypi/
proxy_cache_valid
any 24000h;
proxy_set_header Host $
proxy_cache cache_
proxy_cache_valid 200 302 1h;
proxy_cache_valid 301 1d;
expires 30d;
location /jiaoyu {
proxy_pass http://mirrors.tuna./pypi/
proxy_cache_valid
any 24000h;
proxy_set_header Host $
proxy_cache cache_
proxy_cache_valid 200 302 1h;
proxy_cache_valid 301 1d;
expires 30d;
}我们讲了用国内国外的pypi节点来快速部署你的环境,来说下,我们线上的部署方法:个人觉得这个适用于需要大批量部署,又有模块定制,而有些节点不能联外网情况下适用。要是大家的环境不大,推荐用 -i 的方式。 毕竟搭建私有pypi服务是很折腾的事~ 安装pypimirrorpip install z3c.pypimirror要是安装不上的话,可以用官方的方式:$ git clone /macagua/macagua.buildout.pypimirror.git
$ virtualenv .
$ source ./bin/activate
$ python bootstrap.py
$ ./bin/buildout -vvvN
$ deactivate安装完毕就要填写配置文件,需要填写的参数主要有:mirror_file_path 下载的包的存放路径base_url 服务器地址,这个注意要和Apache上的一致!create_indexes 布尔类型,用来在下载的每个包目录下创建索引package_matches 这个是用户自定义的,PyPI包无数,使用正则表达式有选择地下载,要不然硬盘要爆了lock_file_name 设置运行时锁状态文件存放位置log_filename 设置日志文件存放位置生成配置索引pypimirror -c -v -I pypimirror.cfg这里很慢的,就算你用国内的源,也会让你气的抽风,骂的吐血~我是在公司线上机房做的测试,居然还是同步出问题,想看看抽风不?也可以修改配置文件DEFAULT]
# the root folder of all mirrored packages.
# if necessary it will be created for you
mirror_file_path = /home/pypimirror/paquetes
# where's your mirror on the net?
base_url = http://pypi.python.jp/
# lock file to avoid duplicate runs of the mirror script
lock_file_name = /home/pypimirror/pypi-poll-access.lock
# Pattern for package files, only those matching will be mirrored
filename_matches =
# Patte only packages having matching names will
# be mirrored
package_matches =
Products.*
collective.*
# remove packages not on pypi (or externals) anymore
cleanup = True
# create index.html files
create_indexes = True
# be more verbose
verbose = True
# resolve download_url links on pypi which point to files and download
# the files from there (if they match filename_matches).
# The filename and filesize (from the download header) are used
# to find out if the file is already on the mirror. Not all servers
# support the content-length header, so be prepared to download
# a lot of data on each mirror update.
# This is highly experimental and shouldn't be used right now.
# NOTE: This option should only be set to True if package_matches is not
# set to '*' - otherwise you will mirror a huge amount of data. BE CAREFUL
# using this option!!!
external_links = False
# similar to 'external_links' but also follows an index page if no
# download links are available on the referenced download_url page
# of a given package.
# NOTE: This option should only be set to True if package_matches is not
# set to '*' - otherwise you will mirror a huge amount of data. BE CAREFUL
# using this option!!!
follow_external_index_pages = False
log_filename = /home/pypimirror/pypimirror.log更新pypimirror -c -v -i -U pypimirror.cfg参数说明:-i 创建索引-U 更新镜像。假设前面设置的下载文件存放路径为/data/pypi/files,下面把它链接到/var/www/目录下:ln -s /data/pypi/files /var/www/pypi重启Apache,访问http://xiaorui.cc/pypi/ 应该就可以了。这是最简单的配置,这时的base_url就是 http://xiaorui.cc/pypi/ 。让他定期更新下安装pypimirror遇到的问题:Traceback (most recent call last):
File "/usr/local/lib/python2.6/dist-packages/bottle.py", line 764, in _handle
return route.call(**args)
File "/usr/local/lib/python2.6/dist-packages/bottle.py", line 1575, in wrapper
rv = callback(*a, **ka)
File "hydenMain.py", line 39, in static
return static_file(filename, root='{}/static'.format('.'))ValueError: zero length field name in format大家把python升级到2.7就行了需要说明的是,本地的pypi安装的时候,会出现各种各样的问题,请大家都尝试和搜下问题所在。 我们可以把问题都统计下来,好让也遇到这样的问题的人,能更好的定位和解决问题。本文出自 “” 博客,谢绝转载!
了这篇文章
类别:┆阅读(0)┆评论(0)
13:50:53 15:00:27 02:49:00 03:08:37 23:53:31 00:21:18 13:58:41 18:25:05 00:33:05 09:55:03 22:16:27 22:52:09 23:12:48 02:54:41pip更换软件镜像源 - python_road - 博客园
随笔 - 11, 文章 - 0, 评论 - 0, 引用 - 0
家里的网络访问某些国外网站、下载安装包的时候总是连接不上或者下载速度特别慢, pypi.python.org就是其中一个。所以,使用pip给Python安装软件时,经常出现错误。修改pip连接的软件库可以解决这个问题。
是豆瓣提供一个镜像源,软件够新,连接速度也很好。
pip install pythonModuleName -i /simple
比如我在用pip安装virtualenv的时候,下载速度一直是几k
sudo pip install virtualenv -i /simple
之后下载速度提到了9MB/s}

我要回帖

更多关于 mate8 安装mirrorlink 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信