2017-09-14 4 views
0

これは私を壁に押し上げています。私は、次のツリー構造を持つDjangoプロジェクトを持っている、とDjango ModuleNotFoundスクリプトの場合

load_professors_into_db.pyは、次のコードを持っているルートディレクトリからpython helper_scripts/load_professors_into_db.pyを実行しようとしています:

## TODO: FIX THIS DAMN IMPORT PATH. THE SCRIPT DOESNT RUN CAUSE OF IT 
from ocubulum_dashboard.models import Researcher 
import pandas as pd 
df = pd.read_csv("helper_scripts/soc_myaces_list.csv") 
df = df.dropna() 
df = df[~pd.isnull(df["scopus_id"])] 
df = df[df["scopus_id"] != 'None'] 

しかし、それはModuleNotFoundエラーが試されます。私は__init__.pyファイルをどこにでも追加しようとしましたが、どちらもうまくいきません。

Traceback (most recent call last): 
    File "helper_scripts/load_professors_into_db.py", line 10, in <module> 
    from ocubulum_dashboard.models import Researcher 
ModuleNotFoundError: No module named 'ocubulum_dashboard' 

この問題は発生しません。私がscopus_scraper.pyのように実行したい他のスクリプトについては、このばかげたインポートの問題に直面しています。

Traceback (most recent call last): 
     File "data_collectors/scopus/scopus_scraper.py", line 1, in <module> 
     from ocubulum_dashboard.models import Researcher 
    ModuleNotFoundError: No module named 'ocubulum_dashboard' 

この問題の解決方法を教えてもらえますか?私はPython 3.6です。

フォルダ構造全体は:

├── data_aggregators 
│   ├── myaces_aggregator.py 
│   └── scopus_aggregator.py 
├── data_collectors 
│   ├── execute_all.py 
│   ├── __init__.py 
│   ├── journals 
│   │   ├── __init__.py 
│   │   ├── journal_scraper.py 
│   │   ├── master.py 
│   │   ├── __pycache__ 
│   │   │   └── __init__.cpython-36.pyc 
│   │   └── test.json 
│   ├── nus_myaces 
│   │   ├── __init__.py 
│   │   ├── master.py 
│   │   └── __pycache__ 
│   │    └── __init__.cpython-36.pyc 
│   ├── __pycache__ 
│   │   └── __init__.cpython-36.pyc 
│   └── scopus 
│    ├── __init__.py 
│    ├── master.py 
│    ├── __pycache__ 
│    │   └── __init__.cpython-36.pyc 
│    ├── scopus_scraper.py 
│    └── scopus_wrapper 
│     ├── __init__.py 
│     ├── __pycache__ 
│     │   ├── __init__.cpython-36.pyc 
│     │   └── scopus_wrapper.cpython-36.pyc 
│     └── scopus_wrapper.py 
├── environment.yml 
├── helper_scripts 
│   ├── __init__.py 
│   ├── load_professors_into_db.py 
│   ├── __pycache__ 
│   │   └── __init__.cpython-36.pyc 
│   └── soc_myaces_list.csv 
├── __init__.py 
├── manage.py 
├── ocubulum 
│   ├── __init__.py 
│   ├── __pycache__ 
│   │   ├── __init__.cpython-36.pyc 
│   │   ├── settings.cpython-36.pyc 
│   │   ├── settings_development.cpython-36.pyc 
│   │   ├── urls.cpython-36.pyc 
│   │   ├── views.cpython-36.pyc 
│   │   └── wsgi.cpython-36.pyc 
│   ├── settings_development.py 
│   ├── settings.py 
│   ├── static 
│   ├── urls.py 
│   ├── views.py 
│   └── wsgi.py 
├── ocubulum_dashboard 
│   ├── admin.py 
│   ├── apps.py 
│   ├── __init__.py 
│   ├── migrations 
│   │   ├── 0001_initial.py 
│   │   ├── __init__.py 
│   │   └── __pycache__ 
│   │    ├── 0001_initial.cpython-36.pyc 
│   │    └── __init__.cpython-36.pyc 
│   ├── models.py 
│   ├── __pycache__ 
│   │   ├── admin.cpython-36.pyc 
│   │   ├── apps.cpython-36.pyc 
│   │   ├── __init__.cpython-36.pyc 
│   │   ├── models.cpython-36.pyc 
│   │   ├── tests.cpython-36.pyc 
│   │   └── views.cpython-36.pyc 
│   ├── static 
│   │   ├── css 
│   │   │   ├── custom.css 
│   │   │   └── side-menu.css 
│   │   ├── img 
│   │   │   └── logo.png 
│   │   └── js 
│   │    └── ui.js 
│   ├── templates 
│   │   └── ocubulum 
│   │    ├── dashboard.html 
│   │    └── layout.html 
│   ├── tests.py 
│   └── views.py 
├── Procfile 
├── __pycache__ 
│   └── __init__.cpython-36.pyc 
├── README.md 
├── requirements.txt 
└── runtime.txt 

答えて

0

from ..ocubulum_dashboard.models import Researcherを試してみてください。

ocubulum_dashboardを含むフォルダをPYTHONPATHに追加してください。

+0

いずれも機能しないようです。 – Wboy

関連する問題