Python 2 and Python 3 - Running in Command Prompt

后端 未结 2 1930
终归单人心
终归单人心 2020-12-19 12:22

Having various projects in both Python 2 and Python 3 (with both python versions installed), I was looking for a more intuitive way to run scripts via Command Prompt than

相关标签:
2条回答
  • 2020-12-19 12:59

    Searching did not yield good results, so I thought I should share the process I took with anyone looking for this in the future.

    1. Make sure the Python 3 folder is present in the PATH environment variable.
    2. Locate the "python.exe" file in the Python 3 folder.
    3. Copy and Paste the "python.exe" file within the Python 3 folder.
    4. Rename the copied file to "python3" (or whatever you want the command to be).

    Now, when you input python3 script.py to Command Prompt, the script will run through the copied Python 3 file.

    Also, by copying python.exe (instead of renaming it) you allow other interpreters - such as PyCharm - to continue using their default "python.exe" path settings.

    I hope this helps!

    EDIT:

    A "symlink" has the same effect, but keeps things a bit tidier.

    0 讨论(0)
  • 2020-12-19 13:06

    If Python 2 and 3 are both installed and in the PATH variable, you can do:

    py -2

    or

    py -3

    0 讨论(0)
提交回复
热议问题