我想在Python文件中使用一些Fortran文件。我使用了命令C:\ Python27 \ python.exe setup.py build_ext --inplace --fcompiler = g95。我的setup.py文件包含以下代码:
import sys, os
extra_link_args = []
extra_link_args = ['-framework', 'accelerate']
from numpy.distutils.core import setup, Extension
opt_flags = ['-g', '-fbounds-check', '-I/usr/include/']
files1 = ['particle_solvers/fbsl_sim_fmod.f90',
'particle_solvers/fbsl_parts_fmod.f90',
'particle_solvers/fbsl_poisson_fmod.f90',
'particle_solvers/fbsl_convol_fmod.f90',
'particle_solvers/fbsl_lbfr_parts_fmod.f90',
'particle_solvers/fbsl_ltp_parts_fmod.f90',
'particle_solvers/fbsl_pusher_fmod.f90',
]
ext1 = Extension(name='_fbsl_f90',
sources=files1,
extra_compile_args=opt_flags,
extra_link_args=extra_link_args)
setup(name="_fbsl_f90",
version='0.1',
description="Hidden",
author="Hidden",
author_email='Hidden',
url='',
ext_modules=[ext1])
但是我遇到了以下错误:
g95.exe:f90: build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:211
&ef2pywrap, smooth_heaviside, r)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_smooth_heaviside' at (1)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:13
&nf2pywrap, t)
1
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:217
&nf2pywrap, f_exact_is_known, t)
2
Error: Differing types REAL(8) and LOGICAL(4) in formal arguments at (1) and (2)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:223
&inal_is_knownf2pywrap, f_exact_final_is_known)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_f_exact_final_is_known'
at (1)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:228
&2pywrap, f_exact_initial, eta_0, eta_1)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_f_exact_initial' at (1)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:235
&, t, eta_0, eta_1)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_f_exact' at (1)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:243
&rap, f_exact_final, eta_0, eta_1)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_f_exact_final' at (1)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:250
&_field_is_givenf2pywrap, velocity_field_is_given)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_velocity_field_is_given'
at (1)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:255
&ine_u0, x0, x1)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_affine_u0' at (1)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:262
&ine_u1, x0, x1)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_affine_u1' at (1)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:269
&p, quadratic_u0, t, x0, x1)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_quadratic_u0' at (1)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:277
&p, quadratic_u1, t, x0, x1)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_quadratic_u1' at (1)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:285
&w_0f2pywrap, bwd_affine_flow_0, t, x0, x1)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_bwd_affine_flow_0' at (1
)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:293
&w_1f2pywrap, bwd_affine_flow_1, t, x0, x1)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_bwd_affine_flow_1' at (1
)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:301
&ic_flow_0f2pywrap, bwd_quadratic_flow_0, t, x0, x1)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_bwd_quadratic_flow_0' at
(1)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:309
&ic_flow_1f2pywrap, bwd_quadratic_flow_1, t, x0, x1)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_bwd_quadratic_flow_1' at
(1)
In file build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90:317
&0, x1)
1
Error: Extra formal argument for 'f2pywrap_fbsl_sim_f90_bggk_a' at (1)
error: Command "C:\Users\QUENTIN\bin\g95.exe -fno-second-underscore -O -Ibuild\s
rc.win32-2.7 -IC:\Python27\lib\site-packages\numpy\core\include -IC:\Python27\in
clude -IC:\Python27\PC -c -c build\src.win32-2.7\_fbsl_f90-f2pywrappers2.f90 -o
build\temp.win32-2.7\Release\build\src.win32-2.7\_fbsl_f90-f2pywrappers2.o -fmod
=build\temp.win32-2.7\Release\ -Ibuild\temp.win32-2.7\Release\" failed with exit
status 1
我不明白为什么我会有这些额外的正式参数错误。我该如何解决这些问题?我正在使用Python 2.7和g95编译器在Windows 7上工作。
编辑:好的,为了简化,这里是我的Fortran代码示例:
module test_f90
implicit none
real *8 :: delta
contains
real*8 function test_f(r)
real*8, intent(in) :: r
test_f = 0.5*( 1 + erf(r/delta) )
end function
end module test_f90
当我使用命令C:\ Python27 \ python.exe setup.py build_ext --inplace --fcompiler = g95时,使用此setup.py文件:
import sys
extra_link_args = []
from numpy.distutils.core import setup, Extension
opt_flags = ['-g', '-fbounds-check', '-I/usr/include/']
files1 = ['test_fmod.f90',
]
ext1 = Extension(name='_test_f90',
sources=files1,
extra_compile_args=opt_flags,
extra_link_args=extra_link_args)
setup(name="_test_f90",
version='0.1',
description="test module",
author="Hidden",
author_email='Hidden',
url='',
ext_modules=[ext1])
我有这个由f2py生成的Fortran文件:
! -*- f90 -*-
! This file is autogenerated with f2py (version:2)
! It contains Fortran 90 wrappers to fortran functions.
subroutine f2pywrap_test_f90_test_f (test_ff2pywrap, r)
use test_f90, only : test_f
real(kind=8) r
real(kind=8) test_ff2pywrap
test_ff2pywrap = test_f(r)
end subroutine f2pywrap_test_f90_test_f
subroutine f2pyinittest_f90(f2pysetupfunc)
use test_f90, only : delta
interface
subroutine f2pywrap_test_f90_test_f (test_ff2pywrap, test_f, r)
real(kind=8) test_f
real(kind=8) r
real(kind=8) test_ff2pywrap
end subroutine f2pywrap_test_f90_test_f
end interface
external f2pysetupfunc
call f2pysetupfunc(delta,f2pywrap_test_f90_test_f)
end subroutine f2pyinittest_f90
但我仍然有这个错误:
g95.exe:f90: build\src.win32-2.7\_test_f90-f2pywrappers2.f90
In file build\src.win32-2.7\_test_f90-f2pywrappers2.f90:15
subroutine f2pywrap_test_f90_test_f (test_ff2pywrap, test_f, r)
1
Error: Extra formal argument for 'f2pywrap_test_f90_test_f' at (1)
error: Command "C:\Users\QUENTIN\bin\g95.exe -fno-second-underscore -O -Ibuild\s
rc.win32-2.7 -IC:\Python27\lib\site-packages\numpy\core\include -IC:\Python27\in
clude -IC:\Python27\PC -c -c build\src.win32-2.7\_test_f90-f2pywrappers2.f90 -o
build\temp.win32-2.7\Release\build\src.win32-2.7\_test_f90-f2pywrappers2.o -fmod
=build\temp.win32-2.7\Release\ -Ibuild\temp.win32-2.7\Release\" failed with exit
status 1
答案 0 :(得分:0)
很抱歉,正如声明的那样,f2py包装器支持似乎已被破坏 具有冲突签名的两次函数:前2个然后是3个正式参数。目前尚不清楚这个版本是否适合您,尽管您可能会发现通过前几个f2py ToC条目的示例很有用。
答案 1 :(得分:0)
它显示numpy未正确安装。您可以从以下链接下载numpy
https://pypi.org/project/numpy/
,或者您可以使用wheel文件安装numpy。
转到以下行下载合适的车轮。
https://www.lfd.uci.edu/~gohlke/pythonlibs/
在上面的链接中搜索numpy并安装它
答案 2 :(得分:-3)
https://sourceforge.net/projects/numpy/?source=typ_redirect 上面提到的链接有numpy下载的源文件。
然后在终端发出命令。
cd /home/Downloads/numpy-1.11.2
LS
sudo python setup.py install