How do I add Python 3.3 to Powershell?

前端 未结 2 695
一向
一向 2021-01-16 08:19

Hey I\'ve been trying to add Python 3.3 to windows powershell by repacing 27 with 33 in the path.

I tried to post a screenshot but turns out I need 10 rep so I\'ll j

相关标签:
2条回答
  • 2021-01-16 08:56

    The windows environment variable path is searched left to right. If the path to the 2.7 binaries is still in the variable, it will never find the 3.3 binaries, whose path you are appending to the end of the path variable.

    Also, you are not adding the path to PowerShell. The windows python binaries are what PowerShell considers legacy executables. What you are doing is telling the OS where executable binaries are. PowerShell knows how to use that info to execute those binaries without an absolute path. to do what you are looking to do in Powershell, try something like this

    $env:Path = ((($env:Path -split ";") | Where-Object { $_ -notlike "*Python*"}) -join ";") + ";C:\Python33"
    

    To make it persist, do this next

    [Environment]::SetEnvironmentVariable("Path",$env:Path, "User")
    
    0 讨论(0)
  • 2021-01-16 09:16

    Python 3.3 comes with PyLauncher (py.exe), which is installed in the C:\Windows directory (already on the path) and enables any installed Python to be executed via command line as follows:

    Windows PowerShell
    Copyright (C) 2009 Microsoft Corporation. All rights reserved.
    
    PS C:\> py
    Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:19:30) [MSC v.1600 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> ^Z
    
    PS C:\> py -2
    Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> ^Z
    
    PS C:\> py -3
    Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:19:30) [MSC v.1600 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    

    Note that the default Python if both 2.X and 3.X are installed is 2.X (3.X in later versions of Python), but this can be overridden with the -3 switch or the default changed by setting the PY_PYTHON environment variable.

    Also, if you install Python 3.3 last and register extensions, PyLauncher will be the default program for .py files and adding a special #! comment to to top of a script will specify the version of Python to use for the script. This allows you to have Python 2 and Python 3 files on the desktop and just double-click them to run the correct version of Python for that script.

    See Python Launcher for Windows in the Python 3 docs.

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