How to make Python 2.7 and Python 3.1 coexist in Windows 7?

I have Python 3.1 installed on my desktop, but now I need Python 2.7 to run CQL. I installed both versions of Python in my box, type "Python", version 3.1 has been released. but when I tried to use version 2.7, indicating the path to the executable 2.7, it was again called with some errors, as follows:

C:\Python27>.\python.exe Traceback (most recent call last): File "C:\Python31\lib\site.py", line 56, in <module> import os File "C:\Python31\lib\os.py", line 380, in <module> from _abcoll import MutableMapping # Can't use collections (bootstrap) File "C:\Python31\lib\_abcoll.py", line 54 class Hashable(metaclass=ABCMeta): ^ SyntaxError: invalid syntax 

What should I do to make both versions of Python work for me?

+4
source share
1 answer

Use cygwin to have a nice bash environment that allows you to easily run python scripts using specific interpreters or use virtualenv to create environments based on specific interpolations:

 > mkdir project > cd project > C:\Python27\Scripts\virtualenv.exe -p C:\Python32\python.exe . > Scripts\activate 

At this point, your env was installed in this project, and python input will start python3.2
You would have typed deactivate to return to normal env. With this approach, you can either configure this on a per-project basis to manage version dependencies between python projects, or make it more global for each python version as a whole. To you.

On nix-based systems, we have the luxury of the โ€œshebangโ€ line at the top of the script to tell which interpreter to use. Windows only has file extension associations via the GUI, and you must be explicit on the command line in the form python <script.py>

+3
source

Source: https://habr.com/ru/post/1413813/


All Articles