# yum -y install python-pip
2. 用pip安装pypiserver
# pip install pypiserver
3. 建立目录
# mkdir /home/pypi/packages
4. 启动服务
# nohup pypi-server -p 8080 /home/pypi/packages &
#备注:确保端口不冲突,8888端口没有被使用。
5. 将一个包下载,装到packages下面,比如下载simplejson 的包
# pip -q install –no-deps -i http://pypi.python.org/simple -d /home/pypi/packages simplejson
如果想把所有的包下载下来,只能一个一个包( http://pypi.python.org/simple 上面的)下载了。
##备注:这一步没有下载成功,只是手工拷贝了一些pypi包到/home/pypi/packages下。如下:
[root@puppetmaster packages]# pwd
/home/pypi/packages
[root@puppetmaster packages]# ls
pymongo-2.6.3.tar.gz tornado-2.4.1.tar.gz
6. 如果要升级的话,下面的命令可以升级目录下的所有包
# pypi-server -U /home/pypi/packages/
7. 为了方便建立索引个,我安装了一个包 pip2pi
# pip install pip2pi
现在可以使用 dir2pi 建立索引了,用
# dir2pi /home/pypi/packages
备注:创建索引,生产simple文件,如下:
[root@puppetmaster packages]# pwd
/home/pypi/packages
[root@puppetmaster packages]# ls
pymongo-2.6.3.tar.gz simple tornado-2.4.1.tar.gz
8. 安装Nginx,可以用来做负载均衡。
# yum -y install nginx
配置文件(pypi源机器是 pypi1.hy01):
server {
listen 80;
server_name pypi.hy01.internal.wandoujia.com;
access_log /home/work/nginx/logs/pypi_wandoujia.access.log main;
error_log /home/work/nginx/logs/pypi_wandoujia.error.log;
location / {
proxy_pass http://pypi1.hy01:8080/;
}
}
|
如果不采用如上方法,则配置一个nginx服务,内容如下:
[root@puppetmaster sites-enabled]# pwd
/usr/local/webserver/nginx/sites-enabled
[root@puppetmaster sites-enabled]# cat pypi.nginx.conf
server {
listen 8888;
server_name 192.168.90.163;
location / {
index index.php;
root /home/pypi/packages;
}
location ~ \.php$ {
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/www-data/www$fastcgi_script_name;
send_timeout 300;
fastcgi_buffers 8 256k;
include /usr/local/webserver/nginx/conf/fastcgi_params;
}
}
[root@puppetmaster sites-enabled]#
9. 最后装包用
# pip install $package_name -i http://pypi.hy01.internal.wandoujia.com/simple/
备注:我的方法是,如下:
[root@kooxoo90-170 sites-enabled]# pip install pymongo -i http://192.168.90.163:8888/simple
/usr/lib/python2.6/site-packages/setuptools-1.4.2-py2.6.egg/pkg_resources.py:979: UserWarning: /root/.python-eggs is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).
Collecting pymongo
The repository located at 192.168.90.163 is not a trusted or secure host and is being ignored. If this repository is available via HTTPS it is recommended to use HTTPS instead, otherwise you may silence this warning and allow it anyways with '--trusted-host 192.168.90.163'.
Could not find a version that satisfies the requirement pymongo (from versions: )
No matching distribution found for pymongo
[root@kooxoo90-170 sites-enabled]#
解决方法:
[root@kooxoo90-170 sites-enabled]# pip install pymongo -i http://192.168.90.163:8888/simple --trusted-host 192.168.90.163
/usr/lib/python2.6/site-packages/setuptools-1.4.2-py2.6.egg/pkg_resources.py:979: UserWarning: /root/.python-eggs is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).
Collecting pymongo
Downloading http://192.168.90.163:8888/packages/pymongo-2.6.3.tar.gz (324kB)
100% |████████████████████████████████| 327kB 21.7MB/s
Building wheels for collected packages: pymongo
Running setup.py bdist_wheel for pymongo
Stored in directory: /root/.cache/pip/wheels/90/18/ee/1ec1dfc8151aab48c3c60917fd81a160a55bcdb269cf95c132
Successfully built pymongo
Installing collected packages: pymongo
Successfully installed pymongo-2.6.3
[root@kooxoo90-170 sites-enabled]# pip freeze | grep pymongo
/usr/lib/python2.6/site-packages/setuptools-1.4.2-py2.6.egg/pkg_resources.py:979: UserWarning: /root/.python-eggs is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).
pymongo==2.6.3
[root@kooxoo90-170 sites-enabled]#
原文url:http://www.nosa.me/2014/11/08/%E6%90%AD%E5%BB%BApypi-%E6%9C%AC%E5%9C%B0%E6%BA%90/
本文转自 Tenderrain 51CTO博客,原文链接:http://blog.51cto.com/tenderrain/1696119