PIP本地源搭建
Wheel包制作
# pip install wheel
# mkdir ~/wheels
# cd < Project >
# pip wheel --wheel-dir=~/wheels .
# cd ~/
# tar acf wheels.tar.gz wheels
### 使用本地包进行安装
# tar axf wheels.tar.gz wheels
# cd wheels
# pip install --use-wheel --no-index --find-links=./ < Package >
Ubuntu
- 下载pip2pi
# apt install python-pip
# pip install --upgrade pip
# pip install pip2pi
- 搭建apache2服务
# apt install apache2
# mkdir -p /var/www/packages
# sed -i -e "s/ServerAdmin.*/ServerAdmin pypi.com/g" /etc/apache2/sites-available/000-default.conf
# sed -i -e "s/DocumentRoot.*/DocumentRoot \/var\/www\/packages/g" /etc/apache2/sites-available/000-default.conf
# a2ensite 000-default
# systemctl restart apache2
- 批量下载软件包
### 生成tar.gz或whl包
# cd Downloads/
# wget http://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt?h=stable/newton -O requirements.txt
### -r参数用来表示要安装的软件包,-c参数用来限制要安装的软件包的版本
# pip2tgz /var/www/packages -r requirements.txt
### 只生成whl包
# pip wheel --timeout 120 --wheel-dir /var/www/packages --find-links /var/www/packages --build /tmp/openstack-builder --log /var/log/repo/repo_builder.log --requirement requirements.txt
- 建立索引
# dir2pi /var/www/packages
- 单独下载软件包并更新索引
# pip2tgz /var/www/packages zake===0.2.2
# dir2pi /var/www/packages
- 测试pip源
### 访问http://192.168.30.142/simple/index.html
# curl -I http://192.168.30.142/simple/zake/zake-0.2.2-py2.py3-none-any.whl | head -n1
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 19139 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
HTTP/1.1 200 OK
问题处理
- MySQL-python安装报错
Saved /var/www/pypi/MySQL-python-1.2.5.zip
Complete output from command python setup.py egg_info:
sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-5pxlt9/MySQL-python/setup.py", line 17, in <module>
metadata, options = get_config()
File "/tmp/pip-build-5pxlt9/MySQL-python/setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "/tmp/pip-build-5pxlt9/MySQL-python/setup_posix.py", line 25, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
解决办法
# apt install libmysqld-dev
- Psycopg2安装报错
Saved /var/www/pypi/psycopg2-2.6.2.tar.gz
Complete output from command python setup.py egg_info:
running egg_info
creating pip-egg-info/psycopg2.egg-info
writing pip-egg-info/psycopg2.egg-info/PKG-INFO
writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt
writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt
writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'
warning: manifest_maker: standard file '-c' not found
Error: pg_config executable not found.
解决办法
# apt install libpq-dev
- Xattr安装报错
Collecting xattr===0.8.0 (from -r requirements.txt (line 397))
Downloading xattr-0.8.0.tar.gz
Saved /var/www/pypi/xattr-0.8.0.tar.gz
Complete output from command python setup.py egg_info:
c/_cffi_backend.c:15:17: fatal error: ffi.h: No such file or directory
解决办法
# apt install libffi-dev
CentOS
- 下载pip2pi
# yum install python-pip
# pip install --upgrade pip
# pip install pip2pi
- 搭建apache服务
# apt install httpd
# mkdir -p /var/www/packages
# vim /etc/httpd/conf.d/vhost.conf
Listen 81
<VirtualHost *:81>
DocumentRoot "/var/www/packages/simple"
ServerName pypi.com
Errorlog /var/log/httpd/pypi.error.log
CustomLog /var/log/httpd/pypi.access.log common
</VirtualHost>
# systemctl restart httpd
- 批量下载软件包
# wget http://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt?h=stable/newton -O requirements.txt
# yum install mysql-devel libffi-devel libpqxx-devel
# pip wheel --timeout 120 --wheel-dir /var/www/packages --find-links /var/www/packages --build /tmp/openstack-builder --log /var/log/repo/repo_builder.log --requirement requirements.txt
- 建立索引
# dir2pi /var/www/packages
- 测试pip源
### 访问http://192.168.30.142:81