Getting ValueError: script '/src/add2vals.py' not found when using PyInstaller Module

Getting ValueError: script '/src/add2vals.py' not found when using PyInstaller Module

我是 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- 我已经创建了 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/*"
                   }
               }
        }

因此管道构建成功

并且文件完美生成