sacred icon indicating copy to clipboard operation
sacred copied to clipboard

Error when running in poetry environment

Open yet-another-account opened this issue 5 years ago • 3 comments

When running an experiment in poetry, the following occurs:

Traceback (most recent call last):
  File "main.py", line 25, in <module>
    ex = Experiment('experiment-name')
  File "/home/user/.cache/pypoetry/virtualenvs/project-py3.7/lib/python3.7/site-packages/sacred/experiment.py", line 80, in __init__
    _caller_globals=caller_globals)
  File "/home/user/.cache/pypoetry/virtualenvs/project-py3.7/lib/python3.7/site-packages/sacred/ingredient.py", line 55, in __init__
    gather_sources_and_dependencies(_caller_globals, self.base_dir)
  File "/home/user/.cache/pypoetry/virtualenvs/project-py3.7/lib/python3.7/site-packages/sacred/dependencies.py", line 487, in gather_sources_and_dependencies
    sources = gather_sources(globs, base_dir)
  File "/home/user/.cache/pypoetry/virtualenvs/project-py3.7/lib/python3.7/site-packages/sacred/dependencies.py", line 438, in get_sources_from_imported_modules
    return get_sources_from_modules(iterate_imported_modules(globs), base_path)
  File "/home/user/.cache/pypoetry/virtualenvs/project-py3.7/lib/python3.7/site-packages/sacred/dependencies.py", line 407, in get_sources_from_modules
    filename = os.path.abspath(mod.__file__)
  File "/home/user/.pyenv/versions/3.7.3/lib/python3.7/posixpath.py", line 378, in abspath
    path = os.fspath(path)
TypeError: expected str, bytes or os.PathLike object, not NoneType

yet-another-account avatar May 21 '19 02:05 yet-another-account

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 19 '19 03:08 stale[bot]

Any updates on this? I'm still having issues with this. I think it is happening because the source module is just a normal Python file instead of an installed package, and for some reason its __file__ attribute is None.

AVSurfer123 avatar Dec 13 '20 05:12 AVSurfer123

I've never had this issue, and I'm not in a poetry environment. Can you further track down the issue? It looks like a module doesn't have a __file__ attribute. I think that this shouldn't happen as long as it is not an interactive python environment.

We could simply check for __file__ being None, but it is not clear what the source file should be set to in that case. Is it even reproducible then?

A quick fix would be to deactivate source gathering by setting SETTINGS.DISCOVER_SOURCES = 'none'.

thequilo avatar Dec 14 '20 12:12 thequilo