Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using multiple versions of Python

I have both Python 3.3 and Python 2.7 installed on my computer. The python 3.3 works fine, but when I try to run something using python 2.7, it is still referencing python 3.3.

For Example: if I type F:\Python33\python33.exe test1.py, it will run with 3.3 and work fine, but if I type F:\Python27\python27.exe test1.py it gives this error:

File "F:\PYTHON33\LIB\site.py", line 173
    file=sys.stderr)
        ^
SyntaxError: invalid syntax

Note: I have renamed the Python 2.7 and 3.3 .exe's to python27.exe and python33.exe respectively.

Any help would be appreciated, Thank you.

like image 514
JSoothe Avatar asked Dec 12 '13 22:12

JSoothe


People also ask

Can I have multiple versions of Python installed?

Switch between different versions 10. You can repeat the above steps and install different versions of python as you want and set priority and use them as needed. To use these python versions with IDE, go to your IDE's interpreter settings and there you can see the different versions of python available on your system.

Can multiple versions of Python run on the same machine?

If you wish to use multiple versions of Python on a single machine, then pyenv is a commonly used tool to install and switch between versions. This is not to be confused with the previously mentioned depreciated pyvenv script. It does not come bundled with Python and must be installed separately.

How do I run multiple Python versions in Windows?

Installing multiple versions of Python You can download the installer for Python 2.7 here. You can learn to install python2 on Windows here. You can download the installer for Python 3.10 here. You can learn to install python3 on Windows here.

How do I run multiple versions of Python on Linux?

Install that version using "make install". Install all other versions using "make altinstall". For example, if you want to install Python 2.5, 2.6 and 3.0 with 2.6 being the primary version, you would execute "make install" in your 2.6 build directory and "make altinstall" in the others.


1 Answers

Google search results have returned a few useful resources that answer your problem.

Python Docs

The Python Documentation (http://docs.python.org/3.3/using/windows.html#python-launcher-for-windows) gives a quick overview for running multiple versions on the same machine.

The first option would be to include your python version in the file you wish to execute using something along the lines of

#! python
Your code here

To execute in Python 2, or

#! python3
Your code here

For running the code in your Python 3 version. Then you would simply use "python yourscript.py" and the python version would be specified by the Python script.

StackExchange Sites

There are multiple other questions which may address the problem you are facing:
How to install both Python 2.x and Python 3.x in Windows 7

Or for Ubuntu 13: Ubuntu 13.04 Install and running Python 3 at the same time than Python 2.7.x

Or for Mac using Homebrew: How can I use Homebrew to install both Python 2 and 3 on Mac?
And a video reference for Mac without Homebrew: http://www.youtube.com/watch?v=c9LlK2iu7OA

like image 67
Robobenklein Avatar answered Sep 25 '22 20:09

Robobenklein