搭建私有pip源

简介:

# 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


相关文章
|
Linux Python Windows
5分钟学会本地Pypi源搭建
5分钟学会本地Pypi源搭建
842 0
|
Python Windows Linux
配置国内PIP源方法
python开发者都知道,当我们pip install安装扩展库的时候,经常遇到安装失败(超时)等,有时候是因为国外镜像被屏蔽了,带来不少麻烦, 随着国内python开发的增多,越来越多企业都开放了自己的pip源: #阿里云 http://mirrors.
10592 1
|
3月前
|
TensorFlow 算法框架/工具
Pip命令更换国内源
【8月更文挑战第7天】Pip命令更换国内源。
253 3
|
12月前
pip 更换源 国内源 阿里源
pip 更换源 国内源 阿里源
1460 0
|
6月前
|
Ubuntu 开发工具 Docker
在docker中配置apt工具与python的源均为国内源
在docker中配置apt工具与python的源均为国内源
291 1
|
Java Python Windows
Python pip 源设置成国内源,阿里云源,清华大学源,最方便的方式,都在这里了
Python pip 源设置成国内源,阿里云源,清华大学源,最方便的方式,都在这里了
28453 0
|
Linux Windows Python
超简单更换PIP国内下载源
超简单更换PIP国内下载源
1004 0
|
Ubuntu
更换apt-get源 与 更换pip源
更换apt-get源 与 更换pip源
451 0
|
缓存 Linux
配置网络源仓库
配置网络源仓库
343 0
|
Apache 开发工具 数据安全/隐私保护
Python 搭建私有 PyPI 仓库不完全指南
Python 搭建私有 PyPI 仓库不完全指南
3536 0
下一篇
无影云桌面