Create python exe in windows with pyinstaller? - python

I'm trying to create an executable from a python script that I created, but I'm stuck
I installed Python 3.9 x64 for windows and pyinstaller, following different tutorials, but nothing works to me. The initial tutorial was this (I followed others similiars to this too):
https://datatofish.com/executable-pyinstaller/
next, when I was trying to create the .exe with the command: pyinstaller name_archive.py
I got the next error:
'pyinstaller' is not recognized as an internal or external command,
operable program or batch file.
for that problem, I found some solution here:
https://www.it-swarm-es.com/es/python/pyinstaller-no-se-reconoce-como-comando-interno-o-externo/834789072/
I added to the Environment Variables, to PATH, in User Variables and System Variable both, the next dir:
C:\Users\User\AppData\Roaming\Python\Python39\Scripts
Now, running again the command: pyinstaller name_archive.py in the cmd and with the route of the archive (C:\Users\User\Desktop\K1>pyinstaller name_arhive.py) gives this error:
Fatal error in launcher: Unable to create process using '"c:\program files\python39\python.exe" "C:\Users\User\AppData\Roaming\Python\Python39\Scripts\pyinstaller.exe" name_archive.py': The system can't find the specified file
I looked for the problem widely in the web, but I couldn't find any helpful information, even in the pyinstaller website... (https://pypi.org/project/pyinstaller/)
Please help, I tried anything for the last four hours and nothing results... lol

Related

Python script installation fails on windows

I'm trying to deploy a larger python project which includes a script on
windows. Installation works fine on UNIX, but on windows it seems
impossible to get the script running. I've created a minimal example on
GitHub to demonstrate
the problem.
When running pip install ., the script is installed to C:\Program Files\Python39\Scripts\hello-world. The directory is contained in the
PATH. My user has read & execute permissions. The hashbang of
hello-world is replaced with #!c:\program files\python39\python.exe,
which also seems correct. However, running hello-world in the console
yields the following error:
C:\Users\malte>hello-world
'hello-world' is not recognized as an internal or external command,
operable program or batch file.
I expected this to work. Why doesn't it? How can I fix this?
I've tried some things, and noticed another strange behavior in this
context. Running shutil.which('hello-world') returns None. If I
rename hello-world to hello-world.exe, then calling hello-world
results in a strange error, most likely because windows
now thinks the script is a binary. That's fine. Except that now
shutil.which('hello-world')
returns 'C:\\Program Files\\Python39\\Scripts\\hello-world.EXE'. Why?
Update
The master branch of the respository now contains a solution that works cross-platform, which I learned from here: https://matthew-brett.github.io/pydagogue/installing_scripts.html.
It's not exactly clear to me, but the following paragraph from the Python documentation seems to state that a script with a hashbang line must have an extension associated with the python launcher in order for windows to recognize it: https://docs.python.org/3/using/windows.html#from-a-script
In other words, it appears that my assumption that using the scripts parameter of setuptools.setup works cross-platform is subject to some conditions which are hidden somewhere in the python documentation.

Pyinstaller - Python exe when run shows error "Failed to execute script pyi_rth_nltk"

I have developed a simple software in python with GUI. I'm actually working on Natural Language Processing and I've just put the whole NLP process in a GUI.
I tried to convert the whole project to a exe file in python using Pyinstaller. I successfully converted it to an exe file but when I run it , it shows an error message something like this
This is the image of my error
I have already solved it but by using another way of converting py to exe which is the cx_Freeze.
I had the same issue earlier today and finally got it to work using the following software versions:
Python 3.6.8, nltk 3.5 and a dev version of pyinstaller:
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
Additionally, I used scikit-learn version 0.21.1.
Few days back, I had the same problem while compressing to EXE. This Problem generally occurs when PyInstaller failes to find Libraries and Modules to import to the directory. But I overcame this problem and the wise solution yet tedious method to do is mentioned below,
Convert Python Scripts to EXE with console = True in the .spec file or to be simple, do not add --noconsole argument while converting using System Argmuents method.(execute GUI with CMD)
After successfully building the file, go to respective directory (dist folder) and open command prompt
Run the Exe file using Command Prompt.
Find the error message and rectify it correspondingly. For example, consider the following Error Message, vcomp140.dll is missing from \\sklearn\\libs directory.
At the end of this Error Message, you'll find Failed to load dynlib/dll , Therefore, find the file or program which is missing. Say, Here we've .libs\\vcomp140.dll
Find vcomp140.dll using window search bar in your C Drive.
Copy the specific file and paste in the directory(under "dist" folder) where the file is missing. Here, the directory is dist\\PyScriptToEXE\\sklearn\\.libs
MatplotlibDeprecationWarning:
The MATPLOTLIBDATA environment variable was deprecated in Matplotlib 3.1 and will be removed in 3.3.
exec(bytecode, module.__dict__)
Traceback (most recent call last):
...
...
...
py3.7.egg\PyInstaller\loader\pyiboot01_bootstrap.py", line 169, in __init__
__main__.PyInstallerImportError: Failed to load dynlib/dll 'C:\\Users\\MOHAMM~1\\AppData\\Local\\Temp\\_MEI38242\\sklearn\\.libs\\vcomp140.dll'. Most probably this dynlib/dll was not found when the application was frozen.
[13968] Failed to execute script try
Follow the steps again using CMD to eliminate each error.

"python.exe can't find '__main__' module in ..." Error when trying to run python script opencv_blink_detect.py in virtual environment,

Apologies if there's missing information. I'm using python for medical research and am trying to run a program to count the number of blinks via video footage.
https://github.com/skvrahul/blink_detect
The script is located here
My virtual environment is set up here:
Package install instructions were followed from here
Terminal open via Anaconda
Attempt to run via readme instructions
Attempt to direct terminal to look at file path
As you can see, the error message is
(opencv-env) C:\Users\wmj>python C:\Users\wmj\Documents\Python Scripts\Biometrics\blink_detect-master.py -p -sp.dat
C:\Users\wmj\AppData\Local\Continuum\anaconda3\envs\opencv-env\python.exe: can't find 'main' module in 'C:\Users\wmj\Documents\Python'
The contents of C:\Users\wmj\Documents\Python is just Anaconda3-2018.12-Windows-x86_64
I have searched online and most solutions to this problem seem to be either solved by modifying the .py file or doing something with Pycharm
What is the solution to this? I want to be able to run the script as a demonstration to my supervisor
Thank you,
WW
Try first to cd to the exact location of the package and then run exactly as written in the readme instructions.
Python has to get the full path of the script you're trying to execute and the script itself has to get the sp.dat file as an argument.

Pyinstaller exectuable using data from other folders?

I've written a program that generates a random name and displays a random image along with it using Python and tkinter. However, I want the user to be able to add and remove pictures as well as edit the names of students. That being said, I don't want to package these inside the executable where it can't be changed by the user.
To use PyInstaller, I go into the command prompt and navigate to the working directory and type:
pyi-makespec --windowed --onefile --icon=Assets\\icon.ico random_student.py
Then, in the spec file I change datas to:
datas=[('Assets\\icon.ico', 'Assets')],
Then, I run
pyinstaller random_student.spec
The program runs just fine using PyCharm. And I've done this exact same method on a couple of other .py files an it works. However, they don't need to pull images/text into their programs. This will create an executable, but I can't run it. It gives me a Fatal Error "Failed to execute script random_student". I've tried placing the executable in the working directory and in the pictures folder, but neither work.
I'm currently using Windows 10 64-bit and Python 3.6.6
I'd appreciate any kind of help I can get with this!
SOLUTION: I removed the --windowed option so I could actually read the error. Then realized I didn't have Pillow installed so it was unable to be packaged. Thank you for the help.

Running Python in Atom Windows 10

I've installed Python 3.5 on my computer along with Atom. I selected Python in the bottom right and quickly wrote print ("Hello World"). However, I get an error message that says 'python' is not recognized as an internal or external command,
operable program or batch file.
[Finished in 0.364s]
I have looked up solutions online. I have edited the init file in atom as well as the environment variable path, with the path to python. Lastly, I have edited the "Command" field in the "Script" package to include Python3.
The code I placed on the init file is process.env.path = ["C:\Python27\ArcGIS10.2",process.env.PATH].join(";")
Links to where I found my solutions:
https://discuss.atom.io/t/cannot-get-python-to-run-from-atom-on-windows/15585/11
http://www.siliconcreek.net/computers/running-python-in-atom-io-in-windows
quora. com/How-can-I-run-Python-in-Atom
I am using a new windows surface, and am setting up my development environment for the first time on this computer. Please help.

Categories