Not able to run --onefile

Hi, I am not able to run the command “pyinstaller --onefile pythonScriptName.py”. I already have set the path “C:\Program Files\Python39\Scripts” in the environment variable but not able to convert py file in to exe.

I get this message “‘pyinstaller’ is not recognized as an internal or external command,
operable program or batch file.”

Hi Engr,

Have you installed pyinstaller?

It’s not part of Python, it’s a third-party application. It needs to be
installed separately.

Hi,

Yes I have installed “pip install pyinstaller”

“C:\Users\joni>pip install pyinstaller
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pyinstaller in c:\users\joni\appdata\roaming\python\python39\site-packages (4.5)
Requirement already satisfied: pyinstaller-hooks-contrib>=2020.6 in c:\users\joni\appdata\roaming\python\python39\site-packages (from pyinstaller) (2021.2)
Requirement already satisfied: setuptools in c:\program files\python39\lib\site-packages (from pyinstaller) (56.0.0)
Requirement already satisfied: altgraph in c:\users\joni\appdata\roaming\python\python39\site-packages (from pyinstaller) (0.17)
Requirement already satisfied: pywin32-ctypes>=0.2.0 in c:\users\joni\appdata\roaming\python\python39\site-packages (from pyinstaller) (0.2.0)
Requirement already satisfied: pefile>=2017.8.1 in c:\users\joni\appdata\roaming\python\python39\site-packages (from pyinstaller) (2021.5.24)
Requirement already satisfied: future in c:\users\joni\appdata\roaming\python\python39\site-packages (from pefile>=2017.8.1->pyinstaller) (0.18.2)
WARNING: You are using pip version 21.1.3; however, version 21.2.2 is available.
You should consider upgrading via the ‘c:\program files\python39\python.exe -m pip install --upgrade pip’ command.”

I am not able to run the command “pyinstaller --onefile pythonScriptName.py”. I get the same error message which I have mentioned above.

pip did a user install, but you don’t have user scripts directory in PATH. Try running the module via py -m PyInstaller or py -3.9 -m PyInstaller. The module name is case sensitive, so make sure to type “PyInstaller”, not “pyinstaller”.

Or add the user scripts directory to PATH to get the “pyinstaller” command. Here’s one way to show the path of the user scripts directory in Windows:

py -3.9 -c "import sysconfig; print(sysconfig.get_path('scripts', 'nt_user'))"

Hi, I tried both py -m PyInstaller and py -3.9 -m PyInstaller, but I got same error “pyinstaller: error: the following arguments are required: scriptname”.

Kindly advice if there is another method to generate exe from py. Thanks in advance.

It’s an alternative to the pyinstaller command that doesn’t require adding the installation and scripts directories to PATH. However, it’s not a psychic interface that reads your mind to get the rest of the command-line arguments. The required arguments are in your first message.