cx-freeze can't create .exe file - python-3.x

I have wrote a simple Python script for searching files & finding the duplicates as I am currently learning Python. Nothing complicated at all. This is also my first try of using cx-freeze to build an Windows executable. I'm using Python 3.3.
I'm using the included cxfreeze script to create .exe file. So, I've typed cxfreeze search.py --target-dir dist . Everything goes OK during buildup, and I get the 'dist' folder with files in my home directory (using Lubuntu Linux). Problem is, the Lubuntu recognises the file with the name 'search' as executable, but it hasn't got an .exe extension. On the Windows platform, it is showed just as an file without an extension. So when I try to run it on Windows XP, it just won't work. Adding an .exe extension also do not help.
Do someone have a clue what am I doing wrong?
Thanks.

Related

Tesseract cannot find eng.traineddata

I have python program which uses tesseract ocr engine. At first it worked fine. However I uninstall tesseract and reinstall it this time it does not work.
It gives
pytesseract.pytesseract.TesseractError: (1, 'Error opening data file C:\\Program Files\\Tesseract-OCR/eng.traineddata Please make sure the TESSDATA_PREFIX
I did not change anything, but it does not work.
I add TESSDATA_PREFIX to the path.
But when I move eng.traineddata from tesstada to tesseract-ocr file it worked. I have another computer and also it has same program and it works well. However eng.traineddata is in tessdata folder.
Why is the one program gives an error, another is not ?
EDIT
1) 'C:\Program Files\Tesseract-OCR/eng.traineddata' does not exist in two computers. However one of them is working but the other is not working. Therefore As I stated in the question, I move eng.traineddata from tessdata to Tesseract-OCR folder and then it is worked. But here is the question why one of it is working and the other is not working ? Because other program does not have eng.traineddata in the Tesseract-OCR folder.
2) I downloaded the windows executable of tesseract from mannheim uni library. So file is not corrupted.
3)I am using Tesseract 3.05
4) I have created TESSDATA_PREFIX env variable.
5) I downloaded the windows executable of tesseract from mannheim uni library.
Thank you very much.
Does 'C:\Program Files\Tesseract-OCR/eng.traineddata' exists?
Did you check if file is not corrupted (e.g. you downloaded it correctly)
From which (tessdata repository) source you downloaded it?
Adding TESSDATA_PREFIX to paths is useless: you have to setup env variable TESSDATA_PREFIX.
Provide full code how you setup and run pytesseract. Showing only (part of) error message does not help.

Converting .py to .exe with pandas imported for all users not having pandas

I'm new to Python, but I have set up an python script for searching some specific Values in 2 different excel sheets printing out matches (in excel).
Problem is, that our work machines are heavily locked down and without admin privileges, we can't really install anything (we can download though). Is there any version of Python that is Windows 7 compatible that will run standalone without requiring any sort of installer?
I have tried pyInstaller, but the problem is that in my script we need PANDAS.
And there is no possibility to pip install pandas to our local machines. All is blocked. ("pip install pandas" is not possible. I did the code with Anaconda)
So my question is: how can I set up a file for my coworkers, who have no permission to download pandas?
Can I set up an exe file (all use windows 7/10) in my private computer where pandas is already installed and forward it to the workers?
It should be very easy for them to use--> double click for executing the python script
Thanks in advance for any advice.
You can also use pyinstaller which personally I find the easiest to use. It can bundle executables for both Linux and Windows, but it must be run on that architecture that you wish to have executable for, i.e. if you want to have Linux executable the pyinstaller command with your code must be run on Linux OS of some kind.
More here: https://www.pyinstaller.org/
This is old so you may already have found a solution but this might help others.
Python by default is an interpreted language. This means that compiling it into an .exe file is impossible.
However, using some modules it is indeed possible to convert a .py script into a windows executable.
You can try py2exe.
py2exe is a Python Distutils extension which converts Python scripts
into executable Windows programs, able to run without requiring a
Python installation.
They have a tutorial here.

How to convert file .py to .exe, having Python from Anaconda Navigator? (in which command prompt should I write installation codes?)

I created a Python script (format .py) that works.
I would like to convert this file to .exe, to use it in a computer without having Python installed.
How can I do?
I have Python from Anaconda3.
What can I do?
Thank you!
I followed some instruction found here on Stackoverflow.
.I modify the Path in the 'Environment variables' in the windows settings, edited to the Anaconda folder.
.I managed to install pip in conda prompt (I guess).
Still, nothing is working. I don't know how to proceed and in general how to do things properly.
I personaly use pyinstaller, its available from pip.
But it will not really compile, it will just bundle.
The difference is compiling means translating to real machine code while bundling is creating a big exe file with all your libs and your python interpreter.
Even if pyinstaller create bigger file and is slower than cython (at execution), I prefer it because it work all the time without work (except lunching it).

Can't get .exe to execute on other machine - "No module named serial" error

System: Python 3.7 64x running on Windows 10. I also have Anaconda installed on my machine and I program through VS Code. All modules have been installed, verified installed, and are up-to-date.
I have written a script and compiled it into an .exe using pyinstaller. pyinstaller -wFi pyico.ico endpointapp3.py.The .exe works and runs on my machine but it's not meant for my computer. Previous iterations of this script have been compiled, tested, and worked appropriately on its destination computer, a Windows 7 machine with no python installed.
My latest version now includes pyserial, and works, again, on my machine, but I after compiling and creating an .exe file for the destination machine I encounter this error.
File "endpointapp2.py", line 9 in <module>
ModuleNotFoundError: No module named 'serial'
[3512] Failed to execute script endpointapp2.py
Line 9 is my import serial line
As I mentioned before, this executable runs on my machine, but not on the destination machine it was designed for. I don't want to install python, or python modules on the destination machine because I want the .exe to be all inclusive.
Questions:
Why am I getting this error? What does it mean?
Is there a work around that allows me to compile everything together (using pyinstaller) that will hold all the necessary module
information within the .exe?
Is there something else I should be adding to my original script that will allow me to work through this?
NOT A DUPLICATE - This post is for compiling and running python .exe's on another machine, independent of python, with no modules or python installed.
With some assistance and helpful advice (thanks martineau) I was able to solve my problem. When compiling with pyinstaller, it makes a .spec file that it actually uses to compile to .exe.
Here I found the necessary steps to make sure I was adding the files I needed for pyinstaller.
Here I found out how to properly add the module information into my compiling code.
Once pyinstaller had the correct info in the .spec file I was able to compile and execute on the destination machine as intended.
I solve this issue when i move my code into serial module location.
First find where serial module locate :
>>> import serial
>>> serial.__file__
'C:\\Program Files\\Python310\\lib\\site-packages\\serial\\__init__.py'
mine is above.
Then move your file into :
'C:\\Program Files\\Python310\\lib\\site-packages\\{your_file.py}'
Then run pyinstaller :
pyinstaller --onefile your_file.py --additional-hooks-dir serial\\__init__.py
Run your .exe from dist folder. No longer showing error.
The module is called pyserial, but the library call in the code is import serial. Pyinstaller is unable to complete the build because there truly is no module named serial.
To correct this you need to tell pyinstaller to import the correct package by including it in the .spec file under hiddenimports.
hiddenimports=['pyserial']
This will be true for any case where the package name and the import statement call are not the same.

Easier way to create python executable standalone program in window

Creating a python executable in pycharm is harder than creating it in visual studio or creating a vb.net executable.
I thought I'd understand how to do this already but it looks like I have not.
I created a question regarding this in Dec of last year, here >> Create a simple python executable program and an icon to it - Hello World.
But I don't understand the answer or if it was answered completely. So I did my research again and found 2 helpful sites below that helped me create python executable without visual studio involved,
https://pythonhosted.org/PyInstaller/installation.html
https://pythonhosted.org/PyInstaller/usage.html#using-pyinstaller.
I followed the instructions exactly:
In command line, set path to C:\Python34\Scripts, then type pyinstaller "C:\Users\Desktop\PROGRAMs\TEST22.py".
This creates a TEST22.spec file in C:\Python34\Scripts and creates a folder TEST22 in C:\Python34\Scripts\dist and in there, are the TEST22.exe. I click on this executable to run the program, it runs completely fine. But when I copied the executable to the desktop, for example, it doesn't run. It seems like in the scripts folder there are files needed to run it and when it's a stand alone program there are no file to run it. Could someone let me know an easier way to create executable and please advise me on how I could fix it when the executable is copied to desktop or anywhere else and run it ?
Your answer lies in pyinstaller documentation. The dist folder itself is a standalone program directory. To get a single file exe with pyinstaller is not possible even thou pyinstaller has -F option for single exe since it dosnt contain data files.
I would suggest use py2exe and inno setup for creating installer

Resources