【问题标题】:How do you change file association for .py Python files in XP?如何在 XP 中更改 .py Python 文件的文件关联?
【发布时间】:2012-01-02 00:53:29
【问题描述】:

当我输入assoc .py 时,我得到.py=py_auto_file。 当我输入ftype py_auto_file 时,我得到py_auto_file="C:\Program Files\Adobe\Photoshop 7.0\Photoshop.exe" "%1"

我如何制作py_auto_file="C:\Python27"

【问题讨论】:

    标签: python cmd windows-xp file-association


    【解决方案1】:

    您应该将脚本名称 %1 和所有命令行参数 %* 传递给 Python27 可执行文件。为此,只需执行

    ftype py_auto_file="C:\Python27\bin\python.exe" "%1" %*
    

    【讨论】:

    • 这对我不起作用,但我在注册表中找到了 py_auto_file 条目并将 %* 添加到末尾,这解决了我的问题。这是我在运行推荐的 ftype 命令时收到的错误消息:找不到文件类型“py_auto_file”或没有与之关联的打开命令。
    • 如果你得到File type 'py_auto_file' not found or no open command associated with it.File type 'PythonFile' not found or no open command associated with it. 那么你应该尝试以管理员身份打开CMD
    【解决方案2】:

    看来 Photoshop 可能会识别 .py 文件格式,并将“py_auto_file”与 .py 扩展名相关联。

    您可以使用以下命令来定位 python 文件类型:

    C:\>ftype | findstr -i python
    Python.CompiledFile="C:\Python27\python.exe" "%1" %*
    Python.File="C:\Python27\python.exe" "%1" %*
    Python.NoConFile="C:\Python27\pythonw.exe" "%1" %*
    

    下一个命令显示来自我的系统的正确关联:

    C:\>assoc | findstr -i python
    .py=Python.File
    .pyc=Python.CompiledFile
    .pyo=Python.CompiledFile
    .pyw=Python.NoConFile
    

    您可以使用以下命令修复关联:

    assoc .py=Python.File
    assoc .pyc=Python.CompiledFile
    assoc .pyo=Python.CompiledFile
    assoc .pyw=Python.NoConFile
    

    【讨论】:

    • 谢谢!从 Pyton 2.5 升级到 2.7 后,我发现我有同样的问题,你的修复有帮助。现在我要删除 ftype-s "py_auto_file="D:\Python25\python.exe" "%1" %*" (与 pyc_auto_file 相同)。你知道如何删除它们吗? (当然试过 ftype /h :)
    • 我认为只是将它们设置为空白:ftype py_auto_file=。也可以通过regedit.exe在注册表中的HKEY_CLASSES_ROOT下直​​接删除。
    • 在windows 10下,如果您的注册表中有这个键,这个解决方案可能不起作用:HKEY_CLASSES_ROOT\Applications\python.exe只需删除这个键,它就会起作用,否则您需要修改“命令”条目在命令末尾包含 %* 。 link
    【解决方案3】:

    右击.py文件,设置默认程序为python.exe

    【讨论】:

    • 这不会传递命令行参数。如果这样做,则需要编辑注册表中的 py_auto_file 条目,以将 %* 添加到命令行的末尾。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-09
    • 1970-01-01
    • 2013-03-13
    • 1970-01-01
    • 2021-10-16
    • 1970-01-01
    相关资源
    最近更新 更多