【问题标题】:Is there a way to suppress the path of the py file when running python?有没有办法在运行python时抑制py文件的路径?
【发布时间】:2022-10-25 21:20:17
【问题描述】:

我在目录 ..\..\pydir 中有我所有的 python 文件,并在其他地方运行它们。目前我必须使用以下命令运行我的 python 文件:

python ..\..\pydir\test.py

我宁愿不必指定 python 文件的路径。我已将 ..\..\pydir 放入 PATH 环境变量中并尝试:

python test.py

但这不起作用,它找不到文件。是否有一些 python 路径可以用来引用 python 文件位置?

【问题讨论】:

    标签: python windows path


    【解决方案1】:

    Command line:

    调用 Python 时,您可以指定以下任何选项:

    python [-bBdEhiIOqsSuvVWx?] [-c command | -m module-name | script | - ] [args]
    

    <script>
    执行脚本中包含的 Python 代码,其中必须是文件系统路径(绝对或相对)引用 Python 文件、包含 __main__.py 文件的目录,或 一个包含__main__.py 文件的压缩文件。

    【讨论】:

      猜你喜欢
      • 2013-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多