1

I try to executable project by pyinstaller but has error Failed to execute script pyi_rth_pkges , after run program.

Hello Guys this is project structure: tree /F app-1.0.1

│   LICENSE
│   main.py      # this module to run GUI build by tkinter
│   MANIFEST.in
│   PKG-INFO
│   README.md
│   setup.cfg
│   setup.py      # this is the module to package all application
│
├───app.egg-info
│       dependency_links.txt
│       entry_points.txt
│       PKG-INFO
│       requires.txt
│       SOURCES.txt
│       top_level.txt
│
├───components
│       frame.py 
│       menu.py
│       vie.py
│       __init__.py
│
├───lib
│       functions.py
│       variable.py
│       __init__.py
│
├───pages
│       winAbout.py
│       win_star.py
│       __init__.py
│
├───data
    │   __init__.py
    │
    └───image
            logo.ico
            home.jpg
            __init__.py

This is The setup.py code :

from setuptools import setup , find_packages

setup(
    name="app",
    version="1.0.1",
    description="A Python package to get Auto reports for any Site.",
    author="john",
    author_email="john@gmail.com",
    license="MIT",
    classifiers=[
        "License :: OSI Approved :: MIT License",
        "Programming Language :: Python :: 3",
        "Programming Language :: Python :: 3.7",
    ],
    packages=find_packages(),
    package_data={
        'data': ['image/*.ico', 'image/*.jpg'],
    },
    install_requires= ['Pillow'],
    entry_points={
        'console_scripts': [
            'napp=main:App'
        ]
    }
)

After using code: pyinstaller --onefile -w setup.py I see the message in Shell.

1699 INFO: PyInstaller: 3.6
1699 INFO: Python: 3.8.2
1715 INFO: Platform: Windows-10-10.0.18362-SP0
1715 INFO: wrote C:\Users\JOHN\Desktop\app\setup.spec
1730 INFO: UPX is not available.
1768 INFO: Extending PYTHONPATH with paths
['C:\\Users\\JOHN\\Desktop\\app', 'C:\\Users\\JOHN\\Desktop\\app']
1768 INFO: checking Analysis
1768 INFO: Building Analysis because Analysis-00.toc is non existent
1768 INFO: Initializing module dependency graph...
1784 INFO: Caching module graph hooks...
1815 INFO: Analyzing base_library.zip ...
11684 INFO: Processing pre-find module path hook   distutils
11690 INFO: distutils: retargeting to non-venv dir 'c:\\python\\lib'
24084 INFO: Caching module dependency graph...
24348 INFO: running Analysis Analysis-00.toc
24448 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\python\python.exe
24702 INFO: Analyzing C:\Users\JOHN\Desktop\Amazon\setup.py
25809 INFO: Processing pre-find module path hook   site
25840 INFO: site: retargeting to fake-dir 'c:\\python\\lib\\site-packages\\PyInstaller\\fake-modules'
32617 INFO: Processing pre-safe import module hook   setuptools.extern.six.moves
34642 INFO: Processing module hooks...
34642 INFO: Loading module hook "hook-distutils.py"...
34695 INFO: Loading module hook "hook-encodings.py"...
34858 INFO: Loading module hook "hook-lib2to3.py"...
34958 INFO: Loading module hook "hook-pkg_resources.py"...
36349 INFO: Processing pre-safe import module hook   win32com
36581 INFO: Excluding import '__main__'
36581 INFO:   Removing import of __main__ from module pkg_resources
36581 INFO: Loading module hook "hook-pycparser.py"...
36618 INFO: Loading module hook "hook-pydoc.py"...
36618 INFO: Loading module hook "hook-pythoncom.py"...
37182 INFO: Loading module hook "hook-pywintypes.py"...
37745 INFO: Loading module hook "hook-setuptools.py"...
39108 INFO: Loading module hook "hook-sysconfig.py"...
39126 INFO: Loading module hook "hook-win32com.py"...
c:\python\lib\site-packages\win32com\client\makepy.py:369: SyntaxWarning: "is not" with a literal. Did you mean "!="?
  if path is not '' and not os.path.exists(path):
40488 INFO: Loading module hook "hook-xml.dom.domreg.py"...
40519 INFO: Loading module hook "hook-xml.etree.cElementTree.py"...
40519 INFO: Loading module hook "hook-xml.py"...
40519 INFO: Loading module hook "hook-_tkinter.py"...
41461 INFO: checking Tree
41461 INFO: Building Tree because Tree-00.toc is non existent
41461 INFO: Building Tree Tree-00.toc
41923 INFO: checking Tree
41923 INFO: Building Tree because Tree-01.toc is non existent
41923 INFO: Building Tree Tree-01.toc
42005 INFO: Looking for ctypes DLLs
42121 INFO: Analyzing run-time hooks ...
42121 INFO: Including run-time hook 'pyi_rth__tkinter.py'
42158 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
42205 INFO: Including run-time hook 'pyi_rth_pkgres.py'
42220 INFO: Including run-time hook 'pyi_rth_win32comgenpy.py'
42289 INFO: Looking for dynamic libraries
44434 INFO: Looking for eggs
44434 INFO: Using Python library c:\python\python38.dll
44434 INFO: Found binding redirects:
[]
44465 INFO: Warnings written to C:\Users\JOHN\Desktop\app\build\setup\warn-setup.txt
44614 INFO: Graph cross-reference written to C:\Users\JOHN\Desktop\app\build\setup\xref-setup.html
44773 INFO: checking PYZ
44773 INFO: Building PYZ because PYZ-00.toc is non existent
44773 INFO: Building PYZ (ZlibArchive) C:\Users\JOHN\Desktop\app\build\setup\PYZ-00.pyz
46679 INFO: Building PYZ (ZlibArchive) C:\Users\JOHN\Desktop\app\build\setup\PYZ-00.pyz completed successfully.
46759 INFO: checking PKG
46759 INFO: Building PKG because PKG-00.toc is non existent
46759 INFO: Building PKG (CArchive) PKG-00.pkg
66169 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
66215 INFO: Bootloader c:\python\lib\site-packages\PyInstaller\bootloader\Windows-32bit\runw.exe
66215 INFO: checking EXE
66215 INFO: Building EXE because EXE-00.toc is non existent
66231 INFO: Building EXE from EXE-00.toc
66247 INFO: Appending archive to EXE C:\Users\JOHN\Desktop\app\dist\setup.exe
66331 INFO: Building EXE from EXE-00.toc completed successfully.

I get 'dist' folder has the Setup.exe but after run it from sheel I see this error.

PS C:\Users\JOHN\Desktop\app\dist> Setup.exe
Setup.exe : The term 'Setup.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Setup.exe
+ ~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Setup.exe:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException


Suggestion [3,General]: The command Setup.exe was not found, but does exist in the current location. Windows PowerShell does not load commands from the current location by default. If you trust this command, instead type: ".\Setup.exe". See "get-help about_Command_Precedence" for more details.

And After run from Setup.exe from folder I see this Message error:

enter image description here

john
  • 75
  • 1
  • 8
  • 1
    Compiling a setup.py is pointless. It won't affect your python installation. PyInstaller has its own isolated internal environment which is where it would be installed. And when you're running in one file mode, the package that had been installed would get deleted. You can't edit a onefile executable. – Legorooj May 15 '20 at 08:58
  • Oh I don't know why python has all this problems in executable application but if build it in Microsoft Visual Studio it easy to executable your application. I have this tree of my application build by tkinter and script selenium how can I build executable application?? . if is possible to move this project selenium in Visual Studio and build GUI by it and executable application without any problem? – john May 15 '20 at 11:26
  • you're going about this wrong. Do you want to build a library like something from pypi, or a program, like FileZilla? – Legorooj May 15 '20 at 11:59
  • 1
    I need to build program, like FileZilla.but run and use it without installing – john May 15 '20 at 12:06
  • that's easy. Which is the main python file which you run to run your app? – Legorooj May 15 '20 at 12:07
  • Run main.py module to launch application interface and after click start run script selenium from this module AllTests.py – john May 15 '20 at 12:10
  • Does this answer your question? [Pyinstaller "Failed to execute script pyi\_rth\_pkgres" and missing packages](https://stackoverflow.com/questions/37815371/pyinstaller-failed-to-execute-script-pyi-rth-pkgres-and-missing-packages) – AhmedHaies May 15 '20 at 20:49
  • @john try `pyinstaller main.py -w`. That should work. – Legorooj May 16 '20 at 00:20
  • same problem look in this sample https://github.com/Jtonna/Processes-Killer – john May 16 '20 at 02:47

1 Answers1

-1

you should add this import in your main file code

import pkg_resources.py2_warn

also, you can type this for trying solve problem

pip uninstall pyinstaller

pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip

Community
  • 1
  • 1
AhmedHaies
  • 80
  • 1
  • 10
  • 1
    I add this line in main.py but same problem, I think this way setuptools iby pyinstaller is wrong – john May 16 '20 at 00:13
  • pkg_resources isn't the issue here. (Well it is, but @john is compiling incorrectly) – Legorooj May 16 '20 at 00:19
  • Thanks AhmedHaies all work fine after add import pkg_resources.py2_warn in main.py and remove setup.py – john May 17 '20 at 13:57