问题描述
更新.现在,我在 .pyf
文件上运行 f2py
,该文件应生成 _glmnet
模块.
UPDATE Getting close. Now I'm running f2py
on the .pyf
file that should generate the _glmnet
module.
我使用以下命令构建包 python-glmnet 数据包.
I build the package python-glmnet packet with the following command.
python setup.py config_fc --fcompiler=gnu95
--f77flags='-fdefault-real-8'
--f90flags='-fdefault-real-8' build
但是当我导入模块时,出现此错误:
But when I import the module I get this error:
如何导入该模块?
glmnet目录还包含一个以以下内容开头的 glmnet.pyf
文件:
The glmnet directory also contains a glmnet.pyf
file that begins with the following:
! -*- f90 -*-
! Note: the context of this file is case sensitive.
python module _glmnet ! in
interface ! in :_glmnet
subroutine elnet(ka,parm,no,ni,x,y,w,jd,vp,ne,nx,nlam,flmin,ulam,thr,isd,lmu,a0,ca,ia,nin,rsq,alm,nlp,jerr) ! in :glmnet:glmnet.f
integer optional :: ka=1 ! Use covariance updates over naive by default
real*8 :: parm
integer intent(hide),check(shape(x,0)==no),depend(x) :: no=shape(x,0)
integer intent(hide),check(shape(x,1)==ni),depend(x) :: ni=shape(x,1)
real*8 dimension(no,ni) :: x
real*8 dimension(no),depend(no) :: y
real*8 dimension(no),depend(no) :: w
integer dimension(*) :: jd
real*8 dimension(ni),depend(ni) :: vp
integer optional,depend(x) :: ne=min(shape(x,1), nx)
integer :: nx
integer optional,check((flmin < 1.0 || len(ulam)==nlam)),depend(flmin,ulam) :: nlam=len(ulam)
real*8 :: flmin
real*8 dimension(nlam) :: ulam
real*8 :: thr
integer optional :: isd=1 ! Standardize predictors by default
更新
在哪里可以找到此 _glmnet
模块?如下所示,它是否包含在glmnet.pyf文件中?我尝试将此glment文件夹添加到我的 PYTHONPATH
中,但这没有任何改变.
Where can I find this _glmnet
module? Is it contained in the glmnet.pyf file, as shown below? I tried adding this glment folder to my PYTHONPATH
, but that didn't change anything.
~/221/tagger/tagger/glmnet master ls
__init__.py example_lasso_elastic_net.py glmnet.pyc
__init__.pyc glmnet.f glmnet.pyf
elastic_net.py glmnet.py
~/221/tagger/tagger/glmnet master head -10 glmnet.pyf
! -*- f90 -*-
! Note: the context of this file is case sensitive.
python module _glmnet ! in
interface ! in :_glmnet
subroutine elnet(ka,parm,no,ni,x,y,w,jd,vp,ne,nx,nlam,flmin,ulam,thr,isd,lmu,a0,ca,ia,nin,rsq,alm,nlp,jerr) ! in :glmnet:glmnet.f
integer optional :: ka=1 ! Use covariance updates over naive by default
real*8 :: parm
integer intent(hide),check(shape(x,0)==no),depend(x) :: no=shape(x,0)
integer intent(hide),check(shape(x,1)==ni),depend(x) :: ni=shape(x,1)
~/221/tagger/tagger/glmnet master echo $PYTHONPATH
/Users/rose/221/tagger/tagger/glmnet:
~/221/tagger/tagger/glmnet master cd ..
~/221/tagger/tagger master python main.py
Traceback (most recent call last):
File "main.py", line 14, in <module>
from glmnet import glmnet
File "/Users/rose/221/tagger/tagger/glmnet/glmnet.py", line 2, in <module>
import _glmnet
ImportError: No module named _glmnet
推荐答案
据我所知,它正在寻找 _gmlnet
模块,该模块在 gmlnet中定义.pyf
. gmlnet.pyf
不是python模块,它是用于名为 f2py
的程序的一组附加说明,而python将忽略 .pyf
文件.您需要使用 f2py
编译 .pyf
文件以及fortran文件.使用如下命令:
As far as I can tell from the source, it's looking for the _gmlnet
module, which is defined in gmlnet.pyf
. gmlnet.pyf
is not a python module, it's a set of additional instructions for a program called f2py
, and python will ignore the .pyf
file. You need to compile the .pyf
file along with a fortran file using f2py
. Use a command like this:
f2py -c --fcompiler=gnu95 gmlnet.pyf gmlnet.f
尝试安装 f2py
,然后重新安装 gmlnet
软件包.
Try installing f2py
and then reinstalling the gmlnet
package.
这篇关于Python glmnet“没有名为_glmnet的模块"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!