搭建本地pypi源

注意事項(xiàng)

官方文檔

千萬(wàn)不要百度,百度出來(lái)沒(méi)有好東西
看官方文檔,官方文檔
這個(gè)工具只支持python 3.6 以上

安裝虛擬環(huán)境

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

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/ 修改這個(gè)參數(shù)
鏡像源如果有問(wèn)題可以修改為國(guó)內(nèi)的,但是沒(méi)試過(guò),直接用的官方源站,第一次同步都會(huì)耗費(fèi)時(shí)間

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 <mymirrorname>;
        root <path-to-mirror>/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

根據(jù)實(shí)際情況來(lái)填寫(xiě),我的python3.6是編譯的,需要引入lib庫(kù)

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

設(shè)置方法

臨時(shí)使用:

可以在使用pip的時(shí)候,加上參數(shù)-i和鏡像地址(如https://pypi.tuna.tsinghua.edu.cn/simple)

  • 例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas,這樣就會(huì)從清華鏡像安裝pandas庫(kù)。
永久修改,一勞永逸:
  • Linux下,修改 ~/.pip/pip.conf (沒(méi)有就創(chuàng)建一個(gè)文件夾及文件。文件夾要加“.”,表示是隱藏文件夾)
    內(nèi)容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容