間の混乱がneuropredictと呼ばれる私のパッケージである(モジュールの束とinitファイル;モジュールのいずれもneuropredict呼ばれる):円形インポート:ここでは、パッケージとモジュール
$ 09:50:24 miner neuropredict >> tree setup.py neuropredict
setup.py [error opening dir]
neuropredict
├── config_neuropredict.py
├── freesurfer.py
├── __init__.py
├── __main__.py
├── model_comparison.py
├── neuropredict.py
├── rhst.py
├── test_rhst.py
├── visualize.py
0 directories, 16 files
レポは、https://github.com/raamana/neuropredictで入手可能です及び(フォルダ上に示したコンテンツ)をパッケージのinitファイルは、次のとおり
$ 09:50:27 miner neuropredict >> cat neuropredict/__init__.py
__all__ = ['neuropredict', 'rhst', 'visualize', 'freesurfer',
'config_neuropredict', 'model_comparison']
from sys import version_info
if version_info.major==2 and version_info.minor==7:
import neuropredict, config_neuropredict, rhst, visualize, freesurfer, model_comparison
elif version_info.major > 2:
from neuropredict import neuropredict, config_neuropredict, rhst, visualize, freesurfer, model_comparison
else:
raise NotImplementedError('neuropredict supports only 2.7 or Python 3+. Upgrade to Python 3+ is recommended.')
rhst.pyにインポートコード(第20行)のようになり:
$ 09:50:40 miner neuropredict >> head -n 20 neuropredict/rhst.py
from __future__ import print_function
__all__ = ['run', 'load_results', 'save_results']
if version_info.major==2 and version_info.minor==7:
import config_neuropredict as cfg
elif version_info.major > 2:
from neuropredict import config_neuropredict as cfg
else:
raise NotImplementedError('neuropredict supports only 2.7 or Python 3+. Upgrade to Python 3+ is recommended.')
パッケージ内のすべてのモジュールをインポートする必要がある設定ファイルは、(任意のif __name__ == __main__ code
なし)変数の束が含まれてい
$ 09:51:22 miner neuropredict >> head -n 20 neuropredict/config_neuropredict.py
import matplotlib.pyplot as plt
NUM_TREES = 100
COMMON_FIG_SIZE = [9, 9]
CMAP_DATASETS = 'Paired'
のPython 2.7、以下のテストスクリプトの作品は(のみの一部をインポートしますコードが表示されます)。しかし、私がこれをPython 3.6の下で実行すると、すべてが壊れてしまいます(何らかの循環インポートダンス)。示すエラーから
$ 09:51:52 miner neuropredict >> head -n 20 neuropredict/test_rhst.py
import numpy as np
import os
import sys
from sys import version_info
from os.path import join as pjoin, exists as pexists, realpath
sys.dont_write_bytecode = True
from pyradigm import MLDataset
if version_info.major==2 and version_info.minor==7:
from neuropredict import rhst
elif version_info.major > 2:
from neuropredict.neuropredict import rhst
else:
raise NotImplementedError('neuropredict supports only 2.7 or Python 3+. Upgrade to Python 3+ is recommended.')
、私は混乱が、それは強くのみ明示的な輸入を推奨与えられ、Pythonの3+では発生しませんneuropredict(パッケージ)とneuropredict(モジュール)、間にあると思います。
また、test_rhst.pyはpytestで実行したときにエラーを報告しませんが、ターミナルでpython3.6 test_rhst.py
を使用して実行した場合のみエラーが報告されます。
エラーメッセージはあまり役に立たず(通常can not import name rhst
またはcan not import name config_neuropredict
)、ModuleNotFoundErrorなどの理由がわかりません。
この時点で、モジュールの名前をパッケージ名と異なる名前に変更するかどうかを考えています。 neupredict、またはsquash python 2.7に関連するすべてのコード、および排他的にPython 3 +で動作します(私は動作しません)。