由于种种不可抗力原因,我们很难保证在使用Pypi官方源以及国内熟知的清华镜像源一定可以满足Python包的下载需求。
不可否认的是,使用QPT或多或少也需要借助镜像源来保证可以正常下载/使用Python包。
为了避免Pypi源在国内使用时可能存在网络连接超时等问题,QPT在interpreter.py
中内置了https://pypi.tuna.tsinghua.edu.cn/simple
作为默认镜像源并且将超时等待从15s更换为60s。与此同时QPT还提供了全局镜像源设置入口,尽可能保证在不同网络环境下可以有更多镜像源选择空间。
在QPT导入后输入qpt.set_default_pip_source(镜像源地址)
即可进行设置
from qpt.smart_opt import set_default_pip_source
from qpt.executor import CreateExecutableModule
# 设置一个镜像源
set_default_pip_source("https://pypi.tuna.tsinghua.edu.cn/simple")
if __name__ == '__main__':
module = CreateExecutableModule(work_dir="./sample_program",
launcher_py_path="./sample_program/run.py",
save_path="./out")
module.make()
执行上述代码后会输出以下字样
DEBUG: 已设置PIP镜像源为:https://pypi.tuna.tsinghua.edu.cn/simple