If Jupyter content is executed in a container image where there is no guarantee that the UID of the executing user will be mapped in /etc/passwd, a KeyError that is not caught will be raised by p.owner :
```
2023/01/17 18:02:24.481533600 File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/jupyter_core/paths.py", line 82, in _do_i_own
2023/01/17 18:02:24.481543233 return p.owner() == os.getlogin()
2023/01/17 18:02:24.481566456 File "/opt/python/3.10.4/lib/python3.10/pathlib.py", line 1101, in owner
2023/01/17 18:02:24.481568740 return self._accessor.owner(self)
2023/01/17 18:02:24.481576809 File "/opt/python/3.10.4/lib/python3.10/pathlib.py", line 343, in owner
2023/01/17 18:02:24.481577833 return pwd.getpwuid(self.stat(path).st_uid).pw_name
2023/01/17 18:02:24.481594757 KeyError: 'getpwuid(): uid not found: 999'
```
```
2023/01/17 18:02:22.875059195 Creating kernel spec: python3
2023/01/17 18:02:24.481240664 Traceback (most recent call last):
2023/01/17 18:02:24.481256953 File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/traitlets/traitlets.py", line 656, in get
2023/01/17 18:02:24.481304225 value = obj._trait_values[self.name]
2023/01/17 18:02:24.481305903 KeyError: 'kernel_dirs'
2023/01/17 18:02:24.481318923
2023/01/17 18:02:24.481321030 During handling of the above exception, another exception occurred:
2023/01/17 18:02:24.481335566
2023/01/17 18:02:24.481336717 Traceback (most recent call last):
2023/01/17 18:02:24.481346126 File "/opt/python/3.10.4/lib/python3.10/runpy.py", line 196, in _run_module_as_main
2023/01/17 18:02:24.481348053 return _run_code(code, main_globals, None,
2023/01/17 18:02:24.481356437 File "/opt/python/3.10.4/lib/python3.10/runpy.py", line 86, in _run_code
2023/01/17 18:02:24.481357206 exec(code, run_globals)
2023/01/17 18:02:24.481366608 File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/ipykernel/__main__.py", line 5, in
2023/01/17 18:02:24.481367576 app.launch_new_instance()
2023/01/17 18:02:24.481376613 File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/traitlets/config/application.py", line 1041, in launch_instance
2023/01/17 18:02:24.481378866 app.start()
2023/01/17 18:02:24.481390458 File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/ipykernel/kernelapp.py", line 708, in start
2023/01/17 18:02:24.481391271 return self.subapp.start()
2023/01/17 18:02:24.481400293 File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/ipykernel/kernelspec.py", line 232, in start
2023/01/17 18:02:24.481401365 dest = install(
2023/01/17 18:02:24.481409086 File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/ipykernel/kernelspec.py", line 152, in install
2023/01/17 18:02:24.481409880 dest = kernel_spec_manager.install_kernel_spec(
2023/01/17 18:02:24.481419040 File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/jupyter_client/kernelspec.py", line 397, in install_kernel_spec
2023/01/17 18:02:24.481420001 if kernel_dir not in self.kernel_dirs:
2023/01/17 18:02:24.481429041 File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/traitlets/traitlets.py", line 703, in __get__
2023/01/17 18:02:24.481430015 return self.get(obj, cls)
2023/01/17 18:02:24.481437625 File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/traitlets/traitlets.py", line 659, in get
2023/01/17 18:02:24.481438454 default = obj.trait_defaults(self.name)
2023/01/17 18:02:24.481446305 File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/traitlets/traitlets.py", line 1872, in trait_defaults
2023/01/17 18:02:24.481447059 return self._get_trait_default_generator(names[0])(self)
2023/01/17 18:02:24.481455345 File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/jupyter_client/kernelspec.py", line 198, in _kernel_dirs_default
2023/01/17 18:02:24.481456009 dirs = jupyter_path("kernels")
2023/01/17 18:02:24.481474309 File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/jupyter_core/paths.py", line 276, in jupyter_path
2023/01/17 18:02:24.481475197 if prefer_environment_over_user():
2023/01/17 18:02:24.481490154 File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/jupyter_core/paths.py", line 105, in prefer_environment_over_user
2023/01/17 18:02:24.481491080 if sys.prefix != sys.base_prefix and _do_i_own(sys.prefix):
2023/01/17 18:02:24.481533600 File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/jupyter_core/paths.py", line 82, in _do_i_own
2023/01/17 18:02:24.481543233 return p.owner() == os.getlogin()
2023/01/17 18:02:24.481566456 File "/opt/python/3.10.4/lib/python3.10/pathlib.py", line 1101, in owner
2023/01/17 18:02:24.481568740 return self._accessor.owner(self)
2023/01/17 18:02:24.481576809 File "/opt/python/3.10.4/lib/python3.10/pathlib.py", line 343, in owner
2023/01/17 18:02:24.481577833 return pwd.getpwuid(self.stat(path).st_uid).pw_name
2023/01/17 18:02:24.481594757 KeyError: 'getpwuid(): uid not found: 999'
2023/01/17 18:03:16.986492009 ipykernel install failed with exit code 1
```
If Jupyter content is executed in a container image where there is no guarantee that the UID of the executing user will be mapped in
/etc/passwd
, aKeyError
that is not caught will be raised byp.owner
:``` 2023/01/17 18:02:24.481533600 File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/jupyter_core/paths.py", line 82, in _do_i_own 2023/01/17 18:02:24.481543233 return p.owner() == os.getlogin() 2023/01/17 18:02:24.481566456 File "/opt/python/3.10.4/lib/python3.10/pathlib.py", line 1101, in owner 2023/01/17 18:02:24.481568740 return self._accessor.owner(self) 2023/01/17 18:02:24.481576809 File "/opt/python/3.10.4/lib/python3.10/pathlib.py", line 343, in owner 2023/01/17 18:02:24.481577833 return pwd.getpwuid(self.stat(path).st_uid).pw_name 2023/01/17 18:02:24.481594757 KeyError: 'getpwuid(): uid not found: 999' ```
``` 2023/01/17 18:02:22.875059195 Creating kernel spec: python3 2023/01/17 18:02:24.481240664 Traceback (most recent call last): 2023/01/17 18:02:24.481256953 File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/traitlets/traitlets.py", line 656, in get 2023/01/17 18:02:24.481304225 value = obj._trait_values[self.name] 2023/01/17 18:02:24.481305903 KeyError: 'kernel_dirs' 2023/01/17 18:02:24.481318923 2023/01/17 18:02:24.481321030 During handling of the above exception, another exception occurred: 2023/01/17 18:02:24.481335566 2023/01/17 18:02:24.481336717 Traceback (most recent call last): 2023/01/17 18:02:24.481346126 File "/opt/python/3.10.4/lib/python3.10/runpy.py", line 196, in _run_module_as_main 2023/01/17 18:02:24.481348053 return _run_code(code, main_globals, None, 2023/01/17 18:02:24.481356437 File "/opt/python/3.10.4/lib/python3.10/runpy.py", line 86, in _run_code 2023/01/17 18:02:24.481357206 exec(code, run_globals) 2023/01/17 18:02:24.481366608 File "/opt/rstudio-connect/mnt/app/python/env/lib/python3.10/site-packages/ipykernel/__main__.py", line 5, inIt appears as though this behavior was introduced in https://github.com/jupyter/jupyter_core/pull/323