Here I'm using python 3.9.0
pyinstaller : The term 'pyinstaller' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
So pyinstaller isn't on your path
According to WikiPedia A path is a string of characters used to uniquely identify a location in a directory structure. It is composed by following the directory tree hierarchy in which components, separated by a delimiting character, represent each directory.
Checkout this Question from Stackoverflow it will help you
The problem here is that you are not in the shell but in Microsoft PowerShell. That's something completely different. Even if it looks a little like a command shell.
Exit the PowerShell and open the command shell by pressing "Windows Logo"+R, enter cmd and hit OK. Then, you can execute pyinstaller.
Alternatively (and sometimes much easier), you can create a Batch file to execute the pyinstaller command line with all necessary options. Just create an empty text file, write the command in it, write pause on the last line and store it with the extension .BAT. You can then double-click it to execute the command. (pause is necessary to keep the terminal open until you have read all messages, warnings and errors)
I resolved it by this process.
Run this command in the respective path where you got an error.
pip uninstall pyinstaller
go to main python folder C:\Users\USER NAME\AppData\Roaming\Python
and open powershell window in the python path and Now run this command.
pip install pyinstaller
Related
I've just started a class that uses Python. At this point, I'm a complete beginner. I running Windows 10 via Parallels on an iMac. I'm have trouble organizing the directories within the "Python36-32" directory that is located on the VM (Windows). If I place a .py file in the main directory, I can run the file through the command prompt and see something like.
c:\Program Files\Python36-32>python first.py
hello
However, if I try to organized the file the file isn't read at all. For example, if I wanted the "first.py" file to run from a "web221" (the name of my class) subdirectory of "python36-32" and then try to open "first.py", I get:
C:\Program Files\Python36-32\web221>python first.py
'python' is not recognized as an internal or external command,
operable program or batch file.
I'd really like to keep all of the .py files I create for my class organized for obvious reasons. Any help would be appreciated.
When you execute from the one directory, the Python executable is present and Windows has no issue finding what to execute.
From the other directory though, Windows attempts to find the executable in your PATH and cannot see it.
Here is some help from the Python 3 docs:
https://docs.python.org/3/using/windows.html#excursus-setting-environment-variables
Specifically, try this as a test:
Windows allows environment variables to be configured permanently at both the User level and the System level, or temporarily in a command prompt.
To temporarily set environment variables, open Command Prompt and use the set command:
C:\>set PATH=C:\Program Files\Python 3.6;%PATH%
C:\>set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib
C:\>python
However, this will only temporarily add the executable to your path. Try it to see if it works, and if it does, then you'll have the information you need to add it to your PATH variable permanently. Note: your directory is named differently, so you'll need to replace Python 3.6 with the name of the directory where Python is installed.
For the task of editing the PATH such that the changes persist from one command prompt session to the next, there's a related SO question that might be helpful:
How to add to the pythonpath in windows 7?
I tried many times installing, "protoc-3.2.0-windows-x86_64.exe", but it doesn't get installed. When I double-click on it, there would be no screen displayed. I tried opening it through command line interface. I got a message as "Missing Input File".
Protoc Installation Error on Command Prompt
What is that missing input file? What should I do now? Please respond to my problem at the earliest!
protoc-3.2.0-windows-x86_64.exe is the Protocol Compiler. It is not an installer. This is the program itself.
This program is designed to run on the command line. It takes a .proto file as input (which you specify on the command line) and it outputs code in a variety of languages. It says "Missing input file" because you didn't specify a .proto file.
To "install" it, copy the .exe file to wherever you want to run it from. You may want to rename it to protoc.exe, and place it somewhere in your PATH, so that the command you have to type becomes just protoc.
The binary has to be placed in the path specified by Command Prompt, when opened under Admin mode. For me, under Admin mode, it was "C:/Windows/System32".
I want to double click on my Python script (which uses a Tkinter GUI) and I just want it to open the Tkinter window, not the console window.
To do this, I changed the extension from .py to .pyw and this seems to work fine on Windows but when I double click my .pyw file on a Linux machine, it doesn't work. It simply froze and I had to restart my system.
Please suggest a platform-independent solution that would help me to run the Python script without opening the terminal/command prompt.
it's been a while since i tried on linux, but i believe it should be fairly simple, firstly you need to put a shebang at the top of the script so your shell knows which executable to use:
#!/usr/bin/python
or if you want a specific version you can expand this to:
#!/usr/bin/python3.2
using whichever version you want (only works for first 2 digits)
then you need to mark it as executable:
chmod 711 myfile.py
for more info on this see this page
then when you double click it, on the rpi (last i used linux) it asks if you want to execute it, or execute it in the terminal.
if you choose to execute it without the terminal, you should only see the tkinter GUI
You can use pyinstaller to create the executables for the different platforms you want.
For example,
The syntax of the pyinstaller command is:
pyinstaller [options] script [script ...] | specfile
In the most simple case, set the current directory to the location of your program myscript.py and execute:
pyinstaller myscript.py
PyInstaller analyzes myscript.py and:
Writes myscript.spec in the same folder as the script.
Creates a folder build in the same folder as the script if it does not exist.
Writes some log files and working files in the build folder.
Creates a folder dist in the same folder as the script if it does not exist.
Writes the myscript executable folder in the dist folder.
In the dist folder you find the bundled app you distribute to your users.
Normally you name one script on the command line. If you name more, all are analyzed and included in the output. However, the first script named supplies the name for the spec file and for the executable folder or file. Its code is the first to execute at run-time.
For certain uses you may edit the contents of myscript.spec (described under Using Spec Files). After you do this, you name the spec file to PyInstaller instead of the script:
pyinstaller myscript.spec
You may give a path to the script or spec file, for example
pyinstaller options... ~/myproject/source/myscript.py
or, on Windows,
pyinstaller "C:\Documents and Settings\project\myscript.spec"
pyinstaller
so my ultimate goal is to use python to read a specific application's windows event log when triggered by a file update.
Here is my problem, python I believe does not have access to the event logs stored in C:\Windows\System32\winevt\Logs. Whenever I try to read the files I get the following error:
WindowsError: [Error 2] The system cannot find the file specified
I tried every form of escaping, string split/join and using quotes on the file path and I always get the same error. I even cheaply used the os.system('dir "C:\Windows\System32..."') command in the python command prompt to list directories higher in the path for the log to verify access and I receive similar errors up to the C:\Windows\System32 directory, that one will list just fine.
Example:
C:\Windows\System32\winevt\Logs - File not found
C:\Windows\System32\winevt - File not found
C:\Windows\System32 - Lists files
I know these directories exist. So from here I figured I could use a bash script to copy the event log into a temp folder for python to read. I wrote a real simple bash script containing:
xcopy /Y "C:\Windows\System32\winevt\Logs\XXXXXXX" c:\Temp
(XXXXXXX) being the name of the log I want to copy for the python script.
The bash script runs fine on its own but when called by my python script it fails, refuses to copy the file because it can't find it. I have even tried using py2exe to create an exe to then run in administrator mode. This failed too. With similar errors of the file not found. I'm not sure I understand the permissions python uses to call the script and why the bash script cannot copy the file even when it can do it in a normal command prompt.
Any suggestions or flaws you can point out in my logic would be great. I am very stuck.
You are using a 32bits python on a 64bit install of windows.
In most cases, whenever a 32-bit application attempts to access %windir%\System32, the access is redirected to %windir%\SysWOW64
You can use os.listdir("c:\windows\sysnative\winevt\logs") as a workaround to read from the real system32 dir from a 32bit python interpretter runing on a 64bit windows...
Sources:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa384187(v=vs.85).aspx
http://support.microsoft.com/kb/942589
Basically, I'd like to run a script (versus typing python program.py) or even have a shortcut that I could click on and start the program. Any ideas?
From python.org:
On Windows systems, there is no
notion of an “executable mode”. The
Python installer automatically
associates .py files with python.exe
so that a double-click on a Python
file will run it as a script. The
extension can also be .pyw, in that
case, the console window that normally
appears is suppressed.
Also from python.org:
On Windows 2000, the standard Python
installer already associates the .py
extension with a file type
(Python.File) and gives that file type
an open command that runs the
interpreter (D:\Program
Files\Python\python.exe "%1" %*). This
is enough to make scripts executable
from the command prompt as ‘foo.py’.
If you’d rather be able to execute the
script by simple typing ‘foo’ with no
extension you need to add .py to the
PATHEXT environment variable.
Try using a batch file (.bat).
Type in whatever commands you want to execute in the proper order, in notepad, such as:
python program.py
Save the file as iHateTyping.bat
Open the command prompt using Run.
Go to the directory where you saved the file using cd.
Type in:
iHateTyping.bat
& you're done.
I encourage you to read more about batch files in the link highlighted above.
Press Ctrl+R, then type python.py to run your Python script.
Use py2exe to create a portable windows executable file.