reflex-dev / reflex

🕸️ Web apps in pure Python 🐍
https://reflex.dev
Apache License 2.0
20.22k stars 1.16k forks source link

WinError 5 when running Reflex #3830

Open Brave-new-w0rld opened 2 months ago

Brave-new-w0rld commented 2 months ago

Describe the bug reflex run command runs into WinError 5 as shown in an error log down below.

To Reproduce Error log:

(.venv) ~\Desktop\Python\Apps\reflex-python2
reflex run
Warning: Windows Subsystem for Linux (WSL) is recommended for improving initial install times.
─────────────────────────────────────────────────────────────────────────────── Starting Reflex App ────────────────────────────────────────────────────────────────────────────────
[19:26:53] Compiling: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 13/13 0:00:00
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\Lenovo\Desktop\Python\Apps\reflex-python2\.venv\Scripts\reflex.exe\__main__.py", line 7, in <module>
  File "C:\Users\Lenovo\Desktop\Python\Apps\reflex-python2\.venv\Lib\site-packages\typer\main.py", line 338, in __call__
    raise e
  File "C:\Users\Lenovo\Desktop\Python\Apps\reflex-python2\.venv\Lib\site-packages\typer\main.py", line 321, in __call__
    return get_command(self)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Lenovo\Desktop\Python\Apps\reflex-python2\.venv\Lib\site-packages\click\core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Lenovo\Desktop\Python\Apps\reflex-python2\.venv\Lib\site-packages\typer\core.py", line 728, in main
    return _main(
           ^^^^^^
  File "C:\Users\Lenovo\Desktop\Python\Apps\reflex-python2\.venv\Lib\site-packages\typer\core.py", line 197, in _main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "C:\Users\Lenovo\Desktop\Python\Apps\reflex-python2\.venv\Lib\site-packages\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Lenovo\Desktop\Python\Apps\reflex-python2\.venv\Lib\site-packages\click\core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Lenovo\Desktop\Python\Apps\reflex-python2\.venv\Lib\site-packages\click\core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Lenovo\Desktop\Python\Apps\reflex-python2\.venv\Lib\site-packages\typer\main.py", line 703, in wrapper
    return callback(**use_params)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Lenovo\Desktop\Python\Apps\reflex-python2\.venv\Lib\site-packages\reflex\reflex.py", line 287, in run
    _run(env, frontend, backend, frontend_port, backend_port, backend_host, loglevel)
  File "C:\Users\Lenovo\Desktop\Python\Apps\reflex-python2\.venv\Lib\site-packages\reflex\reflex.py", line 245, in _run
    setup_frontend(Path.cwd())
  File "C:\Users\Lenovo\Desktop\Python\Apps\reflex-python2\.venv\Lib\site-packages\reflex\utils\build.py", line 231, in setup_frontend
    path_ops.cp(
  File "C:\Users\Lenovo\Desktop\Python\Apps\reflex-python2\.venv\Lib\site-packages\reflex\utils\path_ops.py", line 47, in cp
    rm(dest)
  File "C:\Users\Lenovo\Desktop\Python\Apps\reflex-python2\.venv\Lib\site-packages\reflex\utils\path_ops.py", line 25, in rm
    shutil.rmtree(path)
  File "C:\Program Files\Python312\Lib\shutil.py", line 781, in rmtree
    return _rmtree_unsafe(path, onexc)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\shutil.py", line 639, in _rmtree_unsafe
    onexc(os.rmdir, path, err)
  File "C:\Program Files\Python312\Lib\shutil.py", line 637, in _rmtree_unsafe
    os.rmdir(path)
PermissionError: [WinError 5] Access denied: 'C:\\Users\\Lenovo\\Desktop\\Python\\Apps\\reflex-python2\\.web\\public'
[19:26:54] Reflex app stopped. 

Expected behavior To run the Reflex app as supposed.

Specifics:

Other The issue temporarily resolved by running attrib –s –r “Folderpath” in cmd. However after re-running Reflex it generates WinError 5 again and the command above should be run once again.

PeterYusuke commented 1 month ago

It seems like the process does not have permission to access the folder. Did you try to run the app with administrator?

Brave-new-w0rld commented 1 month ago

Yes, I run my PyCharm IDE as admin. The issue temporarily resolved by running attrib –s –r “Folderpath” in cmd. However after re-running Reflex it generates WinError 5 again.

mmmcorpsvit commented 1 week ago

windows 11, my fix, work fine: reflex\utils\path_ops.py

import stat

def remove_readonly(func, path, _):
    os.chmod(path, stat.S_IWRITE)
    func(path)

def rm(path: str | Path):
    """Remove a file or directory.

    Args:
        path: The path to the file or directory.
    """
    path = Path(path)
    if path.is_dir():
        # shutil.rmtree(path)
        shutil.rmtree(path, onerror=remove_readonly)
    elif path.is_file():
        path.unlink()
Brave-new-w0rld commented 7 hours ago

same issue

windows 11, my fix, work fine: reflex\utils\path_ops.py

import stat

def remove_readonly(func, path, _):
    os.chmod(path, stat.S_IWRITE)
    func(path)

def rm(path: str | Path):
    """Remove a file or directory.

    Args:
        path: The path to the file or directory.
    """
    path = Path(path)
    if path.is_dir():
        # shutil.rmtree(path)
        shutil.rmtree(path, onerror=remove_readonly)
    elif path.is_file():
        path.unlink()

It works fine for me! Thanks man! Suppose as a fix for developers