Why doesn't virtualenv on Windows associate .py/.pyw/.pyo/.pyc files with virtualenv's version of Python executables?

前端 未结 4 1318
野性不改
野性不改 2021-01-02 15:12

What is the reason virtualenv does not associate .py(w) files with virtualenv\'s version of Python executables? This seems like an ideal task for virtualenv on

4条回答
  •  臣服心动
    2021-01-02 16:01

    The Python launcher supports custom commands. Create a py.ini file in $env:LOCALAPPDATA with a section like this:

    [commands]
    venvpython=C:\Path\To\Virtualenv\Scripts\python.exe
    

    Now, you can use venvpython in the #! line of your script:

    #!venvpython
    import sys
    print(sys.executable)
    

提交回复
热议问题