Trap trapped when running a Python Windows executable

Trap trapped when creating a Python executable file

When I created a Windows executable file using Python, I wanted to process it using command line arguments, but I record the trap that occurred at that time as a reminder.

Command line arguments

Hello world with command line arguments

hello.py


import sys

str1 = sys.argv[1]

print(str1)

python test.py helloworld >>> helloworld

Make an executable file using pyinstaller

pyinstaller hello.py --onefile

Run hello.exe

IndexError: list index out of range The cause was that the list could not be created because it does not use the command line.

Solution

Use Input function

hello.py


str1 = input("please put something")

print(str1)

Run hello.py

>>>please put something helloworld

Conclusion

As a result of trial and error, I could not get the command line arguments using sys, so I decided to use the Input function and it worked. If anyone knows how to use command line arguments in a Windows executable, I'd love to hear from you.

Recommended Posts

Trap trapped when running a Python Windows executable
What's in that variable (when running a Python script)
Specify options when running python
[GCP] A memorandum when running a Python program on Cloud Functions
Precautions when creating a Python generator
When writing a program in Python
Determine if standard output is piped when running a Python script
Everything from building a Python environment to running it on Windows
Building a Python 3.6 environment with Windows + PowerShell
When running a Python shell from Electron, pass multiple arguments to run Python.
[Python] [Windows] Take a screen capture in Python
Creating a python virtual environment on Windows
[Beginner] Installing Python and running programs (Windows)
Call a command from Python (Windows version)
A note I was addicted to when running Python with Visual Studio Code
Error when installing a module with Python pip
A memo of a tutorial on running python on heroku
Simply build a Python 3 execution environment on Windows
CRLF becomes LF when reading a Python file
Python variadic memorandum when inheriting a defined class
I get a UnicodeDecodeError when running with mod_wsgi
Python Note: When assigning a value to a string
A memo when creating a python environment with miniconda
GUI (WxPython) executable file (pyInstaller) [Windows] in Python3
Launch a shell while a Python script is running
I tried running alembic, a Python migration tool
Create a Python virtual development environment on Windows
A story when a Python user passes a JSON file
Python on Windows
Python installation (Windows)
[Grasshopper] When creating a data tree on Python script
Build a GVim-based Python development environment on Windows 10 (3) GVim8.0 & Python3.6
Until drawing a 3D graph in Python on windows10
I tried running python etc. from a bat file
A memorandum when writing experimental code ~ Logging in python
Create a comfortable Python 3 (Anaconda) development environment on windows
Build a GVim-based Python development environment on Windows 10 (1) Installation
Problems when creating a csv-json conversion tool with python
Things to note when initializing a list in Python
Procedure for building a CDK environment on Windows (Python)
Use communicate () when receiving output in a Python subprocess
[Python] I tried running a local server using flask
Create a decent shell and python environment on Windows
I got "ModuleNotFoundError: No module named'azure'" when running a program using Azure SDK for Python