<div class="highlight highlight-source-fortran notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="integer function breaksf2py(arg)
  integer, intent(in) :: arg

  breaksf2py = 2 * arg
end"><pre class="notranslate"><span class="pl-k">integer</span> <span class="pl-k">function</span> <span class="pl-en">breaksf2py</span>(<span class="pl-v">arg</span>)
  <span class="pl-k">integer</span>, <span class="pl-k">intent</span>(<span class="pl-k">in</span>) <span class="pl-k">::</span> arg

  breaksf2py <span class="pl-k">=</span> <span class="pl-c1">2</span> <span class="pl-k">*</span> arg
<span class="pl-k">end</span></pre></div>
<p dir="auto">Compiling with <code class="notranslate">f2py -m foo breaksf2py.f90</code> works fine, but <code class="notranslate">f2py -m foo -h foo.pyf breaksf2py.f90</code> gives the following error for python3 f2py (tested with 3.2 and 3.3)</p>
<blockquote>
<p dir="auto">Reading fortran codes...<br>
Reading file 'breaksf2py.f90' (format:free)<br>
Post-processing...<br>
Block: foo<br>
Block: breaksf2py<br>
Post-processing (stage 2)...<br>
Saving signatures to file "./foo.pyf"<br>
Traceback (most recent call last):<br>
File "/usr/bin/f2py-3.2", line 24, in <br>
main()<br>
File "/usr/lib64/python3.2/site-packages/numpy/f2py/f2py2e.py", line 590, in main<br>
run_main(sys.argv[1:])<br>
File "/usr/lib64/python3.2/site-packages/numpy/f2py/f2py2e.py", line 361, in run_main<br>
postlist=callcrackfortran(files,options)<br>
File "/usr/lib64/python3.2/site-packages/numpy/f2py/f2py2e.py", line 286, in callcrackfortran<br>
pyf=crackfortran.crack2fortran(postlist)<br>
File "/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py", line 2749, in crack2fortran<br>
pyf=crack2fortrangen(block)+'\n'<br>
File "/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py", line 2517, in crack2fortrangen<br>
ret=ret+crack2fortrangen(g,tab,as_interface=as_interface)<br>
File "/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py", line 2561, in crack2fortrangen<br>
vars=vars2fortran(block,block['vars'],argsl,tab+tabchar, as_interface=as_interface)<br>
File "/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py", line 2711, in vars2fortran<br>
lst = true_intent_list(vars[a])<br>
File "/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py", line 2612, in true_intent_list<br>
if c:<br>
UnboundLocalError: local variable 'c' referenced before assignment</p>
</blockquote>
<p dir="auto">Python2 f2py can run <code class="notranslate">f2py-2.7 -m foo -h foo.pyf breaksf2py.f90</code> fine, and python3 f2py can compile the resulting pyf file with <code class="notranslate">f2py-3.3 -m foo -c foo.pyf breaksf2py.f90</code>.</p>
<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/numpy/ticket/1932" rel="nofollow">http://projects.scipy.org/numpy/ticket/1932</a> on 2011-08-12 by trac user josdekloe, assigned to <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/pearu/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/pearu">@pearu</a>.</em></p>
<p dir="auto">I have been trying to use the f2py routinely to build an interface around the ECMWF BUFR library. See <a href="http://code.google.com/p/pybufr-ecmwf/" rel="nofollow">http://code.google.com/p/pybufr-ecmwf/</a> for details. This works fine for the python 2.x versions.</p>
<p dir="auto">However, I also tried to add the possibility to use python3 and here I encountered some trouble. My python code converts properly to python3 using to 2to3 tool, but when I try to use the python3 version of f2py I encounter this error somewhere deep inside the f2py internals:</p>
<p dir="auto">Post-processing (stage 2)...<br>
Saving signatures to file "f2py_build/signatures.pyf"<br>
Traceback (most recent call last):<br>
File "./run_f2py_tool.py", line 11, in <br>
main()<br>
File "/usr/lib64/python3.2/site-packages/numpy/f2py/f2py2e.py", line 563, in main<br>
run_main(sys.argv[1:])<br>
File "/usr/lib64/python3.2/site-packages/numpy/f2py/f2py2e.py", line 342, in run_main<br>
postlist=callcrackfortran(files,options)<br>
File "/usr/lib64/python3.2/site-packages/numpy/f2py/f2py2e.py", line 279, in callcrackfortran<br>
pyf=crackfortran.crack2fortran(postlist)<br>
File "/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py", line 2693, in crack2fortran<br>
pyf=crack2fortrangen(block)+'\n'<br>
File "/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py", line 2465, in crack2fortrangen<br>
ret=ret+crack2fortrangen(g,tab)<br>
File "/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py", line 2505, in crack2fortrangen<br>
body=crack2fortrangen(block['body'],tab+tabchar)<br>
File "/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py", line 2465, in crack2fortrangen<br>
ret=ret+crack2fortrangen(g,tab)<br>
File "/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py", line 2505, in crack2fortrangen<br>
body=crack2fortrangen(block['body'],tab+tabchar)<br>
File "/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py", line 2465, in crack2fortrangen<br>
ret=ret+crack2fortrangen(g,tab)<br>
File "/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py", line 2506, in crack2fortrangen<br>
vars=vars2fortran(block,block['vars'],al,tab+tabchar)<br>
File "/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py", line 2655, in vars2fortran<br>
lst = true_intent_list(vars[a])<br>
File "/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py", line 2557, in true_intent_list<br>
if c:<br>
UnboundLocalError: local variable 'c' referenced before assignment<br>
ERROR: build of python wrapper failed<br>
the signatures file could not be found<br>
Traceback (most recent call last):<br>
File "./build_interface.py", line 1803, in <br>
BI.build()<br>
File "./build_interface.py", line 543, in build<br>
self.generate_python_wrapper(source_dir)<br>
File "./build_interface.py", line 1667, in generate_python_wrapper<br>
raise InterfaceBuildError<br>
<strong>main</strong>.InterfaceBuildError</p>
<p dir="auto">I any additional information is needed I would be happy to provide it.</p>