<p dir="auto">This is a copy <a href="http://projects.scipy.org/numpy/ticket/1932" rel="nofollow">http://projects.scipy.org/numpy/ticket/1932</a> since that one seems no longer in use and no one responded to it in almost 2 years, even though I posted a patch that solves the problem....</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)... Saving signatures to file "f2py_build/signatures.pyf" Traceback (most recent call last):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="File &quot;./run_f2py_tool.py&quot;, line 11, in &lt;module&gt;

    main()

File &quot;/usr/lib64/python3.2/site-packages/numpy/f2py/f2py2e.py&quot;, line 563, in main

    run_main(sys.argv[1:])

File &quot;/usr/lib64/python3.2/site-packages/numpy/f2py/f2py2e.py&quot;, line 342, in run_main

    postlist=callcrackfortran(files,options)

File &quot;/usr/lib64/python3.2/site-packages/numpy/f2py/f2py2e.py&quot;, line 279, in callcrackfortran

    pyf=crackfortran.crack2fortran(postlist)

File &quot;/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py&quot;, line 2693, in crack2fortran

    pyf=crack2fortrangen(block)+'\n'

File &quot;/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py&quot;, line 2465, in crack2fortrangen

    ret=ret+crack2fortrangen(g,tab)

File &quot;/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py&quot;, line 2505, in crack2fortrangen

    body=crack2fortrangen(blockbody?,tab+tabchar)

File &quot;/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py&quot;, line 2465, in crack2fortrangen

    ret=ret+crack2fortrangen(g,tab)

File &quot;/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py&quot;, line 2505, in crack2fortrangen

    body=crack2fortrangen(blockbody?,tab+tabchar)

File &quot;/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py&quot;, line 2465, in crack2fortrangen

    ret=ret+crack2fortrangen(g,tab)

File &quot;/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py&quot;, line 2506, in crack2fortrangen

    vars=vars2fortran(block,blockvars?,al,tab+tabchar)

File &quot;/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py&quot;, line 2655, in vars2fortran

    lst = true_intent_list(vars[a])

File &quot;/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py&quot;, line 2557, in true_intent_list

    if c:"><pre class="notranslate"><code class="notranslate">File "./run_f2py_tool.py", line 11, in &lt;module&gt;

    main()

File "/usr/lib64/python3.2/site-packages/numpy/f2py/f2py2e.py", line 563, in main

    run_main(sys.argv[1:])

File "/usr/lib64/python3.2/site-packages/numpy/f2py/f2py2e.py", line 342, in run_main

    postlist=callcrackfortran(files,options)

File "/usr/lib64/python3.2/site-packages/numpy/f2py/f2py2e.py", line 279, in callcrackfortran

    pyf=crackfortran.crack2fortran(postlist)

File "/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py", line 2693, in crack2fortran

    pyf=crack2fortrangen(block)+'\n'

File "/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py", line 2465, in crack2fortrangen

    ret=ret+crack2fortrangen(g,tab)

File "/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py", line 2505, in crack2fortrangen

    body=crack2fortrangen(blockbody?,tab+tabchar)

File "/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py", line 2465, in crack2fortrangen

    ret=ret+crack2fortrangen(g,tab)

File "/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py", line 2505, in crack2fortrangen

    body=crack2fortrangen(blockbody?,tab+tabchar)

File "/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py", line 2465, in crack2fortrangen

    ret=ret+crack2fortrangen(g,tab)

File "/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py", line 2506, in crack2fortrangen

    vars=vars2fortran(block,blockvars?,al,tab+tabchar)

File "/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py", line 2655, in vars2fortran

    lst = true_intent_list(vars[a])

File "/usr/lib64/python3.2/site-packages/numpy/f2py/crackfortran.py", line 2557, in true_intent_list

    if c:
</code></pre></div>
<p dir="auto">UnboundLocalError?: local variable 'c' referenced before assignment ERROR: build of python wrapper failed the signatures file could not be found Traceback (most recent call last):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="File &quot;./build_interface.py&quot;, line 1803, in &lt;module&gt;

    BI.build()

File &quot;./build_interface.py&quot;, line 543, in build

    self.generate_python_wrapper(source_dir)

File &quot;./build_interface.py&quot;, line 1667, in generate_python_wrapper

    raise InterfaceBuildError?"><pre class="notranslate"><code class="notranslate">File "./build_interface.py", line 1803, in &lt;module&gt;

    BI.build()

File "./build_interface.py", line 543, in build

    self.generate_python_wrapper(source_dir)

File "./build_interface.py", line 1667, in generate_python_wrapper

    raise InterfaceBuildError?
</code></pre></div>
<p dir="auto">main.InterfaceBuildError?</p>
<p dir="auto">I any additional information is needed I would be happy to provide it.</p>
<p dir="auto">I install NumPy from source. I recently checked out the 1.16.1 tag and when I imported the built and installed NumPy, I get</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ImportError: Something is wrong with the numpy installation. While importing we detected an older version of numpy in ['/home/tbekolay/.virtualenvs/pytest/lib/python3.7/site-packages/numpy']. One method of fixing this is to repeatedly uninstall numpy until none is found, then reinstall this version."><pre class="notranslate"><code class="notranslate">ImportError: Something is wrong with the numpy installation. While importing we detected an older version of numpy in ['/home/tbekolay/.virtualenvs/pytest/lib/python3.7/site-packages/numpy']. One method of fixing this is to repeatedly uninstall numpy until none is found, then reinstall this version.
</code></pre></div>
<p dir="auto">The directory pointed there is the directory of the currently installed NumPy. When I looked in <code class="notranslate">numpy/core/__init__.py</code>, I saw the other error message, which includes the <code class="notranslate">git clean -xdf</code> command. When I ran this in the git repo, I could build and install successfully. So I believe it would be useful for both of those cases to include the instructions that normally occur when <code class="notranslate">multiarray</code> can't be imported. (line 19 in <code class="notranslate">core/__init__.py</code>).</p>
<p dir="auto">Alternatively, we could detect if the path given by <code class="notranslate">sys.modules['numpy'].__path__</code> is the same as the one we would get by looking at <code class="notranslate">__file__</code> to determine if it is a weird version error or just an old <code class="notranslate">multiarray</code> sticking around.</p>
<h3 dir="auto">Reproducing code example:</h3>
<p dir="auto">Check out an old release like 1.15.1 and build from source. Check out 1.16.1, build again and install. Then</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span></pre></div>
<h3 dir="auto">Error message:</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ImportError: Something is wrong with the numpy installation. While importing we detected an older version of numpy in ['/home/tbekolay/.virtualenvs/pytest/lib/python3.7/site-packages/numpy']. One method of fixing this is to repeatedly uninstall numpy until none is found, then reinstall this version."><pre class="notranslate"><code class="notranslate">ImportError: Something is wrong with the numpy installation. While importing we detected an older version of numpy in ['/home/tbekolay/.virtualenvs/pytest/lib/python3.7/site-packages/numpy']. One method of fixing this is to repeatedly uninstall numpy until none is found, then reinstall this version.
</code></pre></div>
<h3 dir="auto">Numpy/Python version information:</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="1.16.1 3.7.2+ (default, Feb  2 2019, 14:31:48) 
[GCC 8.2.0]"><pre class="notranslate"><code class="notranslate">1.16.1 3.7.2+ (default, Feb  2 2019, 14:31:48) 
[GCC 8.2.0]
</code></pre></div>