f2py: Running Fortran code in Python on Windows

F2PY is a great package allowing you to run a lot of Fortran code from Python. Fortran 77 code naturally has a high chance of success.
Fortran 90 code can also work, but very elaborate Fortran 90 code may not work.

On Linux, all you need to do is

sudo apt-get install python-numpy gfortran

On Windows, the f2py setup is more involved. You need the MinGW compiler and to modify your system path. I assume here that you have Anaconda Python with Numpy 1.9 installed already. This procedure was used on a 64-bit Windows 10 machine.

1) install MinGW-W64 with the setup settings:
Version 4.9.2 (or newer)
Architecture: x86_64
Threads: posix
Exception: seh
Build revision: 2

2) Insert the mingw bin path to your system path. I did this permanently by going into Windows Advanced System Settings, Environment Variables, System variables, Path, and at the end put:

C:\Program Files\mingw-w64\x86_64-4.9.2-posix-seh-rt_v4-rev2\mingw64\bin

check to see if that’s where your gfortran.exe is at.

test your installation by say using the lowtran7 code.
Following the instructions there, you should get a lowtran7.pyd file that is invoked when running
python pylowtran7.py and you’ll see a plot of atmospheric loss.

Note: If you get the “NotImplementedError: Only MS compiler supported with gfortran on win64″, that is still occurring with Numpy 1.9.2, but has been patched in the master branch (to be released in a future version of Numpy). You can patch this yourself in c:\Anaconda\Lib\site-packages\numpy\distutils\fcompiler\gnu.py on line 337. Comment out the
raise NotImplementedError(...)
and simply replace with the word
and you’ll be working.

Lowtran7 example output in the Arctic looking near zenith.
Lowtran7 example output in the Arctic looking near zenith.

Compiling Octave 4.0 on Ubuntu 14.04

sudo apt-get install gawk gfortran gperf flex libbison-dev libqhull-dev libglpk-dev libcurl4-gnutls-dev libfltk1.3-dev librsvg2-dev libqrupdate-dev libgl2ps-dev libosmesa6-dev libarpack2-dev libqscintilla2-dev

Note, I may have missed something since I didn’t do the above from a clean install (I may have something installed that you’re missing).

Checkout the Octave 3.8 compiling page for hints about what packages you might be missing if you get errors, and leave a comment to let others know.


./configure --enable-jit --prefix=/opt/octave4.0

This resulted in:

  Build Octave GUI:                   yes
  JIT compiler for loops:             yes
  Build Java interface:               yes
  Do internal array bounds checking:  no
  Build static libraries:             no
  Build shared libraries:             yes
  Dynamic Linking:                    yes (dlopen)
  Include support for GNU readline:   yes
  64-bit array dims and indexing:     no
  OpenMP SMP multithreading:          yes
  Build cross tools:                  no

With the only Warning being about JAVA_HOME not defined.
Then I typed


Bluetooth on the Intel Edison

Here are some quick notes for using Bluetooth on the Intel Edison. These tips should also prove handy for Bluetooth on the Raspberry Pi and Beaglebone.

Please refer to the Intel Edison Bluetooth manual.

# opkg install bluez5 bluez-hcidump

Of course, on the Raspberry Pi and Beaglebone, most people are using Debian/Ubuntu so type apt-get instead of opkg.

Some people prefer BlueZ4 over Bluez5, in part because some features were moved around or descoped in BlueZ5, but BlueZ5 can be easier to work with otherwise. The Intel Edison Bluetooth manual uses BlueZ5 to play sound from the Edison over Bluetooth headphones, to send text with Android phones, etc. Check out the manual!

List Wireless devices:
$ rfkill list
The listing will include:
 2: bcm43xx Bluetooth: bluetooth
    Soft blocked: yes
    Hard blocked: no
Unblock Bluetooth devices:
$ rfkill unblock bluetooth

We now see another device:

3: hci0: bluetooth
   Soft blocked: no
   Hard blocked: no
List Bluetooth Device UUID
$ hcitool dev
You should see

and your device UUID.

Enable BLuetooth
# hciconfig hci0 up
Use bluez interface

Please refer to the Intel Edison Bluetooth manual.

LCPFCT solver–accessible from Python

LCPFCT from Python
LCPFCT from Python


The venerable NRL Flux-Corrected Transport algorithm for Solving Generalized Continuity Equations has been cited in hundreds of publications and is used by myself in my PhD thesis and general research.

I have updated the syntax of the original Fortran code slightly to fit with the FORTRAN 77 standard (not changing algorithm behavior, only syntactical correctness). As a byproduct, I have made demo plotting code available in Python that uses f2py to make the LCPFCT run from Python at an order 50x speedup overall since you don’t have to write output to disk and then read it back in via a custom parsing algorithm.

Goldwave 5.x on Linux WINE

You will need a 32-bit winearch. Typically your default .wine directory is 64-bit. Let’s leave that alone and create a new 32-bit wineprefix and setup Goldwave 5. (Goldwave 6 is not WINE compatible as of WINE 1.6).

Download Goldwave 5 to your ~/Downloads directory.

Then, from Terminal,

WINEPREFIX=~/.wine32 WINEARCH=win32 winetricks wmp10

WINEPREFIX=~/.wine32 wine ~/Downloads/gwave5*.exe

Once you’ve installed Goldwave 5, press the F11 key to open Control Properties, then select the System tab, and click the “Use DirectSound AP” radio button. You can test your setup by clicking the Device tab, and the Test playback button, you should hear a brief test tone. Click OK to save this setting.

You should be able to create new/save/play sound files (this gives Goldwave 5 a WINE Silver rating I think)


At this time, Goldwave 6 is not compatible with WINE that I know of. I get the following errors from Goldwave 6 after installing and trying to run Goldwave 6 in a 64-bit Windows 7 wineprefix:

err:module:import_dll Library BTHPROPS (which is needed by L"C:\\Program Files\\GoldWave\\GoldWave.exe") not found

err:module:import_dll Library BLUETOOTHAPIS (which is needed by L"C:\\Program Files\\GoldWave\\GoldWave.exe") not found

err:module:LdrInitializeThunk Main exe initialization for L"C:\\Program Files\\GoldWave\\GoldWave.exe" failed, status c0000135

Compiling OpenCV3 with extra contributed modules

This procedure is for OpenCV3 beta.
Some of the functions you might want like cv2.createBackgroundSubtractorGMG are not in the standard OpenCV 3 package at this time. The newer functions by design go into the opencv_contrib repository.

If you’re comfortable with the previous procedure, you might be ready to try adding these packages.

CRITICAL POINT: you must have the space between -D OPENCV_EXTRA_MODULES_PATH= for this to work, or it will silently ignore the opencv_contrib modules.

I will assume you have the prereqs installed already.

After the cmake command, scroll back up and check that you see something like (for example, look for bgsegm, that’s one of the opencv_contrib modules)

OpenCV modules:
 -- To be built: core imgproc imgcodecs videoio highgui xobjdetect adas video bgsegm bioinspired flann ml features2d calib3d ccalib face text datasets line_descriptor objdetect optflow photo reg rgbd saliency shape xfeatures2d stitching superres surface_matching videostab ximgproc xphoto python2 tracking ts
 -- Disabled: java world
 -- Disabled by dependency: -
 -- Unavailable: androidcamera cuda cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaoptflow cudastereo cudawarping cudev python3 viz cvv matlab

cd /tmp

git clone --branch 3.0.0-beta --depth 1 https://github.com/Itseez/opencv.git

git clone --branch 3.0.0-beta --depth 1 https://github.com/itseez/opencv_contrib

cd /tmp/opencv

mkdir release
cd release

cmake -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules/ -DBUILD_TIFF=ON -DBUILD_opencv_java=OFF -DWITH_CUDA=OFF -DENABLE_AVX=ON -DWITH_OPENGL=ON -DWITH_OPENCL=ON -DWITH_IPP=ON -DWITH_TBB=ON -DWITH_EIGEN=ON -DWITH_V4L=ON -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=$(python3 -c "import sys; print(sys.prefix)") -DPYTHON_EXECUTABLE=$(which python3) -DPYTHON_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") -DPYTHON_PACKAGES_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") ..
# the -j6 is for compilation only, to use up to 6 threads. It has no effect on the compiled opencv code execution
make -j6
make install

Once installed, you should be able to from within Python type:

import cv2
x = cv2.bgsegm.createBackgroundSubtractorGMG()