I plan to develop on both versions of Python 2.x and 3.x on windows7. Please tell me how it is possible to install them without conflict of versions and switch between them? Thank!

  • just install 2 versions of Python, and in Windows you can choose how to run the script and you can go to Python 2 or 3 - users

2 answers 2

Put the 2.x version, put the 3.x version.

After installation, make sure that py.exe used to run *.py files (and pyw.exe for *.pyw ):

 Π‘:\> assoc .py Π‘:\> ftype Python.File 

If you want to run the ΠΊΠΎΠΌΠ°Π½Π΄Π°.py .py file as a simple ΠΊΠΎΠΌΠ°Π½Π΄Π° , then add the .py extension to the %PATHEXT% environment variable.

If you want the selected version of Python to be used to run, then add a shebang at the very top of the Python script. For example, to choose Python 2.x:

 #!/usr/bin/env python2 

To select Python 3.x

 #!/usr/bin/env python3 

You can also explicitly specify the desired version at startup:

 C:\> py -3 \ΠΏΡƒΡ‚ΡŒ\ΠΊΠΎΠΌΠ°Π½Π΄Π°.py 

py -3.5 -m pip install win-unicode-console will run a command for Python 3.5 (for example, if you have both Python 3.6 and 3.5 installed).

There are several ways to customize the default version .

    1. Install the right Python versions, for example

      • 2.7.13
      • 3.5.3
      • 3.6.0

      When installing, tick Add Python xy to PATH if you need access to interpreters on the command line and do not uncheck the pip setting during customization.

    2. If development is conducted through PyCharm, then the interpreter can be selected directly in the settings File --> Setting --> Project --> Project Interpreter . Right there you can install packages for each interpreter. It is also possible to choose virtual environments when using virtualenv . PyCharm interpreter selection

    3. If you also need to call python via the command line. Create copies of python.exe in each of the installed instances (paths for sample typical installation on x64 machines), for example

      • in C:\Python27 from python.exe create a copy of python27.exe ;
      • in C:\Users\<username>\AppData\Local\Programs\Python\Python35 from python.exe create a copy of python35.exe ;
      • in C:\Users\<username>\AppData\Local\Programs\Python\Python35 from python.exe create a copy of python35.exe ;

      leave the original python.exe .

    4. After restarting the command line (restarting the computer --- any operation, when environment variables are updated), if all interpreters are contained in the PATH environment variable, commands will be available

      • D:\>python27 -V Python 2.7.13
      • D:\>python35 -V Python 3.5.3
      • D:\>python36 -V Python 3.6.0
    5. Now you can run scripts on the command line as follows:

      • D:\>python27 script.py
      • D:\>python35 script.py
      • D:\>python36 script.py
    6. Installing packages into each interpreter is possible via pip

      • pip2.7 install <имя ΠΏΠ°ΠΊΠ΅Ρ‚Π°>
      • pip3.5 install <имя ΠΏΠ°ΠΊΠ΅Ρ‚Π°>
      • pip3.6 install <имя ΠΏΠ°ΠΊΠ΅Ρ‚Π°>

    These pip instances are installed directly from Python , you do not need to manually copy them.