How to use multiple versions of Python without uninstallation

前端 未结 15 1544
醉梦人生
醉梦人生 2021-02-05 14:11

I am faced with a unique situation, slightly trivial but painful.

I need to use Python 2.6.6 because NLTK is not ported to Python 3 (that\'s what I could gather).

相关标签:
15条回答
  • 2021-02-05 14:59

    Take a look on WinPython, a nice portable/installable python distribution for Windows.

    Portable: preconfigured, it should run out of the box on any machine under Windows (without any requirement) and the folder containing WinPython can be moved to any location (local, network or removable drive) with most of the application settings

    Flexible: one can install (or should I write "use" as it's portable) as many WinPython versions as necessary (like isolated and self-consistent environments), even if those versions are running different versions of Python (2.7, 3.3) or different architectures (32bit or 64bit) on the same machine

    It also allows you to register and unregister easily a given python version as the system default one.

    But even working as portable, you can make a shortcut of the python executable and put it somewhere in your path. Just name the shortcuts of different versions different names. Then you can just use:

    python_3_64bit_shortcut your_program.py
    
    0 讨论(0)
  • 2021-02-05 15:00

    Use Pythonbrew, its super easy to install, and allows you to very easily install, and switch between, or temporarily use different python versions safely.

    Once pythonbrew is installed:

    #to install new python versions is as simple as:
    pythonbrew install 2.7.2 3.2
    #to use a particular version in the current shell:
    pythonbrew use 3.2
    #to uninstall:
    pythonbrew uninstall 2.7.2
    
    0 讨论(0)
  • 2021-02-05 15:00

    You can use py launcher, that is installed with python distributable:

    py -2    # default python 2
    py -2.7  # specifically python 2.7
    py -3    # default python 3
    py -3.7  # specifically python 3.7
    

    If you need to execute a script with a specific version you can do following:

    py -3.7 my_script.py
    
    0 讨论(0)
  • 2021-02-05 15:02

    You simply install multiple versions in separate directories, and then you run the python program with the Python version you want to use. Like so:

    C:\Python26\Python.exe thescript.py
    

    Or similar.

    What virtualenv does is that it gives you many separate "virtual" installations of the same python version. That's a completely different issue, and hence it will not help you in any way.

    0 讨论(0)
  • 2021-02-05 15:09

    Use virtualenv, which allows you to create dynamic python environments. Check out python's page here.

    http://pypi.python.org/pypi/virtualenv

    Related answered question on installing packages inside virtualenv on windows (as opposed to system-wide) Can I install Python windows packages into virtualenvs?

    0 讨论(0)
  • 2021-02-05 15:11

    I do use at least 3 or 4 versions of Python on my machines (Windows). The installers from http://python.org/ automatically placed them in:

    c:\Python26
    c:\Python27
    c:\Python32
    

    and

    c:\Python24
    

    on one machine. I mostly use Python 2.7 because some applications use wxPython and also for the older console code. This python.exe was not renamed. By the way, the Python 2.7 also supports collections.Counter.

    The c:\Python26 and c:\Python24 are not included in my PATH. In c:\Python32\, the exe was renamed to py.exe. This way, python some.py starts Python 2.7, and py another.py starts Python 3.2.

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