Python3 import module or packages from parent directory

Project directory Architecture

If I want to execute "main_ocsvm_case3_train_set.py" which will call Utilites.common_funcs.py

It will be ececuted normallly in pycharm.

However, when I use command shell, it will cause that:

 

 Soultion:

"add the following codes in  to main_ocsvm_case3_train_set.py"

# -*- coding: utf-8 -*-
"""
    add 'parent path' to system path so that the script can call 'parent directory'
"""
import os, sys

# sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(os.path.abspath('../'))  # add 'parent path' to system path
print(sys.path)

 

Solved.

posted on 2018-10-15 10:10  Quinn-Yann  阅读(275)  评论(0编辑  收藏  举报