1

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!

I. Wewib
  • 333
  • 1
  • 3
  • 9
  • If it works in Python 3.5, why not just use that? This may be a case of "newer is not necessarily better". – Brandin Feb 12 '17 at 17:33
  • I did try to use it @Brandin, when I set up the environment. But it didn't work for some reason. Using an environment is the same as just using python 3.5 itself. But I'd rather get used to the environment and learn from my mistakes, because virtualenv seems to have many cool uses. – I. Wewib Feb 12 '17 at 17:48
  • The problem may be that the developers of the tools in question (PyInstaller, etc.) never tested with Python 3.6 using Python 3.5 from a virtual environment. You would have to do some debugging of the tools (e.g. why is it not finding the DLL) if you want to fix it yourself. Otherwise you'll probably have to use a known-working and tested configuration. – Brandin Feb 12 '17 at 18:05

4 Answers4

2

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.

Juan T
  • 1,219
  • 1
  • 10
  • 21
  • And I don't get the vkv.min.js file. I only have vkv.js and vkv.mod.js in the ``__javascript__`` folder. Is it the latter one? – I. Wewib Feb 12 '17 at 19:23
  • Yes, console is command prompt. And use vkv.js, it's the same as vkv.min.js but [minificated](https://en.wikipedia.org/wiki/Minification_(programming)). – Juan T Feb 12 '17 at 19:44
  • Thank you very much for the help. It isn't the ideal answer but it is at least something I can work with. – I. Wewib Feb 12 '17 at 19:52
  • There is one weird thing though. In the python file, I had this word in a string: reële (a double dot above the second e). But the html seems like to not comprehend it and gives weird symbols in stead. Do you know how to fix that? – I. Wewib Feb 12 '17 at 19:54
  • I think you'll have to escape that e with diaeresis by manually modifying the .js, and replacing whatever is in its place with `"\u00eb"`, the `\u` escape sequence for that character. – Juan T Feb 12 '17 at 20:09
  • Hey, I tried your method and it worked fine for my laptop. But then I sent the HTML file to my friends who don't have python/JS/... installed and it didn't work on their PC's. Do you know why? And more importantly, how to fix that? – I. Wewib Feb 13 '17 at 15:50
  • Remember that they have to have the html and the `__javascript__` folder (with the .js) in the same directory. – Juan T Feb 13 '17 at 16:20
  • I put the html file in the ``__javascript__`` folder and I zipped it. I sent my friends the zip file. – I. Wewib Feb 13 '17 at 17:30
  • No, Put it in a folder, let's call it `x` and inside of it the html and `__javascript__`. – Juan T Feb 13 '17 at 17:33
  • If you want put the html and the js in the same folder but modify the html file, from ``, to `` – Juan T Feb 13 '17 at 17:38
  • 1
    @I.Wewib Re that string that is not displaying, you need to tell the browser the encoding of the html file, for example put this in the header: . [See W3C docs for more](https://www.w3.org/International/questions/qa-html-encoding-declarations.en). Also, to minify files transcrypt uses a copy of google's 'closure', which will only work if you have JRE installed. – fzzylogic Feb 14 '17 at 12:59
0

Try removing 3.6 and installing 3.5.3 from python.org.

Retry with Pyinstaller.

0

Try using py2exe, it's a python module. Its really simple all you need to do is:

Download and install it http://sourceforge.net/projects/py2exe/files/

Create your setup.py

Run your setup.py

Here's a site that will explain it more in detail http://inventwithpython.com/appendixc.html

Evans Wanjau
  • 29
  • 1
  • 4
0

I am able to use pyinstaller in my Python 3.6 environment. You need to download the zip file for Development Release (unstable) and instead of using pip, run the setup.py file from downloaded pyinstaller code.

Sush
  • 1
  • 2