注:本文启发来自同事yc的文档支持,qq教导以及思想启发,这里大力感谢。
注:全过程需要:windows管理员启动cmd
1.安装anaconda
参考:https://www.jb51.net/article/137772.htm
这个链接提供了anaconda的安装,和使用国内镜像快速下载anaconda(5~6M/s)
2.搭建自己的pip源
参考:https://www.jianshu.com/p/799b3490ad6d
- 准备 300G 或以上的存储空间
- bandersnatch:下载某个源的所有 package 到本地
- nginx:发布本地 pypi
这个网站提供的是linux的,不过windows也能用,具体如下:
(1)首先下载bandersnatch,因为装好了anaconda,所以可以使用pip直接下载:
pip install bandersnatch
(2) 生成配置文件 /etc/bandersnatch.conf。
bandersnatch mirror
注:这一步会报错,因为windows没有/etc目录,直接在c盘下创建etc文件夹 ,然后再次运行会发现:C:\\etc\\bandersnatch.conf
文件被生成。
(3)根据实际情况,重点修改以下两个配置,directory 指 package 在本地存放的位置,master 指被同步的源。
[mirror]
; The directory where the mirror data will be stored.
directory = /srv/pypi
; The PyPI server which will be mirrored.
; master = https://testpypi.python.org
; scheme for PyPI server MUST be https
master = https://pypi.python.org
我这块需要修改为windows的,且directory目录至少要300G,包太多:
(4)下载所有 package 至本地,我这要在windows下的anconda prompt里面运行:
bandersnatch -c /etc/bandersnatch.conf mirror
$ bandersnatch -c /etc/bandersnatch.conf mirror
2014-01-15 09:49:26,556 INFO: bandersnatch/1.5 (CPython 2.7.6-final0, Linux 3.19.0-37-generic x86_64)
2014-01-15 09:49:26,558 INFO: Setting up mirror directory: /srv/pypi/
2014-01-15 09:49:26,559 INFO: Setting up mirror directory: /srv/pypi/web/simple
2014-01-15 09:49:26,560 INFO: Setting up mirror directory: /srv/pypi/web/packages
2014-01-15 09:49:26,560 INFO: Setting up mirror directory: /srv/pypi/web/local-stats/days
2014-01-15 09:49:26,561 INFO: Generation file missing. Reinitialising status files.
......
更新本地的 pacakge,(我暂时没用到,刚下载完,再去更新,会发现全是文件已存在):
bandersnatch -c /etc/bandersnatch.conf mirror
(5)安装并配置nginx(我的是基于windows,我安装的是下面链接的nginx版本,没用最新的)
参考:https://www.cnblogs.com/qfb620/p/5508468.html
测试nginx可用后,关闭nginx,然后修改配置文件:
D:\nginx\nginx-1.8.1\conf\nginx.conf
备份该文件,然后删除里面的server{........},用如下替换
server {
listen *:80;
server_name localhost;
root F:\\python_package\\web;
autoindex on;
charset utf-8;
}
注:F:\\python_package\\web 是之前bandersnatch下载包之后自动生成的
配置好之后,启动nginx。
(6)配置其他服务器的pip源(基于windows)
我这里用的是同一个局域网的,其他windows电脑。(能ping通我的ip)
来到另一台电脑,安装python后会自带pip,然后做如下操作:
参考:https://www.cnblogs.com/cwp-bg/p/8497075.html
打开查看隐藏文件夹选项后来到:(AppData为隐藏项目)
C:\Users\Administrator\AppData\Roaming
然后看有没有pip文件夹,没有就新建该文件夹,然后在该文件夹下新建pip.ini,输入如下:
[global]
timeout = 6000
index-url = http://我的机器ip/simple
trusted-host = 我的机器ip
(7)测试pip install
用配置好pip源的电脑,管理员运行cmd,输入如下:
pip install pymysql
结果如下:
生效,确实访问了我的ip下的pip源,并且路径一直,可以在我的电脑浏览器输入链接,找到该文件:
输入链接:http://我的机器ip/packages/ed/39/15045ae46f2a123019aa968dfcba0396c161c20f855f11dea6796bcaae95/
发先如下:
(8)下一步,照搬到linux