Scientific Python on Windows

After several experiments, I really think that WinPython is the best option for Windows when working with Scientific Python. Are you ready for Python?

Why WinPython?

The are several alternatives for installing Python on Windows out there. However, if you’re working with scientific python packages like NumPy, SciPy, Matplotlib, OpenCV, etc, most of the times you’ll end up configuring Windows PATH, installing several Microsoft Visual C++ versions, compiling complicate things…we don’t want that! It also includes full support for PyQt!

WinPython is a standalone version of Python that brings a lot of stuff already installed and ready to use. Moreover you don’t mess with Windows PATH and you can install as many versions as you want (both Python 2 and 3!!).

How it works?

  1. Download WinPython;
  2. Extract the zip for whatever folder you want. Personally, I have a folder called “Python” where I keep both Python2 and Python3 installations;winpython_folders
  3. Navigate to the installation folder, for example “WinPython-32bit-2.7.10.3” and you’ll find some scripts inside it. “WinPython Command Prompt.exe” is the one you want. Just double click it and you have a working Python console! Simple as that!

OpenCV (with FFMPEG) support

WinPython doesn’t ship with OpenCV. However is very simple to install it.

For Python 2

  1. Download OpenCV for Windows (http://opencv.org/downloads.html)
    Note: I only tried with OpenCV versions 3.0 and 3.1 but it should work with version2 also.
  2. Run the installer which essentially extracts content for a specified folder (put it wherever you want, it really doesn’t matter since you’ll remove it later on);
  3. Then navigate to this folder and go to “opencv\build\python\2.7”. Inside this folder you’ll find both x64 and x86 options. Choose it accordingly to your WinPython installation;
  4. Inside the previous folder you’ll find a single file “cv2.pyd”. Copy it to “Python\WinPython-32bit-2.7.10.3\python-2.7.10\Lib\site-packages” where “Python\WinPython-32bit-2.7.10.3” is the folder where you installed WinPython.

For Python 3

Unfortunately, at the time of this writing,  OpenCV does not include binaries for Python 3. But wait! There is a simple workaround too!

  1. Go to http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv. Here you’ll find a list of pre-compiled binaries for Python on Windows. Download the wheel accordingly to your WinPython installation. For example, “opencv_python-3.1.0-cp34-none-win_amd64.whl” means OpenCV 3.1.0, Python 3.4 64 bits;
  2. Open you Python console by calling “WinPython Command Prompt.exe” from your WinPython installation;
  3. On the console, change dir to where you downloaded the OpenCV binary;
  4. Run:
    pip install opencv_python-3.1.0-cp34-none-win_amd64.whl
  5. And that’s it!

FFMPEG support

Finally, if you want OpenCV with ffmpeg support:

  1. Navigate to “opencv\build\bin” (inside the OpenCV extracted folder);
  2. You’ll find both “opencv_ffmpeg310_64.dll” and “opencv_ffmpeg310.dll” (this may vary depending on OpenCV version), choose it accordingly to your WinPython installation;
  3. Copy the corresponding file to “Python\WinPython-32bit-2.7.10.3\python-2.7.10\”;
  4. And that’s it!

Final steps

Remove the OpenCV folder if you want.

Remove the downloads of WinPython and OpenCV if you want.

One thought on “Scientific Python on Windows

Leave a comment