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

"FileNotFoundError" using pathlib after freezing the script #1878

Open
sirlagg opened this issue Apr 25, 2023 · 7 comments
Open

"FileNotFoundError" using pathlib after freezing the script #1878

sirlagg opened this issue Apr 25, 2023 · 7 comments

Comments

@sirlagg
Copy link

sirlagg commented Apr 25, 2023

As a part of a python application, files in unmapped network drive are accessed. The script runs like a charm when running the .py file, but after freezing it as an .exe file using cx_freeze I am getting the following error:

FileNotFoundError: [WinError 3] The system cannot find the path specified: '\one\random\folder\file.txt'

When running the following line:

sizelist = [float(Path(x).stat().st_size) for x in ListOfFiles]

The file definitely exists. I have noticed that under file properties in Windows, the file path is shown as:

\?\UNC\one\random\folder\file.txt

I have isolated the issue as caused by cx_Freeze. I have frozen the following script in cx_Freeze and pyinstaller:

# encoding: utf-8

from pathlib import Path

folder = input("Folder:")
file_list = []
file_list += list(Path(folder).rglob("**/*.mdf"))
file_list += list(Path(folder).rglob("**/*.mf4"))
file_list += list(Path(folder).rglob("**/*.dat"))
print([(Path(p), Path(p).is_file()) for p in file_list]) # For tracking

x = input("Press enter...")

When frozen with pyinstaller, Path(p).is_file() is True for all files. With cx_Freeze, some obtain True and the ones with the "\?\UNC" start of the path fail.

Is it there a way to solve this issue on cx_Freeze?

@marcelotduarte
Copy link
Owner

Python from python.org or conda? What version?
python -VV

@sirlagg
Copy link
Author

sirlagg commented May 2, 2023

Python from python.org

Python 3.11.3 (tags/v3.11.3:f3909b8, Apr 4 2023, 23:49:59) [MSC v.1934 64 bit (AMD64)]

@marcelotduarte
Copy link
Owner

marcelotduarte commented Jun 30, 2023

I cannot reproduce with python 3.11.4
I used the following code:

main.py
    from pathlib import Path
    from pprint import pprint
    #from pyfakefs.fake_filesystem_unittest import Patcher
    #
    folder = "//server/share"
    #patcher = Patcher()
    #patcher.setUp()
    #filesystem = patcher.fs
    #filesystem.add_real_directory("/local/path", target_path=folder)
    file_list = list(Path(folder).rglob("**/*.pdf"))
    #pprint(file_list)
    pprint([(p.as_posix(), p.is_file()) for p in file_list if not p.is_file()])
    #patcher.tearDown()
setup.py
    from cx_Freeze import Executable, setup
    setup(
        name="test",
        version="0.1",
        description="Sample for test with cx_Freeze",
        executables=[Executable("main.py")],
    )

The code in comments using pyfakefs is to be used in a test, if reproducible in a fakefs.
The only issue that I found is in a path accessible via samba that has incurred unicode, but it give a error, not a false positive.

NOTE: folder = "//server/share" can be changed to folder = "\\server\share" and the result is the same.

@marcelotduarte
Copy link
Owner

Release 6.15.3 is out!

Can you give me feedback?
Can I close the issue?

@sirlagg
Copy link
Author

sirlagg commented Jul 8, 2023

Hi, I have upgraded to the latest version and unfortunately the issue persists...

@marcelotduarte
Copy link
Owner

Can you reproduce the error with my test code in the previous comment?

@marcelotduarte marcelotduarte changed the title "FileNotFoundError" in python after freezing the script "FileNotFoundError" using pathlib after freezing the script Jul 8, 2023
@sirlagg
Copy link
Author

sirlagg commented Jul 10, 2023

When running main.exe, it returns [].

When running main.exe with all lines uncommented, it returns this error:

FileNotFoundError: [Errno 2] No such file or directory in the fake filesystem: '/local/path'

Unfortunately, the behaviour is the same when running both the .exe and the .py versions.

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

No branches or pull requests

2 participants