Python,__init__.py调用扩展model失败
1.调用目录为:dir/dadi/dadi目录下包括:
__init__.py Demographics1D.py
__init__.py源码:"""
For examples of dadi's usage, see the examples directory in the source
distribution.
Documentation of all methods can be found in doc/api/index.html of the source
distribution.
"""
import logging
logging.basicConfig()
import Demographics1D
import Demographics2D
import Godambe
import Inference
import Integration
import Misc
import Numerics
import PhiManip
# import the triallele modules - numerics, integration, demographics
try:
import Triallele.numerics, Triallele.integration, Triallele.demographics
except ImportError:
pass
# Protect import of Plotting in case matplotlib not installed.
try:
import Plotting
except ImportError:
pass
# We do it this way so it's easier to reload.
import Spectrum_mod
Spectrum = Spectrum_mod.Spectrum
# When doing arithmetic with Spectrum objects (which are masked arrays), we
# often have masked values which generate annoying arithmetic warnings. Here
# we tell numpy to ignore such warnings. This puts greater onus on the user to
# check results, but for our use case I think it's the better default.
import numpy
numpy.seterr(all='ignore')
运行命令 python3 -c "import dadi"
报错信息:
File "dir/dadi/__init__.py", line 11, in <module>
import Demographics1D
ModuleNotFoundError: No module named 'Demographics1D' 模块默认是从Lib文件下搜索。 lubcat 发表于 2017-2-28 13:32
模块默认是从Lib文件下搜索。
lib目录下已经有dadi的文件了,这个就是lib目录下dadi目录下的__init__.py 搜索路径里大概没有你新添的这个路径,
如果这个Demographics1D模块本身没问题的话。 lubcat 发表于 2017-2-28 14:12
搜索路径里大概没有你新添的这个路径,
如果这个Demographics1D模块本身没问题的话。
我查了一下__init__.py,这个用法应该没有问题,在lib目录下新建model的文件夹里只要有__init__.py,并在这个脚本中import该目录下的model,就可以直接在其他目录下调用该目录下的model,这一点应该是没有问题的
但是就像要加coding=‘uft-8’才能输入中文一样,我猜是不是少了什么才会import不到 from _collections_abc import *
import _collections_abc
找了个系统的包看了下,
collections是个包,包含abc.py 和__init_
他的导入方式是上面这样的。 lubcat 发表于 2017-2-28 14:37
找了个系统的包看了下,
collections是个包,包含abc.py 和__init_
他的导入方式是上面这样的。
好像还是不对
jojodeMacBook-Air:fs_from_data jojo$ head -15 dir/dadi/__init__.py
"""
For examples of dadi's usage, see the examples directory in the source
distribution.
Documentation of all methods can be found in doc/api/index.html of the source
distribution.
"""
import logging
logging.basicConfig()
from Demographics1D import *
import Demographics1D
import Demographics2D
import Godambe
import Inference
jojodeMacBook-Air:fs_from_data jojo$ python3 fs_from_data.py
Traceback (most recent call last):
File "fs_from_data.py", line 4, in <module>
import dadi
File "dir/dadi/__init__.py", line 11, in <module>
from Demographics1D import *
ModuleNotFoundError: No module named 'Demographics1D' Luse 发表于 2017-2-28 15:23
好像还是不对
dadi这个包,不是包含Demographics1D和__init__两个文件
参照系统自带包的导入方式
我认为是
from_dadi_Demographics1D import *
import_dadi_Demographics1D
好吧。这样也不可以,就不知道啦=。= lubcat 发表于 2017-2-28 15:37
dadi这个包,不是包含Demographics1D和__init__两个文件
参照系统自带包的导入方式
我认为是
谢谢帮忙qwq,确实不可以…… Luse 发表于 2017-2-28 15:40
谢谢帮忙qwq,确实不可以……
{:10_284:}{:10_284:}
还是图样图森破了…… lubcat 发表于 2017-2-28 16:01
还是图样图森破了……
不知道和python版本有没有问题,我换python2就搞定了…… Luse 发表于 2017-2-28 20:31
不知道和python版本有没有问题,我换python2就搞定了……
{:10_266:}{:10_266:}
神奇了
页:
[1]