获取 ValueError:使用 PyInstaller 模块时找不到脚本“/src/add2vals.py”
Posted
技术标签:
【中文标题】获取 ValueError:使用 PyInstaller 模块时找不到脚本“/src/add2vals.py”【英文标题】:Getting ValueError: script '/src/add2vals.py' not found when using PyInstaller Module 【发布时间】:2021-11-05 16:25:34 【问题描述】:我是 Python 项目 的新手,使用 Jenkins 声明式管道
我已尝试按照本教程进行操作: 优酷:https://www.youtube.com/watch?v=kW_bADC2fFM Git 仓库:https://github.com/patebija/simple-python-pyinstaller-app
这个构建和单元测试阶段工作正常,下面是我在打包阶段日志中遇到的错误:
+ docker run --rm -v /var/jenkins_home/workspace/ython_Project_MultiBranch_master/134/sources:/src cdrx/pyinstaller-linux:python3 python3 -m PyInstaller -F add2vals.py
WARNING: Support for the legacy ~/.dockercfg configuration file and file-format is deprecated and will be removed in an upcoming release
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
python3 -m PyInstaller -F add2vals.py
79 INFO: PyInstaller: 3.6
79 INFO: Python: 3.7.5
80 INFO: Platform: Linux-4.19.0-17-amd64-x86_64-with-debian-wheezy-sid
81 INFO: wrote /src/add2vals.spec
85 INFO: UPX is available.
Traceback (most recent call last):
File "/root/.pyenv/versions/3.7.5/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/root/.pyenv/versions/3.7.5/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/root/.pyenv/versions/3.7.5/lib/python3.7/site-packages/PyInstaller/__main__.py", line 121, in <module>
run()
File "/root/.pyenv/versions/3.7.5/lib/python3.7/site-packages/PyInstaller/__main__.py", line 114, in run
run_build(pyi_config, spec_file, **vars(args))
File "/root/.pyenv/versions/3.7.5/lib/python3.7/site-packages/PyInstaller/__main__.py", line 65, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "/root/.pyenv/versions/3.7.5/lib/python3.7/site-packages/PyInstaller/building/build_main.py", line 734, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "/root/.pyenv/versions/3.7.5/lib/python3.7/site-packages/PyInstaller/building/build_main.py", line 681, in build
exec(code, spec_namespace)
File "/src/add2vals.spec", line 17, in <module>
noarchive=False)
File "/root/.pyenv/versions/3.7.5/lib/python3.7/site-packages/PyInstaller/building/build_main.py", line 191, in __init__
raise ValueError("script '%s' not found" % script)
ValueError: script '/src/add2vals.py' not found
script returned exit code 1
以下是我用过的Jenkinfile:
pipeline
agent none
stages
stage('Build')
agent
docker
image 'python:3-alpine'
steps
sh 'python -m py_compile sources/*.py'
stash(name: 'compiled-results', includes: 'sources/*.py*')
stage('Unit Test')
agent
docker
image 'qnib/pytest:latest'
steps
sh 'py.test --verbose --junit-xml test-reports/results.xml tests/*.py'
post
always
junit 'test-reports/results.xml'
stage('Packaging')
agent any
environment
//VOLUME = '$(pwd)/sources:/src '
VOLUME = '$PWD/sources:/src'
IMAGE = 'cdrx/pyinstaller-linux:python3'
steps
dir(path: env.BUILD_ID)
unstash(name: 'compiled-results')
//sh "docker run --rm -v $VOLUME $IMAGE 'pyinstaller -F add2vals.py'"
//used PyInstaller as a module
sh "docker run --rm -v $VOLUME $IMAGE 'python3 -m PyInstaller -F add2vals.py'"
post
success
//This archiveArtifacts step archives the standalone executable file and exposes this file
//through the Jenkins interface.
archiveArtifacts "$env.BUILD_ID/sources/dist/add2vals"
sh "docker run --rm -v $VOLUME $IMAGE 'rm -rf build dist'"
我尝试将资源和测试文件分成两个包 项目结构:
如果你能帮助我解决这个问题会有所帮助吗? PS:我使用的是 ubuntu 20.04
【问题讨论】:
【参考方案1】:请找到我的解决方法来解决包装问题:
1- 我已经创建了 setup.py 文件
from distutils.core import setup
from setuptools import find_packages
setup(
name='PythonProject',
version='0.2dev',
description='packaging for my first python app',
packages=find_packages(),
author='mohtadi.nasri',
url='https://github.com/*/Python-project',
platforms='Ubuntu'
)
2- 如下所示更改了打包阶段
stage('Packaging')
agent any
environment
//VOLUME = '$(pwd)/sources:/src'
VOLUME = '$PWD/sources:/src'
IMAGE = 'cdrx/pyinstaller-linux:python3'
steps
dir(path: env.BUILD_ID)
unstash(name: 'compiled-results')
//https://docs.python.org/3/distutils/builtdist.html
sh 'python3 setup.py bdist_dumb --format=zip'
post
success
archiveArtifacts "$env.BUILD_ID/dist/*"
因此管道构建成功
并且文件已完美生成
【讨论】:
以上是关于获取 ValueError:使用 PyInstaller 模块时找不到脚本“/src/add2vals.py”的主要内容,如果未能解决你的问题,请参考以下文章
获取 ValueError:使用 PyInstaller 模块时找不到脚本“/src/add2vals.py”
继续获取 ValueError: invalid literal for int() with base 10: '1, 7'
python/Pyqt5 - 如何在使用 ast 和获取 ValueError 时避免 eval:attemt 中的格式错误的字符串以提高代码安全性
检查 IP 地址是不是真实 - 获取 ValueError: invalid literal for int() with base 10: '192.168.0.105'