LoginSignup
0
0

StreamlitがDockerで使えないのを乗り切る

Posted at

症状

streamlitをDockerで動かすとNo such file or directoryとでてしまう。

# streamlit run app.py

Collecting usage statistics. To deactivate, set browser.gatherUsageStats to False.

Traceback (most recent call last):
  File "/usr/local/bin/streamlit", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/streamlit/web/cli.py", line 233, in main_run
    _main_run(target, args, flag_options=kwargs)
  File "/usr/local/lib/python3.11/site-packages/streamlit/web/cli.py", line 269, in _main_run
    bootstrap.run(file, is_hello, args, flag_options)
  File "/usr/local/lib/python3.11/site-packages/streamlit/web/bootstrap.py", line 411, in run
    _install_pages_watcher(main_script_path)
  File "/usr/local/lib/python3.11/site-packages/streamlit/web/bootstrap.py", line 386, in _install_pages_watcher
    watch_dir(
  File "/usr/local/lib/python3.11/site-packages/streamlit/watcher/path_watcher.py", line 155, in watch_dir
    return _watch_path(
           ^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/streamlit/watcher/path_watcher.py", line 130, in _watch_path
    watcher_class(
  File "/usr/local/lib/python3.11/site-packages/streamlit/watcher/event_based_path_watcher.py", line 92, in __init__
    path_watcher.watch_path(
  File "/usr/local/lib/python3.11/site-packages/streamlit/watcher/event_based_path_watcher.py", line 170, in watch_path
    folder_handler.watch = self._observer.schedule(
                           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/watchdog/observers/api.py", line 323, in schedule
    emitter.start()
  File "/usr/local/lib/python3.11/site-packages/watchdog/utils/__init__.py", line 92, in start
    self.on_thread_start()
  File "/usr/local/lib/python3.11/site-packages/watchdog/observers/inotify.py", line 125, in on_thread_start
    self._inotify = InotifyBuffer(path, self.watch.is_recursive, event_mask)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/watchdog/observers/inotify_buffer.py", line 37, in __init__
    self._inotify = Inotify(path, recursive, event_mask)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/watchdog/observers/inotify_c.py", line 174, in __init__
    self._add_dir_watch(path, recursive, event_mask)
  File "/usr/local/lib/python3.11/site-packages/watchdog/observers/inotify_c.py", line 387, in _add_dir_watch
    self._add_watch(full_path, mask)
  File "/usr/local/lib/python3.11/site-packages/watchdog/observers/inotify_c.py", line 401, in _add_watch
    Inotify._raise_error()
  File "/usr/local/lib/python3.11/site-packages/watchdog/observers/inotify_c.py", line 417, in _raise_error
    raise OSError(err, os.strerror(err))
FileNotFoundError: [Errno 2] No such file or directory

対応

上記に書かれているがこれらのオプションを渡してあげる

  • --server.headless true
  • --server.fileWatcherType none
  • --browser.gatherUsageStats false

Dockerfileだとこんな感じ

FROM python:3.11-slim
RUN pip install streamlit
CMD ["streamlit", "run", "app.py", "--browser.gatherUsageStats", "false", "--server.headless", "true", "--server.fileWatcherType", "none"]
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0