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

EC2环境Python2.7执行python –m .命令报错:无法打开文件'–m'

Fix: python: can't open file '–m': [Errno 2] No such file or directory

Hey there! Let's break down why this error is happening and how to fix it step by step:

1. The immediate culprit: Incorrect dash character

The first problem is that you're using a Chinese en dash (–) instead of an English hyphen (-) for the -m flag. Python doesn't recognize the en dash as a command-line option—instead, it treats –m as a filename it needs to open, which is why you get the "No such file or directory" error.

2. Fix the command format (even after fixing the dash)

Even if you swap the dash to the correct one, python -m . isn't a valid command. The -m flag tells Python to run a module as a script, so you need to specify a valid module name after it, not just a dot. Here's what you can do instead:

  • If you want to run a specific script in your current directory (e.g., my_script.py), skip the -m flag entirely and run:
    python my_script.py
    
  • If you're working with a Python package (a directory containing an __init__.py file) and want to run it as a module, specify the package name. For example, if your package is named my_package and lives in your current working directory, run:
    python -m my_package
    
    Note: Make sure the package has a __main__.py file inside it—this is the script Python will execute when you run the package with -m.

Quick corrected command example

If you meant to run a script named main.py in your current directory, the proper command is:

python main.py

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 07:59:14