ビルド中のコードからいくつかの関数をテストして、私がjupyterノートにインポートする必要があります。Jupyterノートブックの間違ったパス
の問題は、simTools_pathは機能とjupyterノートブックでは異なります。さらに、私がメインのpythonスクリプトからこれらの関数を呼び出すと、うまく動作します。
MWE
simTools_path /オブジェクト/ classes.py
simTools_path = os.path.abspath(os.getenv('SIMTOOLS_PATH'))
sys.path.append(simTools_path)
def testPath():
print 'testPath', simTools_path
jupyterノート
import os,sys
# paths
simTools_path = os.path.abspath('../')
os.environ["SIMTOOLS_PATH"] = "simTools_path"
os.environ["PYTHONPATH"] = "simTools_path"
sys.path.append(simTools_path)
from objects.classes import testPath
print simTools_path
testPath()
結果:
のsimTools_path= /home/jhumberto/WORK/Projects/code/simulations_2016-07-14/simTools
testPath= /home/jhumberto/WORK/Projects/code/simulations_2016-07-14/simTools/jupyterNotebooks/simTools_path
注
1)Iは、比較的simTools_pathパスにファイルのデータをロードするために、異なるモジュール内のさまざまな機能は、このパス変数を使用します。
2)私のjupyterノートは/ホーム/ jhumberto/WORK /プロジェクト/コード/ simulations_2016-07-14/simTools/jupyterNotebooks
に任意のアイデアに位置していますか?
は、ライン 'はos.environ [ "SIMTOOLS_PATH" であった= "simTools_pathは、"' 'はos.environ [ "SIMTOOLS_PATH"] = simTools_path'を読むことになって(引用符なし)? 1つは親ディレクトリを指し、もう1つは現在のディレクトリ内のsimTools_pathというフォルダを指します。 – mdurant
@mdurant愚かな私、それだった!ありがとう!私はそれを受け入れることができるように答えを書いてくださいできますか? – jorgehumberto