Pyinstaller Files Suddenly Missing - python

I successfully created .exe files using Pyinstaller. I was on a Windows 7 machine using Anaconda3, PyQt5, OpenCV3, and Python 3.6. Anaconda3 was in the Windows Environment Path. Because there is no release for Pyinstaller for Python 3.6, I created a Python 3.5.3 environment (with OpenCV) within Anaconda3. I wrote the software in Python 3.6, then activated Python3.5.3 to run Pyinstaller. The executable worked flawlessly. The dist folder was abot 370MB.
Then I upgraded the machine to Windows 10 using a clean installation. I installed Anaconda3 (Anaconda3 was added to the Windows Environment Path) and OpenCV (PyQt5 was already available within Anaconda3), created the Python3.5.3 environment, installed PyInstaller iand OpenCV nto the Python 3.5.3 environment. Using Spyder and Python 3.6, the script runs perfectly. When activating Python 3.5.3 and running python myscript.py from the command line, the script ran flawlessly. However, Pyinstaller only installs about 220MB and the resultant executable does not execute.
I don’t have the old dist folder from the successful Windows 7 build to see what files were added to the dist folder that were not added when in Windows 10.
Does anyone know how I can determine the additional files needed for the Pyinstaller buid?

I switched to cx_Freeze. It also didn't work at first, but then I added optional packages PyQt5, cv2, and numpy. cx_Freeze crashed and gave me an error about PyQt5, so I took PyQt5 out of the optional packages and ran python setup.py build again and it worked. So then I removed cv2 and it still worked. Then I removed numpy and it failed. So I added numpy back in. Here is setup.py
from cx_Freeze import setup, Executable
exe=Executable(
script="VSWv08.py", base = "Win32GUI")
includefiles=["VSWManual.txt", "VSWLicense.txt"]
includes=[]
excludes=[]
packages=["numpy"]
setup(
version = "1.0",
description = "MyApplication",
author = "Me",
name = "My Application",
options = {'build_exe':
{'excludes':excludes,'packages':packages,'include_files':includefiles}},
executables = [exe]
)

Related

How to convert .py to .exe (32bit)

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.

Windows 10: Make Py Launcher choose official installation instead of Anaconda (same Python version)

I installed official Python then Anaconda3 afterwards (both 3.9)
I suspect it is because I ticked 'Register Anaconda3 as my default Python 3.9' when I was installing Anaconda, that now when I type py -0p in cmd, the path goes to Anaconda (I do not have Anaconda in PATH). I would like Python 3.9 to use the official installation.
Installed Pythons found by py Launcher for Windows *
-3.9-64 C:\Users\xxx\anaconda3\python.exe
What exactly did ticking 'Register Anaconda3 as my default Python 3.9' change in my system? I would like to revert it. I already looked for py.ini and it does not exist beside py.exe and %LOCALAPPDATA%, so it is not that.
With reference to this comment: py launcher does not find my Python 2.7, I deleted \HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\3.9 in regedit. py -0p gave this output after a reboot, which is what I wanted:
Installed Pythons found by py Launcher for Windows *
-3.9-64 C:\Program Files\Python39\python.exe
My Python installation is system-wide, so the keys for the offical installation exist at \HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\3.9.
For those who installed Python for their user only, you may want to modify the keys in \HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\3.9 instead of deleting them.

Error loading Python lib with PyInstaller on MacOS

I am trying to package some python into an executable on MacOS (10.14.5). I am able to create the executable, but executing the resulting dist/hello_world executable gives the following error:
[55240] Error loading Python lib '/var/folders/yh/6_6mb2y96kg0gnb_nh9r2zrr0000gp/T/_MEIwUMw4X/Python': dlopen: dlopen(/var/folders/yh/6_6mb2y96kg0gnb_nh9r2zrr0000gp/T/_MEIwUMw4X/Python, 10): no suitable image found. Did find:
/var/folders/yh/6_6mb2y96kg0gnb_nh9r2zrr0000gp/T/_MEIwUMw4X/Python: code signature invalid for '/var/folders/yh/6_6mb2y96kg0gnb_nh9r2zrr0000gp/T/_MEIwUMw4X/Python'
My machine is running Python 3.7.7 installed from using the Mac installer downloaded from https://www.python.org/
For now, the script I am trying to package only contains print('hello world!') and the packaging command I am using is pyinstaller -F hello_world.py
I had success using pyenv and installing the specific version of python with the enable framework option:
env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.7.6
With this version of python (set using the command pyenv local 3.7.6 in the folder where hello_world.py is located), install pyinstaller (and any other modules you need) with pip. Then build with
pyinstaller hello_world.py --onefile --clean --windowed
which should give you a functioning dist/hello_word. As a python fledgling, I have no idea why this works as opposed to the steps in the original question. (I thought the Mac OS installer included the Python.framework by default -- I'm sure my ignorance is exposed here as this probably differs significantly from what the PYTHON_CONFIGURE_OPTS variable is doing above).
Also possible to do all this within a virtual environment (easily managed by pyenv-virtualenv).
The latest version of Pyinstaller only supports Python 2.7, 3.5–3.7. If you downgrade to Python 3.7 it will work!

How to make pyinstaller not use anaconda and build a small-size exe file

I have been trying to build .exe file using pyinstaller in windows 10. It worked, but the size of the exe file is ~212 MB, even by using a venv (as in here). I thought it might be because I am using python by anaconda!
Then I installed a separate version of Python so not to use anaconda! But it did not work (still large file).
Then I uninstalled anaconda to test it. Pyinstaller is still trying to access Python in 'C:\Program Files\anaconda3\python.exe' (this error: No Python at 'C:\Program Files\anaconda3\python.exe'). However I have removed all path to anaconda. Probably it has always tried to reach anaconda, and this is why I haven't been successful to build a small size .exe file.
How can I clearly indicate paths for pyinstaller and python?
Finally, after a lot of researching, could solve my problem:
Uninstalled all pythons and anaconda from my PC
Removed all Path from the system variables
Restarted the windows
Installed a fresh Python from its website
Installed Pyinstaller using pip install pyinstaller
Tested my .py code in cmd. It showed me all the packages that are missing.
Installed all required packages by using pip install name-of-package
Ran final command by pyinstaller -F -w --clean file.py
(Optional) Install Anaconda if you need (don't add Anaconda Python as the default python. Also don't add its path to the system variables).
Note: You can build virtualenv and do pyinstaller in them.
My previous tries which used anaconda resulted in file of 212 MB in size. This process generated a .exe file of size 27 MB (Importing only pandas module).
I ran into a similar problem and found PyCharms virtualenv manager very helpful. https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html
This just necessitated downloading python from python.org and linking the virtual environment to this interpreter, rather than the conda interpreter (otherwise it will throw strange SSL errors).
This seems to allow neat parallel use of conda and virtualenv.

Can cx-freeze be used in Ubuntu to freeze a python script to a Windows executable?

When I use cxfreeze in Ubuntu, it automatically compiles the python script to a Linux executable. I've looked through the documentation extensively, and I can't find a way to freeze the script into a .exe for the purposes of running the program on a Windows machine. Can this be done-?
You can do that.... but you'll have to install Wine (apt-get install wine) and then install in Wine the windows version of Python and all the python libraries your application needs, and then you'll be able to freeze your script into an exe for windows in your ubuntu box.

Categories

Resources