Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyInstaller not found #2549

Open
hrauch opened this issue Feb 13, 2024 · 7 comments
Open

PyInstaller not found #2549

hrauch opened this issue Feb 13, 2024 · 7 comments
Labels
help wanted Extra attention is needed

Comments

@hrauch
Copy link

hrauch commented Feb 13, 2024

Description

I installed nicegui, pyinstaller and pywebview in a virtual environment with Python 3.12 and Windows 11.
Trying your example on https://nicegui.io/documentation/section_configuration_deployment I get this error message:
C:\Program Files\Python312\python.exe: No module named PyInstaller
If I change the last line of your build.py script in
subprocess.call(cmd, shell=True)
everything is ok. May be that this modification is only needed with Windows 11.

@falkoschindler
Copy link
Contributor

Thanks for reporting this issue @hrauch!

Can anyone with Windows 11 reproduce the problem? Should we simply add shell=True?

@falkoschindler falkoschindler added the help wanted Extra attention is needed label Feb 19, 2024
@JS-Aibel
Copy link

Not able to reproduce the problem.
Example Configuration & Deployment | NiceGUI OK for Windows 11.
I have nicegui and pyinstaller installed, not pywebview.

@alimate2023
Copy link

alimate2023 commented Mar 22, 2024

If you use a virtual environment, it says that the package is not found. Try installing and packaging pyinstall without a virtual environment.

@gotev
Copy link
Contributor

gotev commented Mar 27, 2024

Been able to reproduce that on Windows 10 running a Python 3.12.2 virtual envronment and to find a working solution. My multiplatform build script looks like this (Linux can be added as well):

from pathlib import Path
import subprocess
import platform
import os
import shutil
import nicegui

APP_NAME = 'Your App Name'

def remove(folder):
    if os.path.exists(folder):
        shutil.rmtree(folder)

def build_windows():
    return [
        'pyinstaller',
        'main.py',  # your main file with ui.run()
        '--name', APP_NAME,  # name of your app
        '--onedir',
        '--windowed',
        '--icon', 'AppIcon.ico'
    ]

def build_macos():
    return [
        'python',
        '-m', 'PyInstaller',
        'main.py',  # your main file with ui.run()
        '--name', APP_NAME,  # name of your app
        '--windowed',
        '--icon', 'AppIcon.icns'
    ]

build_matrix = {
    'Windows': build_windows,
    'Darwin': build_macos
}

common_data_params = [
    '--add-data', f'{Path(nicegui.__file__).parent}{os.pathsep}nicegui',
    # '--add-data', f'assets{os.pathsep}assets' # you can add your own additional resources
]

if __name__ == "__main__":
    platform_name = platform.system()

    if platform_name not in build_matrix:
        print(f'Unsupported platform {platform_name}')
        sys.exit(1)

    remove('build')
    remove('dist')

    subprocess.call(build_matrix[platform_name]() + common_data_params)

@falkoschindler
Copy link
Contributor

Thanks @gotev!
This makes we wonder if we should provide such a versatile build script with the official NiceGUI package. This way we could bundle all gained knowledge from the documentation and discussions and continuously improve the "recipe" until it works for everyone.

@gotev
Copy link
Contributor

gotev commented Mar 28, 2024

@falkoschindler I agree and I volunteer for a PR, just tell me where do we want to have this added. Have to test it on a Linux btw to have a complete script.

@falkoschindler
Copy link
Contributor

@gotev That would be awesome! I think we can start by putting it in the root directory of the repository. Once we have a release candidate, I'd love to make the executable available as an official script in the NiceGUI package. We probably just need to add something like this to pyproject.toml:

[tool.poetry.scripts]
your-command = "your_project_name.your_script:main"

falkoschindler added a commit that referenced this issue Apr 25, 2024
* feat: added build package script

* code review and refactoring

* fix data path

* always print the PyInstaller command

* fix add-data format

* add more description and help text

---------

Co-authored-by: Falko Schindler <falko@zauberzeug.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants