pythonpython-3.xwindowsstreamlitramdisk

Running a Streamlit script encounters OSError: [WinError 1] Incorrect function


I was trying Streamlit 1.13 on Windows 10, where I encountered the following error:


Z:\>streamlit run st1.py
2022-10-04 02:25:28.218 INFO    numexpr.utils: NumExpr defaulting to 4 threads.

  Welcome to Streamlit!

  If you're one of our development partners or you're interested in getting
  personal technical support or Streamlit updates, please enter your email
  address below. Otherwise, you may leave the field blank.

http://localhost:8501
Traceback (most recent call last):
  File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\site-packages\tornado\http1connection.py", line 276, in _read_message
    delegate.finish()
  File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\site-packages\tornado\routing.py", line 268, in finish
    self.delegate.finish()
  File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\site-packages\tornado\web.py", line 2322, in finish
    self.execute()
  File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\site-packages\tornado\web.py", line 2344, in execute
    self.handler = self.handler_class(
  File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\site-packages\tornado\web.py", line 239, in __init__
    self.initialize(**kwargs)  # type: ignore
  File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\site-packages\streamlit\web\server\routes.py", line 49, in initialize
    self._pages = get_pages()
  File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\site-packages\streamlit\web\server\server.py", line 397, in <lambda>
    for page_info in source_util.get_pages(
  File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\site-packages\streamlit\source_util.py", line 155, in get_pages
    "script_path": str(main_script_path.resolve()),
  File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\pathlib.py", line 1215, in resolve
    s = self._flavour.resolve(self, strict=strict)
  File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\pathlib.py", line 215, in resolve
    s = self._ext_to_normal(_getfinalpathname(s))
OSError: [WinError 1] Incorrect function: 'st1.py'

The installation of streamlit was complete: initially there was a conflict which I fixed, I also installed it in Anaconda and the error was the same.

I checked the exact streamlit file which rised the exception and changed the script to print the actual path of the script and it was correct, as well as the file was there.


#File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\site-packages\streamlit\source_util.py", line 155, in get_pages

def get_pages(main_script_path_str: str) -> Dict[str, Dict[str, str]]:
    global _cached_pages
    print("main_script_path_str=",main_script_path_str) #DEBUG

    # Avoid taking the lock if the pages cache hasn't been invalidated.
    pages = _cached_pages
    if pages is not None:
        return pages

Solution

  • The problem was with the location of the script on a RAM disk. Moving it to the a regular disk resolved it.

    Another question with this Win error reminded me that the drivers of Windows RAM drives, at least the ones I've used such as Imdisk or OSFMount, seem to have missing support of some of the OS file functions.

    OSError: [WinError 1] Incorrect function

    E.g. "Rust" also had errors when trying to build source located in any of these RAM drives on Windows.