环球视点!python 镜像环境搭建总结
目录
取最小安装包镜像更新问题取最小安装包
使用python-3.7.3-embed-win32,注意对:python37._pth的修改,修改方法:
# uncomment_pth.py from pathlib import Path def main(path_cur): for p in path_cur.glob("*._pth"): if not (p.suffix == "._pth" and p.stem.startswith("python")): continue print("found: " + str(p)) f_lines = [] with p.open() as f: for line in f.readlines(): if line.startswith("#import site"): line = line.split("#", 2)[1] f_lines.append(line) with p.open("w") as f: f.writelines(f_lines) return True return False if __name__ == "__main__": path_cur = Path(".") main(path_cur)
使用get-pip.py安装pip,并在有网终的情况下安装好环境
【资料图】
::first_install_with_net.bat set old_dir=%cd% cd /d "%~dp0" python uncomment_pth.py python get-pip.py pip install devpi devpi-web cd /d "%old_dir%" pause
使用pip打包好环境,注意打包get-pip.py
::pkg_py_env.bat set req=..\req_pkg_py_env.txt set whs=..\wheels pip freeze >%req% pip wheel -r %req% -w %whs% pip wheel pip -w %whs% pip wheel setuptools -w %whs% pip wheel wheel -w %whs% pip uninstall wheel -y pip uninstall setuptools -y :: pip 不能用pip卸载自己,需要用下列语句 python -m pip uninstall pip -y rd /s /q Lib rd /s /q Scripts pause
压缩清理后的环境,并传入有网络的环境后,解压基础环境
::unpkg_py_env.bat set req=..\req_pkg_py_env.txt set whs=..\wheels set get-pip=%~dp0get-pip.py set uncomment=%~dp0uncomment_pth.py python %uncomment% python %get-pip% --no-index --find-links=%whs% set PATH=%PATHON_HOME%\Scripts pip install -r %req% --no-index --find-links=%whs% pause
编写配置环境变量的脚本
:: py_env.bat @echo off set old_dir=%cd% cd /d "%~dp0" set PATHON_HOME=%cd% set PATH=%PATHON_HOME%\;%PATHON_HOME%\Scripts;%PATH% title Ptython Env:PATHON_HOME=%PATHON_HOME% cd /d "%old_dir%" if "%1" == "" call cmd REM @echo off REM set PYTHONHOME=%cd% REM set PATH=%PYTHONHOME%/Scripts;%PYTHONHOME%;%PATH% REM set PYTHONPATH=%PYTHONHOME%/Lib REM title %PYTHONHOME%\python.exe REM call cmd
安装devpi-server服务,并初始化好环境,这里需要依赖nssm,需要自行下载,注意nssm需要管理员权限
::install_service.bat set svr_name=devpi set svr_dir=d:\devip_server_datas cd /d "%~dp0" ::用于获取权限 nssm call py_env.bat devpi-init --serverdir %svr_dir% devpi-gen-config --serverdir %svr_dir% nssm install %svr_name% "%cd%\Scripts\devpi-server.exe" --serverdir %svr_dir% --host 0.0.0.0 pause nssm start %svr_name% devpi use root/pypi --always-set-cfg=yes pause
如果不需要了,则卸载相关服务
::remove_service.bat net stop devpi nssm remove devpi confirm pause
镜像更新问题
编写基础功能脚本文件, 并放到pythong.exe同级目录
# tasks.py import datetime import io import os from invoke import task from tqdm import tqdm # @task # def package(c): # dir_path = datetime.datetime.now().strftime("%Y_%m_%d-%H_%m_%S-devpi_server_datas") # c.run(f"devpi-export.exe --serverdir D:\\devip_server_datas --include-mirrored-files {dir_path}") # c.run(fr""C:\Program Files\WinRAR\Rar.exe" a {dir_path}.zip {dir_path}") # # print("hello") @task(iterable=["p"]) def down(c, p): from pathlib import Path Path(r"tmp_whl_dirs").mkdir(exist_ok=True) c.run(fr"cd tmp_whl_dirs & pip download {" ".join(p)}") @task def up(c): dir_path = datetime.datetime.now().strftime("%Y_%m_%d-%H_%m_%S-devpi_server_datas") c.run(f"devpi-export.exe --serverdir D:\\devip_server_datas --include-mirrored-files {dir_path}") c.run(fr""C:\Program Files\WinRAR\Rar.exe" a {dir_path}.zip {dir_path}") from ftplib import FTP ftp = FTP("xxx") ftp.login("xxx", "xxxxx") # ftp.cwd("devip_server_datas") with open(dir_path + ".zip", "rb") as f: f.seek(0, io.SEEK_END) file_size = f.tell() f.seek(0, io.SEEK_SET) with tqdm(unit="blocks", unit_scale=True, leave=True, miniters=1, desc="Uploading......", total=file_size) as tqdm_instance: ftp.storbinary(f"STOR {dir_path}.zip", f, 2048, callback=lambda sent: tqdm_instance.update(len(sent))) c.run("net stop devpi") c.run("net start devpi") # ftp.storbinary(f"STOR {dir_path}.zip", f) # print("finished!!") # os.unlink(dir_path)
下载需要的包:
:: down.bat @echo off set old_dir=%cd% cd /d "%~dp0" set PATHON_HOME=%cd% set PATH=%PATHON_HOME%\;%PATHON_HOME%\Scripts;%PATH% title Ptython Env:PATHON_HOME=%PATHON_HOME% :download set /p down_pkgs=请输入需要下载的包名,用空格隔开: inv down -p "%down_pkgs%" goto :download pause
导出需要镜像的包,并上传镜像包到无网络的环境里
:: up_load.bat @echo off set old_dir=%cd% cd /d "%~dp0" set PATHON_HOME=%cd% set PATH=%PATHON_HOME%\;%PATHON_HOME%\Scripts;%PATH% title Ptython Env:PATHON_HOME=%PATHON_HOME% REM set /p down_pkgs=请输入需要下载的包名 用空格隔开 inv up pause
导入镜像
to do...
到此这篇关于python 镜像环境搭建总结的文章就介绍到这了,更多相关python 镜像搭建内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
X 关闭
X 关闭
- 15G资费不大降!三大运营商谁提供的5G网速最快?中国信通院给出答案
- 2联想拯救者Y70发布最新预告:售价2970元起 迄今最便宜的骁龙8+旗舰
- 3亚马逊开始大规模推广掌纹支付技术 顾客可使用“挥手付”结账
- 4现代和起亚上半年出口20万辆新能源汽车同比增长30.6%
- 5如何让居民5分钟使用到各种设施?沙特“线性城市”来了
- 6AMD实现连续8个季度的增长 季度营收首次突破60亿美元利润更是翻倍
- 7转转集团发布2022年二季度手机行情报告:二手市场“飘香”
- 8充电宝100Wh等于多少毫安?铁路旅客禁止、限制携带和托运物品目录
- 9好消息!京东与腾讯续签三年战略合作协议 加强技术创新与供应链服务
- 10名创优品拟通过香港IPO全球发售4100万股 全球发售所得款项有什么用处?