Search code examples
pythonwindowstype-conversionpyinstallerexe

How to install pyinstaller (windows)


I want to convert .py files to .exe files so I can execute them on a webpage. However. every method of doing this involves pyinstaller which I do not know how to install. Could someone either explain the procedure to get pyinstaller OR tell me if there are any other methods to convert .py to .exe without using pyinstaller


Solution

  • Installing Pyinstaller
    Installing pyinstaller is pretty simple and straight forward. All you gotta do is pip install pyinstaller or python -m pip install pyinstaller (obviously you have to make sure that your python and pip are in PATH).To check if pyinstaller got installed correctly, simply type pyinstaller in your cmd, if no errors appear, it means, you have pyinstaller installed. If for some reason, pyinstaller installs correctly but still doesn't work, you might want to add it in your PATH. You can consider adding C:\Users\user_name\AppData\Roaming\Python\Python37\Scripts to the Path.

    Using Pyinstaller
    To convert the .py file into a .exe file, you can run the following commands (Make sure you are in the same directory as your python file) -

    pyinstaller file_name.py - Simply converts your python file into an executable. This will create a few folders and files, and when you will run your .exe file, it will open up console and run your script.
    pyinstaller -w file_name.py - By adding a -w, console will no longer appear while running your .exe.
    pyinstaller -F file_name.py - By adding a -F, only one folder will be created, which will be containing your .exe and no other files.
    pyinstaller -i icon.ico filename.py - By adding a -i, you will be able to add a .ico file as your icon.

    And of course you can use flags in combination to achieve even better results.

    [External Links]
    Using pyinstaller - https://pyinstaller.readthedocs.io/en/stable/usage.html#options
    Installing pyinstaller - https://pyinstaller.readthedocs.io/en/stable/installation.html#installing-in-windows
    Working of pyinstaller - https://pyinstaller.readthedocs.io/en/stable/operating-mode.html