-
-
Notifications
You must be signed in to change notification settings - Fork 224
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
DarwinException: Attempting to copy two files #913
Comments
I remember reflecting on this back when I did PR #590. The basic issue is that the Freeze objects only tracks where files are going (in .files_copied) rather than where they came from. So, before the PR (and I think still for files other than Mach-O files on Darwin), if the Freeze tried to copy a second file to the same spot as a file had already been copied, it would just assume the file was previously copied and continue on. The PR changed that to report an error in those circumstances. We could easily add a new option for build_exe to make it ignore the problem again (or make that the default behaviour?). If it is really just two copies of the same library, presumably it would still work. If we go the new option route, I could also change the error message to suggest trying that option? |
I am not very familiar with the code of this PR, I just did basic tests and accepted what you told me, which are advances. And sometimes they need some adjustments. |
I just reinstalled python with homebrew, now i have version 3.9.1. #!/usr/local/bin/python will produce the error "Attempting to copy two files". Then i checked the size of the 2 .dylib files: |
The sizes are 488 and 320 kb? I wonder if the difference is that the big one contains 32-bit and 64-bit code. Anyway, I'm confused why the 1-line program would be trying to grab anything from the PIL package. What is in the setup.py script? First step is probably to figure out why that is happening. |
Sorry, my mistake: the 1-line program test.py is "import matplotlib" , with import sys it works. |
Thanks. That makes more sense then. Just tried, and it looks like it does actually load two copies of "liblzma.5.dylib" (also "libz.1.2.11.dylib") when you run the underlying program. (I think this is different from Windows, where you could only get one library with a given file name, as I understand it.) So to be totally safe, we would need to copy both libraries into the frozen application, which I think would require mangling the filenames or putting the "extra" copies in new a new subdirectory(ies). Or we could just hope that the libraries are interchangeable and only copy one (which was how things worked before PR #590). In case it is helpful, here is a program that runs a specified python script and prints a list of the modules / dynamics libraries that are (in fact) loaded (so far only for OSX). Good for sanity checking with cx_Freeze is doing. Marcelo--this will appear in a PR with some other tools at some point when I get around to it. Also, out of curiosity, was there a reason you explicitly included the "os" package in your setup script? (Just wondering if there was some problem otherwise.) |
Thank you for help. |
Hi Marcelo-- I (belatedly!) think that you were correct above. Since the dynamic link is to a file that is already being included in the frozen application (as part of the package) we should just detect that and update the link so that it points to the file in the package. This isn't going to work if the package is being zip_included, or if the two libraries are outside packages, and in that case we would still have the error, or need to do name mangling, etc. Would it be hard to make information available about what files are in copied modules, and where those files ended up? |
The idea with script_runner.py would be to run it on the program being frozen (i.e., "test.py", in your case), rather than the setup script. Sorry for the confusion. |
When the package goes to the zip, the extensions (.so, .pyd, etc) are renamed. For dependencies of an extension like that of PIL, it remains in the same folder (PIL/.dylibs).
It is a possibility that I have in mind. I think that is not hard. For now, I think we should bypass this error, and implement a better approach in the future. Bypassing the error gives a chance to the developer to substitute the library in a post build process. There is a package delocate that finds dynamic libraries imported from python extensions. Do you know it? |
Here again my output of script_runner, this time i hope the correct one. |
I did not know about that one. Thanks. I'll take a look. |
Oddly, the report there shows only one copy of liblzma being loaded. |
I deleted the source 2 file and ran my setup script again. Nevertheless it appears again. imac-von-heinz:lib christen$ cd /Users/christen/Desktop/xtest/ Source 2 is no longer available, but it still appears in the log output. How is this possible? Is it hidden in a zip file? |
Hi @heinzchristen. As a quick fix, could you try with PR #915? That change converts the error to a warning, so the freeze will proceed. The frozen application will only include the first version of the library in question, so behaviour might be different (or maybe not). |
I would really like to test the new version 915, but I don't know how to load it. I don't know enough about github. I simply installed cx_freeze with pip install cx_freeze. |
You can download the code here: https://github.com/cainesi/cx_Freeze/archive/darwin_dylib_collision_fix.zip Download it, unzip it, go into the directory, and then run "pip install ." That should install a copy of cx_Freeze based on the downloaded source. You need to have a C-compiler to build cx_Freeze, but I think if you're using homebrew then you would have already installed apple Command Line Tools? |
Thank you very much. This fixed my problem and my programs can be freezed. |
No problem. Just to confirm, did you check that the frozen program runs? (This fix is a hack, so it's possible that the frozen program would not run, it would run differently from the original unfrozen script) |
Yes, my programs run, even the biggest project (using biopython, reportlab, matplotlib and a lot of others) run perfectly. So i am very happy. Thanks. |
@cainesi Thanks! To document, you can suggest to others to test your PR directly (without additional work):
|
Thanks. I didn't know you could do that with pip. Next time. I thought a bit more about how to fix this. I would propose the following:
As a side benefit, this would allow some simplifications in the darwintools.py code. If that sounds like it might be acceptable, I can do a PR. |
@cainesi Sorry for the late response. |
Hi @marcelotduarte. Thanks. I've wished that the Windows/Linux/Mac code was better separated for a while, but have not had the time to do it. I was thinking it would be better if we had a sub-class of Freezer for each platform, which implement all the necessary platform-specific adjustments--was that what you had in mind? For the file copying suggestion, I've done some very preliminary work along the lines I was suggesting. I'll upload it to a draft PR, in case it's any help. Are you going to put #915 into the next version, pending a more permanent fix? |
Exactly.
Yes. |
That's great, and will make things much easier. I can just add most of the darwintools stuff into the DarwinFreezer subclass. I did some very preliminary work on implementing file copying changes I suggested earlier. It is here, if you are interested: cainesi@894f52c (at the moment it creates two copies of the frozen executable, to check that the old and new code were giving consistent results). I'll hold off on doing any more work on that until Freezer gets split. Also, I took the draft off #915 if you want to use it. |
cx_Freeze 6.6 has just been released. |
@cainesi Please see this: https://github.com/marcelotduarte/cx_Freeze/discussions/912
I already commented about this error in #887 (comment)
I think this is introduced in PR #590
Using macOS Github Action I have the same error with the sample https://github.com/marcelotduarte/cx_Freeze/tree/main/cx_Freeze/samples/pillow
This is an annoying error because the developer has no possibilities to workaround, then we have to choose the library or give an option to choose.
In the issue reported, the library to choose is a PIL library like in the sample.
Can you take a look?
The text was updated successfully, but these errors were encountered: