xxl-job
xxl-job copied to clipboard
想用python脚本安装py的第三方库,出现一些小问题
版本: xxl-job-2.3.1 python 3.5.3 ubuntu14.0.4
问题: 我在平台写了一个py脚本,通过os.system执行一个pip来下载依赖 `
-- coding: UTF-8 --
import time import sys import os
redis_command = "sudo pip install redis" os.system(redis_command) print(redis_command)
exit(0) `
平台返回的结果是
2022-08-03 06:48:01 [com.xxl.job.core.thread.JobThread#run]-[133]-[xxl-job, JobThread-3-1659509248607] ----------- xxl-job job execute start ----------- ----------- Param: 2022-08-03 06:48:01 [com.xxl.job.core.handler.impl.ScriptJobHandler#execute]-[80]-[xxl-job, JobThread-3-1659509248607] ----------- script file:/data01/xxl-job/log/jobhandler/gluesource/3_1659508320000.py ----------- Traceback (most recent call last): File "/usr/local/bin/pip", line 7, in from pip._internal.cli.main import main File "/usr/local/lib/python3.5/dist-packages/pip/_internal/cli/main.py", line 57 sys.stderr.write(f"ERROR: {exc}") ^ SyntaxError: invalid syntax sudo pip install redis 2022-08-03 06:48:01 [com.xxl.job.core.thread.JobThread#run]-[179]-[xxl-job, JobThread-3-1659509248607] ----------- xxl-job job execute end(finish) ----------- ----------- Result: handleCode=200, handleMsg = null 2022-08-03 06:48:01 [com.xxl.job.core.thread.TriggerCallbackThread#callbackLog]-[197]-[xxl-job, executor TriggerCallbackThread] ----------- xxl-job job callback finish.
然后我去查了一下
sys.stderr.write(f"ERROR: {exc}")
这个问题,我在执行器的服务器上运行也有这个问题,在服务器上更新了pip后,服务器上运行脚本没问题
之后在平台上运行还是之前的结果
后来我试着在脚本中解决这个问题,并在平台运行
`
-- coding: UTF-8 --
import time import sys import os import redis
redis_command = "sudo -H pip install redis"
os.system("wget https://bootstrap.pypa.io/pip/3.5/get-pip.py") os.system("python3.5 get-pip.py")
os.system(redis_command) print(redis_command)
exit(0) `
平台返回的是这个 ` 2022-08-03 07:08:34 [com.xxl.job.core.thread.JobThread#run]-[133]-[xxl-job, JobThread-3-1659510514384] ----------- xxl-job job execute start ----------- ----------- Param: 2022-08-03 07:08:34 [com.xxl.job.core.handler.impl.ScriptJobHandler#execute]-[80]-[xxl-job, JobThread-3-1659510514384] ----------- script file:/data01/xxl-job/log/jobhandler/gluesource/3_1659510488000.py ----------- --2022-08-03 07:08:34-- https://bootstrap.pypa.io/pip/3.5/get-pip.py Resolving bootstrap.pypa.io (bootstrap.pypa.io)... 151.101.0.175, 151.101.64.175, 151.101.128.175, ... Connecting to bootstrap.pypa.io (bootstrap.pypa.io)|151.101.0.175|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 1908223 (1.8M) [text/x-python] Saving to: 'get-pip.py'
0K .......... .......... .......... .......... .......... 2% 46.6M 0s
50K .......... .......... .......... .......... .......... 5% 97.5M 0s
100K .......... .......... .......... .......... .......... 8% 132M 0s 150K .......... .......... .......... .......... .......... 10% 104M 0s 200K .......... .......... .......... .......... .......... 13% 110M 0s 250K .......... .......... .......... .......... .......... 16% 102M 0s 300K .......... .......... .......... .......... .......... 18% 138M 0s 350K .......... .......... .......... .......... .......... 21% 134M 0s 400K .......... .......... .......... .......... .......... 24% 150M 0s 450K .......... .......... .......... .......... .......... 26% 203M 0s 500K .......... .......... .......... .......... .......... 29% 200M 0s 550K .......... .......... .......... .......... .......... 32% 167M 0s 600K .......... .......... .......... .......... .......... 34% 216M 0s 650K .......... .......... .......... .......... .......... 37% 176M 0s 700K .......... .......... .......... .......... .......... 40% 93.5M 0s 750K .......... .......... .......... .......... .......... 42% 95.1M 0s 800K .......... .......... .......... .......... .......... 45% 125M 0s 850K .......... .......... .......... .......... .......... 48% 103M 0s 900K .......... .......... .......... .......... .......... 50% 151M 0s 950K .......... .......... .......... .......... .......... 53% 106M 0s 1000K .......... .......... .......... .......... .......... 56% 149M 0s 1050K .......... .......... .......... .......... .......... 59% 104M 0s 1100K .......... .......... .......... .......... .......... 61% 140M 0s 1150K .......... .......... .......... .......... .......... 64% 105M 0s 1200K .......... .......... .......... .......... .......... 67% 117M 0s 1250K .......... .......... .......... .......... .......... 69% 124M 0s 1300K .......... .......... .......... .......... .......... 72% 139M 0s 1350K .......... .......... .......... .......... .......... 75% 136M 0s 1400K .......... .......... .......... .......... .......... 77% 109M 0s 1450K .......... .......... .......... .......... .......... 80% 137M 0s 1500K .......... .......... .......... .......... .......... 83% 129M 0s 1550K .......... .......... .......... .......... .......... 85% 117M 0s 1600K .......... .......... .......... .......... .......... 88% 88.7M 0s 1650K .......... .......... .......... .......... .......... 91% 81.5M 0s 1700K .......... .......... .......... .......... .......... 93% 78.5M 0s 1750K .......... .......... .......... .......... .......... 96% 91.5M 0s 1800K .......... .......... .......... .......... .......... 99% 75.2M 0s 1850K .......... ... 100% 161M=0.02s
2022-08-03 07:08:34 (113 MB/s) - 'get-pip.py' saved [1908223/1908223]
DEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021. pip 21.0 will remove support for this functionality. Collecting pip<21.0 Downloading pip-20.3.4-py2.py3-none-any.whl (1.5 MB) Installing collected packages: pip Attempting uninstall: pip Found existing installation: pip 22.2.1 Uninstalling pip-22.2.1: Successfully uninstalled pip-22.2.1 Successfully installed pip-20.3.4 DEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021. pip 21.0 will remove support for this functionality. Requirement already satisfied: redis in /usr/local/lib/python3.5/dist-packages (3.5.3) sudo -H pip install redis 2022-08-03 07:08:38 [com.xxl.job.core.thread.JobThread#run]-[179]-[xxl-job, JobThread-3-1659510514384] ----------- xxl-job job execute end(finish) ----------- ----------- Result: handleCode=200, handleMsg = null 2022-08-03 07:08:38 [com.xxl.job.core.thread.TriggerCallbackThread#callbackLog]-[197]-[xxl-job, executor TriggerCallbackThread] ----------- xxl-job job callback finish. `
看样子是在平台运行的时候重新更新了pip 这是什么情况