0

I have question. I want to run my code with python language in jupyter notebook, but when i run my code it has error. error is: "An exception has occurred, use %tb to see the full traceback.

SystemExit: 2"

cloud you please help me :(

from tensorflow.keras.models import Sequential
from utils import *
import argparse
def parse_args():
    parser = argparse.ArgumentParser(description="train data path")
    parser.add_argument("--xpath", help="Xdata Path", default='', type=str,                                                              required=True)
    parser.add_argument("--ypath", help="ydata Path", default='', type=str, required=True)
    parser.add_argument("--group", help="group", default='', type=str, required=True)
    return parser.parse_args()

if __name__ == '__main__':
     args = parse_args()
     for train_X, train_y, test_X, test_y in read_data(args.xpath, args.ypath, args.group):
          model_fit(train_X, train_y, test_X, test_y)
tripleee
  • 175,061
  • 34
  • 275
  • 318
Mina
  • 1
  • 2
  • First of all please fix the indentation. Then explain how do you use it? What arguments are provided? Because the simple meaning of this error is that you does not providing any of the expected arguments. – Daniel Nudelman Apr 27 '21 at 10:53
  • I don't know how to solve this error. and I search but i can not find the problem – Mina Apr 27 '21 at 11:05
  • The script wants to be called on the command line with arguments; take out the `if __name__ == '__main__':` stuff and replace it with something which is correct for notebooks, or just call the function you want to call with the parameters you need. – tripleee Apr 27 '21 at 11:15
  • Using `argparse` in a notebook is difficult. `argparse` parses commndline strings, but the notebook server takes its own commandline values, You don't show the `usage` error, but most likely it's complaining about missing arguments, `ypath` and `group`. Either run this script with a regular `python` call, or find another way of specifying the required variables. – hpaulj Apr 27 '21 at 16:29

0 Answers0