Search code examples
pythonwindowspython-3.xvirtualenvpyinstaller

How to let others run your Python program without installing Python


I made my second program in Python. It's a program that calculates the roots of a quadratic equation. I think it's cool and I want to let my friends use it without having to let them install python.

I heard about Pyinstaller from a friend and I tried this method out: first I typed pip install pyinstaller in cmd. Then I changed directory to the folder that contains the file that I want to share with my friends (it's called vkv.py). Then I entered this command: pyinstaller vkv.py but I got this error: Indexerror: tuple index out of range. Apparently the problem was that I have Python 3.6.0 and Pyinstaller only works with versions up to Python 3.5.

So I had to try another method. Yesterday, I tried cx_Freeze and some other method that I forgot, but both of them failed. Cx_Freeze failed due to me having Python 3.6.0 (same as Pyinstaller) and I don't remember what went wrong with the other method.

My friend (who told me about Pyinstaller) told me to use virtualenv, so I looked up a tutorial on the matter. Looks like I needed to make a virtual environment where I use Python 3.5. So these are the commands that I typed in cmd:

  1. pip install virtualenv
  2. mkdir Environments
  3. cd environments
  4. virtualenv -p C:\Users\hp\AppData\Local\Programs\Python\Python35\python.exe py35_env
  5. (before entering this command, I installed Python 3.5.0)
  6. C:\Users\hp\Environments\py35_env\Scripts\activate
Now that the environment has been made and activated, I installed Pyinstaller in this environment, with pip install pyinstaller. Then I changed directory to: C:\Users\hp\Desktop\Code\Python testing (which is where the vkv.py file is located at). Then I typed: pyinstaller vkv.py, but now I got a whole bunch of lines, with an error on the last line: ImportError: DLL load failed: %1 is not a valid Win32 application.. Here is a screenshot of it: ImportError

Being the curious person that I am, I wanted to know what would happen if I opened another cmd window and tried Pyinstaller again without the environment (so I basically tried the very first method again, listed above). It is strange that I got the same "ImportError" and not the "IndexError" from before.

So now my questions are (ranked from more important to less important):

  1. what can I do to let my friends run the Python file without having to install Python?
  2. What does this ImportError mean and how can I fix it?
  3. What happened there with the last time that I tried pyinstaller vkv.py in cmd outside of the environment? Why did it give me an ImportError and not the IndexError, which is what I got when I first tried to run this command?

Sorry to make this a long post, but I like to give a lot of information because I'm afraid that I might leave something important out.

Thanks in advance for any kind of help!


Solution

  • As you want to use Python 3.6, you can't use Pyinstaller, py2exe, cx_Freeze or others. However, there is a tool called Transcrypt and it's compatible with Python 3.6. It can be installed with pip: pip install transcrypt, and converts Python code into JavaScript. To use it open the console and type transcrypt vkv.py.

    It automatically generates a folder, __javascript__, and files on it. When transcript ends, you are ready to use it with html.

    (Assuming the .html is in the same directory as the .py and the folder)

    <html>
    <head>
        <title>Example</title>
    </head>
    <body>
        <script src="./__javascript__/vkv.min.js"></script>
    </body>
    </html>
    

    You can use the html as an executable (depending on your program, here is the documentation) by running it with your browser.