Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gather_sources_and_dependencies fails in notebooks with ipykernel 6.21.0 #909

Open
champialex opened this issue Feb 1, 2023 · 2 comments

Comments

@champialex
Copy link

champialex commented Feb 1, 2023

Jupyter released 6.21.0 on the 31st of Jan.
It includes ipython/ipykernel#1078 which adds a file variable. Sadly, that file doesn't actually exist....

Reproduce in a notebook with

pip install ipykernel==6.21.0
from sacred.dependencies import gather_sources_and_dependencies
gather_sources_and_dependencies(globals(), save_git_info=True)

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
path/to/my/notebook/directory/3a203c6e-289c-4c4e-abf1-74450c51ac54 in <cell line: 1>()
----> 1 gather_sources_and_dependencies(globals(), save_git_info=True)

/opt/conda/envs/my_env/lib/python3.8/site-packages/sacred/dependencies.py in gather_sources_and_dependencies(globs, save_git_info, base_dir)
    726 def gather_sources_and_dependencies(globs, save_git_info, base_dir=None):
    727     """Scan the given globals for modules and return them as dependencies."""
--> 728     experiment_path, main = get_main_file(globs, save_git_info)
    729 
    730     base_dir = base_dir or experiment_path

/opt/conda/envs/my_env/lib/python3.8/site-packages/sacred/dependencies.py in get_main_file(globs, save_git_info)
    597         main = None
    598     else:
--> 599         main = Source.create(globs.get("__file__"), save_git_info)
    600         experiment_path = os.path.dirname(main.filename)
    601     return experiment_path, main

/opt/conda/envs/my_env/lib/python3.8/site-packages/sacred/dependencies.py in create(filename, save_git_info)
    455     def create(filename, save_git_info=True):
    456         if not filename or not os.path.exists(filename):
--> 457             raise ValueError('invalid filename or file not found "{}"'.format(filename))
    458 
    459         main_file = get_py_file_if_possible(os.path.abspath(filename))

ValueError: invalid filename or file not found "path/to/my/notebook/directory/3a203c6e-289c-4c4e-abf1-74450c51ac54"
@thequilo
Copy link
Collaborator

It works for me:

!pip show ipykernel
Name: ipykernel
Version: 6.21.0
[...]

from sacred.dependencies import gather_sources_and_dependencies
gather_sources_and_dependencies(globals(), save_git_info=True)

(None,
 set(),
 {<PackageDependency: ipython=8.10.0>,
  <PackageDependency: numpy=1.21.5>,
  <PackageDependency: sacred=0.8.4>})

Are there other packages / version differences that could cause this on your side?

@champialex
Copy link
Author

I'm guessing that the difference is that I'm running in jupyterhub.
Or do you have __file__ that is defined, and that also exists according to os.path.exists(__file__)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants