python本地镜像源搭建_搭建本地pypi源

注意事项

千万不要百度,百度出来没有好东西

看官方文档,官方文档

这个工具只支持python 3.6 以上

安装虚拟环境

切换到你想要放置的目录再做一下步操作

python3.6 -m venv bandersnatch 或者 virtualenv --python=python3.6 bandersnatch

source bandersnatch/bin/activate

pip3.6 install bandersnatch

Quick start

官方原话

Run bandersnatch mirror - it will create an empty configuration file for you in /etc/bandersnatch.conf].

Review /etc/bandersnatch.conf and adapt to your needs.

Run bandersnatch mirror again. It will populate your mirror with the current status of all PyPI packages. Current mirror package size can be seen here: https://pypi.org/stats/

A blacklist or whitelist can be created to cut down your mirror size. You might want to Analyze PyPI downloads to determine which packages to add to your list.

Run bandersnatch mirror regularly to update your mirror with any intermediate changes.

配置文件唯一需要修改的就是你的包存放目录directory = /data/storage/pypi/ 修改这个参数

镜像源如果有问题可以修改为国内的,但是没试过,直接用的官方源站,第一次同步都会耗费时间

Web Server

Configure your webserver to serve the web/ sub-directory of the mirror. For nginx it should look something like this

server {

listen 127.0.0.1:80;

server_name ;

root /web;

autoindex on;

charset utf-8;

}

Note that it is a good idea to have your webserver publish the HTML index files correctly with UTF-8 as the charset. The index pages will work without it but if humans look at the pages the characters will end up looking funny.

Make sure that the webserver uses UTF-8 to look up unicode path names. nginx gets this right by default - not sure about others.

Cron jobs

根据实际情况来填写,我的python3.6是编译的,需要引入lib库

00 0 * * * bandersnatch mirror >/dev/null 2>&1

设置方法

临时使用:

例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas,这样就会从清华镜像安装pandas库。

永久修改,一劳永逸:

Linux下,修改 ~/.pip/pip.conf (没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹)

内容如下:

[global]

index-url = https://pypi.tuna.tsinghua.edu.cn/simple

[install]

trusted-host = https://pypi.tuna.tsinghua.edu.cn

你可能感兴趣的:(python本地镜像源搭建)