Maximum Recursion Depth and Unlimited folders created

When I tried to package the model I developed using the spacy, I get the error RecursionError: maximum recursion depth exceeded while calling a Python object and infinite en-model folders are being created (One inside the other and so on..)

Below is the command I gave and the exception I received. Please help.

C:\Users\kjagini\Prodigy_Poc>python -m spacy package model C:\Users\kjagini\Prodigy_Poc\git_model
:heavy_check_mark: Loaded meta.json from file
model\meta.json
Traceback (most recent call last):
File "C:\Users\kjagini\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "C:\Users\kjagini\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "C:\Users\kjagini\AppData\Local\Programs\Python\Python37\lib\site-packages\spacy_main
.py", line 35, in
plac.call(commands[command], sys.argv[1:])
File "C:\Users\kjagini\AppData\Local\Programs\Python\Python37\lib\site-packages\plac_core.py", line 328, in call
cmd, result = parser.consume(arglist)
File "C:\Users\kjagini\AppData\Local\Programs\Python\Python37\lib\site-packages\plac_core.py", line 207, in consume
return cmd, self.func(*(args + varargs + extraopts), **kwargs)
File "C:\Users\kjagini\AppData\Local\Programs\Python\Python37\lib\site-packages\spacy\cli\package.py", line 72, in package
shutil.copytree(path2str(input_path), path2str(package_path / model_name_v))
File "C:\Users\kjagini\AppData\Local\Programs\Python\Python37\lib\shutil.py", line 351, in copytree
copytree(srcname, dstname, symlinks, ignore, copy_function)
File "C:\Users\kjagini\AppData\Local\Programs\Python\Python37\lib\shutil.py", line 351, in copytree
copytree(srcname, dstname, symlinks, ignore, copy_function)
File "C:\Users\kjagini\AppData\Local\Programs\Python\Python37\lib\shutil.py", line 351, in copytree
copytree(srcname, dstname, symlinks, ignore, copy_function)
[Previous line repeated 985 more times]
File "C:\Users\kjagini\AppData\Local\Programs\Python\Python37\lib\shutil.py", line 354, in copytree
copy_function(srcname, dstname)
File "C:\Users\kjagini\AppData\Local\Programs\Python\Python37\lib\shutil.py", line 266, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "C:\Users\kjagini\AppData\Local\Programs\Python\Python37\lib\shutil.py", line 103, in copyfile
if _samefile(src, dst):
File "C:\Users\kjagini\AppData\Local\Programs\Python\Python37\lib\shutil.py", line 88, in _samefile
return os.path.samefile(src, dst)
File "C:\Users\kjagini\AppData\Local\Programs\Python\Python37\lib\genericpath.py", line 96, in samefile
s1 = os.stat(f1)
RecursionError: maximum recursion depth exceeded while calling a Python object

I think what's happening here is that you're saving the packaged model into the same directory as the original data. As part of spacy package, the files in the input directory are copied to the output directory. But if the output directory is also the input directory, it will keep copying and end up in an infinite recursion.

Try saving out the model again (or delete everything that was added) and run the command again with a different output directory.

Thanks for the quick response.. it worked fine now.
I just have another question.
When I import -

  • spacy.load('en_model')
    I have to submit the path where my model is saved in, correct? Like below :
    nlp = spacy.load(r'C:\Users\kjagini\git_spacy_model\en_model-0.0.0\en_model\en_model-0.0.0')

Asking because in the "First steps" article on the website, when the model was loaded the path was not given but it was just

  • spacy.load('en_model').

Please confirm.

You don't need to use spacy package btw if you just want to load in the model – the command is mostly intended to turn your model into a pip-installable Python package. But you can also just load the model from a path.

Well, this just depends on the current working directory. If you save your model to a directory en_model and you're in the parent directory, you can load it via the relative path en_model.