FAQ Database Discussion Community


Importing a f2py .pyd from an explicit path (Bad magic number ImportError)

python,f2py
I have built a .pyd module from some fortran code via f2py, which we can call foo.pyd. I want to import this into a python code, which we can call main.py. When I import as: import foo everything works fine. However, because this python will eventually be 'frozen' into an...

f2py with OMP: can't import module, undefined symbol GOMP_*

python,numpy,fortran,openmp,f2py
I was hoping to use openmp to speed up my Fortran code that I run through f2py. However, after compiling succesfully, I can't import the module in Python. For a Fortran95 module like this: module test implicit none contains subroutine readygo() real(kind = 8), dimension(10000) :: q !$OMP WORKSHARE q...

Why is my Fortran code wrapped with f2py using so much memory?

python,memory-management,fortran,out-of-memory,f2py
I am trying to calculate all the distances between approximately a hundred thousand points. I have the following code written in Fortran and compiled using f2py: C 1 2 3 4 5 6 7 C123456789012345678901234567890123456789012345678901234567890123456789012 subroutine distances(coor,dist,n) double precision coor(n,3),dist(n,n) integer n double precision x1,y1,z1,x2,y2,z2,diff2 cf2py intent(in) :: coor,dist cf2py...

How can I get info on run time errors for Python modules built with f2py

python,numpy,fortran,f2py
Edit 3/6: Sorry, this was a false alarm. It seems to be working now. I believe the -g flag on gfortran and --debug-capi are sufficient after all to generate line numbers for GDB (gnu debugger). I will make a short answer summarizing how to do this in case it is...

Expose both “in,out” and “inplace” versions of subroutine with f2py

python,f2py
I am using f2py to integrate some Fortran77 routines into my python module but can't settle on a good way to solve the following problem. My Fortran routines destroy all input arrays during the course of computation. I'd like to offer the user both the option to use the memory...

Disabling fp-model strict when using ifort with f2py

python,numpy,optimization,fortran,f2py
I'm using f2py to offload performance critical sections of my python code to fortran. I have two fortran compilers, gfortran and ifort. Since the code I run will be on intel processors, ifort is usually faster. But for the most critical part of my code, I observe the opposite, with...

make: f2py: No such file or directory

python,make,f2py
I am running Mac OS X 10.10. I have some python code I have inherited. I need to run "make" in a certain directory, because I get a warning when I run my python script along the lines of WARNING: failed to import test1lib. Please run make in /this/directory/ So...

f2py does not return dimension(N,3) to python

python,f2py
I'm working with f2py and I'm quite stuck. I have a function in fortran: !f90 subroutine f( !args implicit none; double precision, dimension(N, 3):: fMatrix; !f2py double precision, dimension(N,3), intent(out, c) :: fMatrix !Stuff happens here end subroutine force I've used f2py -c -m moduleName file.f90 to convert it to...

defining arrays in fortran after dynamic size declaration

python,arrays,fortran,f2py
I am new to Fortran and what I want is that my size of the matrix depends on if N is even or odd, Naively I would try something like below, but this doesnt compile, if I remove the if statement it works fine though, subroutine f(fMatrix,oMatrix,N) implicit none; integer,intent(in)::N...

f2py: Pre-allocating arrays as input for Fortran subroutine

python,numpy,fortran,f2py
Here is a minimalized snippet from a Fortran subroutine that i want to call in python. The task is very simple. The first time the code is called a value is assigned to the first entry of the array iwk. The subroutine is then called a second time, the expected...

Segmentation fault after removing debug printing

python,fortran,f2py
I have a (for me) very weird segmentation error. At first, I thought it was interference between my 4 cores due to openmp, but removing openmp from the equation is not what I want. It turns out that when I do, the segfault still occurs. What's weird is that if...

F2PY cannot see module-scope variables

python,numpy,fortran,fortran90,f2py
Sorry about being new to both Fortran 90 and f2py. I am using Windows 64 bit, Python 3.4 64 bit, gfortran. Numpy version is 1.9.1, and I commented the "raise NotImplementedError("Only MS compiler supported with gfortran on win64")" in the gnu.py, as instructed on this link: http://scientificcomputingco.blogspot.com.au/2013/02/f2py-on-64bit-windows-python27.html I have a...