How to Install Both Python 2.X and Python 3.X in Windows

How to I get Python 2.x and 3.x to co-exist?

I'm not sure I understand your question, but I'll take a shot. I'm also assuming you're on Windows.

It's simple -- just install both. They will install to different directories, create different start menu folders, etc. I'd also reccomend PyWin32 for the PythonWin editor installed in both 2.7 and 3.2,

  • http://sourceforge.net/projects/pywin32/files/pywin32/Build216/pywin32-216.1.win32-py3.2.exe/download &
  • http://sourceforge.net/projects/pywin32/files/pywin32/Build216/pywin32-216.win32-py2.7.exe/download

If you mean how do you write one script that works with either Python 2 or Python 3, look at http://docs.python.org/library/2to3.html

How to use pip with Python 3.x alongside Python 2.x

The approach you should take is to install pip for Python 3.2.

You do this in the following way:

$ curl -O https://bootstrap.pypa.io/get-pip.py
$ sudo python3.2 get-pip.py

Then, you can install things for Python 3.2 with pip-3.2, and install things for Python 2-7 with pip-2.7. The pip command will end up pointing to one of these, but I'm not sure which, so you will have to check.

Using both Python 2.x and Python 3.x in IPython Notebook

A solution is available that allows me to keep my MacPorts installation by configuring the Ipython kernelspec.

Requirements:

  • MacPorts is installed in the usual /opt directory
  • python 2.7 is installed through macports
  • python 3.4 is installed through macports
  • Ipython is installed for python 2.7
  • Ipython is installed for python 3.4

For python 2.x:

$ cd /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin
$ sudo ./ipython kernelspec install-self

For python 3.x:

$ cd /opt/local/Library/Frameworks/Python.framework/Versions/3.4/bin
$ sudo ./ipython kernelspec install-self

Now you can open an Ipython notebook and then choose a python 2.x or a python 3.x notebook.

Choose your python!

Using pip version with Python 3.x alongside Python 2.x on Windows

You will want to make sure you have the correct Anaconda environment activated, which it looks like you have in this case.

conda env list   # Display the list of conda environments

Sample Image

In the Windows Command Prompt you should just need to use:

activate py35   # Or whatever your Python 3.5 environment is called. (Mine is root)
pip install pymssql

Instead of pip-3.5.

To install it in another environment (mine is called py27):

activate py27
pip install pymssql

I successfully used this command in both my Python 2.7 and 3.5 Anaconda environments.

To go back to your primary environment (root), just type activate without an environment name after it

Using pip on Windows installed with both python 2.7 and 3.5

You will have to use the absolute path of pip.

E.g: if I installed python 3 to C:\python35, I would use:
C:\> python35\Scripts\pip.exe install packagename

Or if you're on linux, use pip3 install packagename

If you don't specify a full path, it will use whichever pip is in your path.



Related Topics



Leave a reply



Submit