I'm trying to convert a simple python code (any sample code) into an executable file but on opening the application all I can see is a blank black screen.
I am using:
Python 3.7
PyInstaller 3.6
One file output
I am able to convert the file to .exe using auto-py-to-exe but I don't see any output when I try to run the application.
Pyinstaller is much easier than other things, you need to install with pip:
pip install pyinstaller
And then go to the path of your Python file and then:
pyinstaller -w -F my_file.py
In general there are some different ways so you can try the below and see if the issue is solved.
auto-py-to-exe is "A .py to .exe converter using a simple graphical interface built using Eel and PyInstaller in Python.". You can find a quick guide here
PyInstaller "freezes (packages) Python applications into stand-alone executables, under Windows, GNU/Linux, Mac OS X, FreeBSD, Solaris and AIX." You can find more usage info here (also pointed out by #nakE)
py2exe "is a Python Distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation.".You can find more usage info here (also as pointed out by #Kompocik)
If it is not solved then I am pretty confident that there is an issue with the executed code per se and not the conversion.
Can you please share your code so we can have a look?
Try doing this in order:
py -3.7 -m pip uninstall pyinstaller
py -3.7 -m pip install pyinstaller
pyinstaller --onefile test.py
Related
I created an application using PyQt5, and I'm willing to convert it to a 32bit executable file (.exe) using auto-py-to-exe! I searched a lot about this and figured out that I should use a 32bit version of Python for this purpose(examples:[1],[2],[3],[4]). Since I'm comfortable with using Conda environments, I tried to make a clone from my preferred Conda environment(that contains PyQt5 and auto-py-to-exe) in this way:
set CONDA_SUBDIR=win-32
conda create --name py32 --clone python3.10
conda activate py32
conda update --all
# Then I tried to run auto-py-to-exe
auto-py-to-exe
After this, I did a transformation using auto-py-to-exe successfully. But still, I get this error on 32bit windows when I try to execute the .exe file:
Now I'm somewhat disappointed about how I should achieve my goal.
Important Question: Why did I use set CONDA_SUBDIR=win-32? Because I think that command helps me clone everything with 32bit format and converts my cloned Python to a 32bit version, this helps me run auto-py-to-exe and convert my .py file to a .exe 32bit file. But it seems I'm wrong about this since I can't run the .exe file in 32bit OS.
Can you please help me how I can create a 32bit version of Python in a Conda environment and then use auto-py-to-exe to create the 32bit .exe file? (I assume that auto-py-to-exe also uses Python for running, and the 32bit version of Python influence on auto-py-to-exe result.)
Additional details:
My OS: 64bit Windows 10
But I want to run the .exe file on another machine that has 32bit Windows 10
Update:
Since I didn't get an answer about Conda environments, I tried installing 32bit Python. I achieved a 32bit .exe file with these steps:
Installing Python 3.10.1 32bit using this link.
Adding the Python path to the User variables and System variables:
Then I opened cmd and installed the required packages like auto-py-to-exe (also those used in .py) using pip.
run auto-py-to-exe in cmd and start converting.
The result is a 32bit .exe file that a 32bit OS can execute. But This isn't exactly what I looked for(it works, but it made me install a 32bit Python and add it to the path, which isn't what I looked for). So I write this here and hope for someone to help me do these in a Conda environment.
Don't use Conda environment use venv or pipenv. you can't convert conda environment .py file to exe because of its dependency.While using venv use pyinstaller. install comand -
pip install pyinstaller
convert command -
pyinstaller --onefile -w 'filename.py'
When using pipenv use auto-py-to-exe. yeah auto-py-to-exe is old, but there are no other tools.as for conda you can't do anything.
I have installed pyinstaller like this pip install pyinstaller as a Youtube video said to convert pyw to exe.
Then the tutorial said to convert pyw to exe you need to type pyinstaller -w filename.pyw
, but this doesn't work for me why?
pyinstaller is not a command on your system's PATH, which means that your terminal cannot find it. Because it is a Python module, you may be able to run it with python -m pyinstaller -w main.pyw. This -m <name> specifies that we wish to run a Python module with the given name.
Alternatively, you can add the location of the pyinstaller folder to your PATH. However, this requires finding out where pyinstaller was installed with pip, too. I've generally used the former strategy, and that's the strategy I recommend.
Is there a way to deploy a Python program that includes all dependencies on a Linux system?
I have used py2exe to "compile" a python script with all modules to a standalone .exe, but that's obviously only working on Windows.
Is there an easy way to e.g. develop a flask server with Python and have all its scripts and modules bundled together so that it can be executed on Linux without having to install the dependencies with pip? (assuming python3 is installed on the Linux platform, but no specific Python modules).
Use PyInstaller in Linux based systems
PyInstaller is a program used to convert Python scripts into standalone deployable applications.
Install PyInstaller from PyPI:
pip install pyinstaller
Go to your program’s directory and run:
pyinstaller yourprogram.py
This will generate the bundle in a subdirectory called dist
You can use -onefile argument in order to generate the bundle with
only a single executable file.
You can install the dependencies in the same directory as the program as mentioned here and then package it any way you want. This way the program can always access the dependencies even if they are not installed in the system the program is being executed in.
I've been trying to use PyInstaller on my program, scratch_1.py. The PyCharm project folder is called "idigen", which is saved in my desktop. So, I changed the director like so:
cd /Users/joelsaarinen/Desktop/idigen
then, moved on to use pyinstaller, and I get this error:
pyinstaller scratch_1.py
-bash: pyinstaller: command not found
I'm confused because when I use:
pip show pyinstaller
to verify that I have pyinstaller installed, it returns a positive result.
Is there an additional command I should be putting in when using Pyinstaller on one of my files? Might this be an issue with this specific program or the operating system in general? Thanks in advance.
This is a common problem due to the fact that you might install a different version of python and keep using an old version that is preinstalled in the machine. Here is the best solution.
First, check the version of the python that you installed. In my case, i installed python 3.5 and the machine had python2.7. If you run python on the terminal, most likely the preinstalled one is the one that will run.
Second, check the directory of your desired python version. watch -a python3 is the command to run to see your directory.
Third, set the directory as the main one to run your python commands.
alias python=/usr/local/bin/python3 does the whole trick
Lastly, reinstall pip. Download the get-pip.py file and run sudo /usr/local/bin/python3 get-pip.py * I used the path to show the reason we updated the alias*
Now you can run pyinstaller without problems
pyinstaller appears to have installed correctly, but the command is not available on PATH. You need to locate where the executable was placed.`below to find executables
set | grep pyinstaller
now modify path by this
export PATH=some_path:another_path
launchctl setenv PATH $PATH
I just downloaded the source code of pyInstaller from official website, put it where I can find it and wrote a script which launches pyinstaller.py from that folder.
For some reason, pyinstaller.py is missing in the pyInstaller installation downloaded via pip.
I had the same issue on MacOS with Developer Tools 11.4 and found two ways to start pyinstaller:
alt 1: path based solution
$ pip3 show -f pyinstaller|grep pyinstaller
will find pyinstaller in a bin path:
../../../../usr/local/bin/pyinstaller
...
So you can use one of the set-the-path-or-an-alias approaches or call via fully qualified path.
alt 2: call via python module
$ pip3 show -f pyinstaller|grep __init__
will get you a hint on how pyinstaller is defined as a module:
PyInstaller/__init__.py
...
With that capitalization, it's possible to call pyinstaller as a module with the following:
$ python3 -m PyInstaller --version
4.2
I'm using the latter now.
I am trying to convert a .py file to an exe. My file, hello.py, reads:
print "Hello, World!"
I am currently trying to use pyinstaller. However when I run the command
pyinstaller hello.py
I get the error message "tuple index out of range" which I have been told means my version of python is unsupported. In particular it would seem the situation is that pyinstaller thinks I am trying to compile python 3.6 code into an exe. But I have python 2.7 and python 3.6 installed. How do I let it know that I want it to regard the code as python 2.7 code?
Using Python3:
Make sure PyInstaller is installed in Python 3.x: pip3 freeze
PyInstaller==3.3.1
Then running the command:
/path/to/python3 -m PyInstaller your_script.py
First install Pyinstaller in your python2.7 version if not installed previously
py -2 -m pip install pyinstaller
and then go to your folder and
py -2 -m pyinstaller -F filename.py
When you need to bundle your application within one OS but for different versions of Python and support libraries – for example, a Python 3 version and a Python 2.7 version; or a supported version that uses Qt4 and a development version that uses Qt5 – we recommend you use virtualenv. With virtualenv you can maintain different combinations of Python and installed packages, and switch from one combination to another easily. (If you work only with Python 3.4 and later, python3 -m venv does the same job, see module venv.)
Use virtualenv to create as many different development environments as you need, each
with its unique combination of Python and installed packages.
Install PyInstaller in each environment.
Use PyInstaller to build your application in each environment.
The answers have devolved in "How do I tell pyinstaller which python version to use?" So, I know that this doesn't really answer the original question. However, I wasted about an hour trying to figure this out so, in the hopes that others don't have to waste an hour... To force pyinstaller to use Python 3.9 under Windows do the following.
Given Windows and Python 3.9:
python3.9 -m PyInstaller [whatever options you want]
You have to type it as PyInstaller instead of pyinstaller (i.e. note the capitalization).
python3.9 -m pyinstaller
Produces an error:
C:\Users\chris.SR\AppData\Local\Programs\Python\Python39\python.exe: No module named pyinstaller
Supposing you have python 2.x on the path under python2 you can do
python2 -m pyinstaller hello.py
I ran two a couple things.
If you uninstall python3, it works with python2.
If you have python3 installed (and it is the primary), and have pyinstaller installed in python3, it wont work (python3 pyinstaller used).
If you have python3 installed, but do not have it installed in python3 or uninstalled it (pip3 uninstall pyinstaller), pyinstaller works.
Checking the environmental variables (windows 10) PATH had python3 first. This may be the issue and may not be resolved because it is checking python3 directories first, and picks up pyinstaller for python3. pyinstaller does not check the file either (#!/usr/env/bin python2).
Unless pyinstaller puts an option relating to this issue, there may be no solution short of uninstalling pyinstaller from python3 temporarily.
note
could also use py2exe, using py2exe for python2, pyinstaller for python3