You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Mac终端带命令行参数运行exe文件?解决命令未找到报错

Fixing "-bash: p1: command not found" When Running a Windows EXE on Mac

Got it, let's break down why you're hitting this error and fix it step by step:

Why the Error Happens

The .exe file extension is specific to Windows executable files—macOS (a Unix-based system) doesn't recognize this format natively. When you try to run p1.exe or just p1, your terminal has no idea how to execute it, hence the "command not found" message. The good news is you have two solid solutions depending on your situation:


Since you originally used pyinstaller to generate a .exe (likely on a Windows system), you'll need to re-run the packaging process directly on your Mac to create a macOS-compatible executable:

  1. Open your Mac terminal and navigate to the folder where your p1.py script lives:
    cd /path/to/your/p1.py/folder
    
  2. Re-run PyInstaller with the same --onefile flag:
    pyinstaller p1.py --onefile
    
  3. PyInstaller will create a dist subfolder inside your current directory. Inside dist, you'll find a file named p1 (no .exe suffix)—this is your macOS executable.
  4. Run it with your command-line arguments like this:
    ./dist/p1 -f input.txt
    
    (The ./ tells the terminal to look in the specified directory for the executable.)

Solution 2: Use Wine to Run the Windows EXE (If You Can't Re-Package)

If you need to use the existing .exe file (e.g., you don't have access to the original p1.py script on your Mac), you can use Wine—a tool that lets you run Windows applications on Unix-based systems:

  1. First, install Homebrew if you haven't already, then run this command to install Wine:
    brew install wine
    
  2. Once Wine is installed, run your .exe file with the arguments like this:
    wine p1.exe -f input.txt
    
    Wine will simulate a Windows environment to execute the file.

Quick Note

The reason python p1.py -f input.txt works fine is because Python is cross-platform—the script itself isn't tied to a specific system's executable format. PyInstaller, however, compiles the script into a system-specific binary, so you need to match the target OS when packaging.

内容的提问来源于stack exchange,提问作者Miffy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:33:25