GithubHelp home page GithubHelp logo

dmahugh / python-exe-sample Goto Github PK

View Code? Open in Web Editor NEW
3.0 0.0 1.0 6.04 MB

example of how to create a standalone executable from a Python script, using PyInstaller

License: MIT License

Python 98.64% Batchfile 1.36%

python-exe-sample's Introduction

creating an executable from Python code

This repo provides an example of how to create a single-file Windows executable from a Python app using PyInstaller.

The general approach is largely based on Luke Lee's excellent Real Python article Using PyInstaller to Easily Distribute Python Applications. That article targets Linux platforms, and in this sample I've tweaked a few things to make it work on Windows. Note that PyInstaller doesn't support cross-platform builds, so you need to build the executable on the same platform you're deploying to.

For more information about this sample, see the blog post Building a Python EXE for Windows.

Installation

  • Install Python (version 3.6 or higher).
  • Clone this repo
  • Recommended: create a virtual environment (e.g., python -m venv venv) and activate it.
  • In the root folder of the cloned repo, use the command python -m pip install -r requirements.txt to install dependencies.
  • Install the opcreader package with the command pip install --editable . in the root folder.

Usage

After you've cloned the repo and installed dependencies, you should be able to build an executable by executing the build command in build-windows-exe.bat. Console output is quite verbose, and when it's done running you will have an opcinfo.exe file in the dist subfolder.

To verify that the EXE is working correctly go into the distfolder and try running the executable against one of the test files. For example:

screenshot

For command syntax, see the output of opcinfo -h.

Making changes

Since the opcreader package was installed with the --editable option, you can make changes to the source code and see them reflected immediately. Your changes won't be reflected in the .EXE file until you rebuild it, but you can run cli.py to run the latest version from source code. For example, use python cli.py -h to see the help screen.

Running tests

Use pytest to run the tests, as shown here:

tests

Contributing

This project is a work in progress, and pull requests, feature requests and issues are welcome. Feel free to log an issue if you have a suggestion. Thanks!

License

This project is licensed under the MIT License.

python-exe-sample's People

Stargazers

 avatar  avatar  avatar

Forkers

sugunamenon95

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.