Considering panel for a gui: can I package as an exe?

Hi,

Considering learning this framework to develop a gui for my python command line code. My code is computationally intensive. I want to use the gui for setting up problems, and looking at results. Results will be mainly plots and spreadsheet-type views.

Once the gui is developed, while I’m fine with users needing a supported/modern browser to use the gui, I will want to distribute a single .exe (on windows/mac/linux some may not have internet access) with all the dependencies. Can this be done? Is that fully supported? Thanks

Hi, I’d really appreciate any thoughts on the above?
Thanks,

Maybe Using Panel in Pyodide & PyScript — Panel v1.3.8 to use offline.

Thank you for your reply. I’m very new to this - I had wondered if there was something such as pyinstaller that could have produced an .exe file. Is that doable? The link you’ve provided discusses things that are beyond me at the moment so I don’t really understand the content of that page.

I don’t know; my recommendation is to create a simple panel example and try packaging it into an exe!

import panel as pn

pn.extension()

pn.pane.Markdown("Hello world").show()

Once you do, feel free to report back and share the results with the community so everyone can learn :slight_smile:

1 Like

Hi!

I’ve managed to resolve this on Linux. I created a wheel for my Panel App by using the following setup.py:

from setuptools import setup, find_packages

setup(
    name='MyApp',
    ...
    packages=find_packages(),
    install_requires=[
        'numpy>=1.22',
        ...
        ],
    extra_requires={'dev': ['twine>=4.0.2']},
    classifiers=[
        'Programming Language :: Python :: 3',
        ...
    ],
    scripts=['MyApp.sh',
             'myapp.py',
             ],
    python_requires='>=3.12',
)

Note: the key idea is to put MyApp.sh and myapp.py in the scripts section in order to have them available in your $PATH later.

Note that the MyApp.sh is a shell script that will launch the panel app. In my case, it looks like this:

#! /usr/bin/bash

panel serve --show $(dirname $0)/myapp.py

The $(dirname $0) will get the current path from the MyApp.sh script (wich is the same for myapp.py).

Then, I created the wheel file:

python setup.py bdist_wheel sdist

At this point, there will be a wheel file created in the dist directory. Now you can upload it to PyPi or use it for a local installation. To test, I created another environment (make sure to have all the packages dependencies installed) and installed the wheel:

pip install --force-reinstall myapp.whl

Note: I used the --force-reinstall to ensure that the modifications I made elsewhere would take effect upon installation.

With the wheel file installed within an appropriated environment, I could launch MyApp.sh from elsewhere on my computer.

I’m not sure, but this seems more like a makeshift solution than an adequate one for what it is intented for, but it works in my case.

Caveats: in this way, both MyApp.sh and myapp.py will be included in your $PATH, which is not ideal, since we just want MyApp.sh.

1 Like

Check out setup.py entry points too so you can define it as whatever you want.

From chatgpt:

Using entry_points in Python allows you to define entry points in your package so that external scripts or other packages can easily invoke your code. This is commonly used for creating command-line interfaces (CLI) that can be called from anywhere once the package is installed.

Here’s a step-by-step guide on how to use entry_points to call a CLI from anywhere:

  1. Define the CLI function: First, you need to create the function that will serve as your CLI. This function typically parses command-line arguments and performs the desired actions.

    # mypackage/cli.py
    
    import argparse
    
    def main():
        parser = argparse.ArgumentParser(description='Description of your CLI tool')
        # Add arguments and options to the parser
        parser.add_argument('input', help='Input argument')
        args = parser.parse_args()
    
        # Your CLI logic here
        print("Input:", args.input)
    
    if __name__ == '__main__':
        main()
    
  2. Update setup.py: In your setup.py file, define the entry point for your CLI using the console_scripts key.

    # setup.py
    
    from setuptools import setup, find_packages
    
    setup(
        name='mypackage',
        version='0.1',
        packages=find_packages(),
        entry_points={
            'console_scripts': [
                'mycli = mypackage.cli:main'
            ]
        }
    )
    

    In this example, mycli is the name of the command that users will run to invoke your CLI, and mypackage.cli:main specifies the function main within the cli module of the mypackage package.

  3. Install the package: You can now install your package using pip.

    pip install .
    
  4. Run the CLI: Once installed, users can run your CLI from anywhere by typing the command specified in the entry point (mycli in this example) followed by any necessary arguments.

    mycli argument
    

This setup allows users to easily invoke your CLI command from any directory once your package is installed, making it accessible from anywhere in the system.