-
Notifications
You must be signed in to change notification settings - Fork 254
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
Unexpected behaviour due to fpdf
being the module name
#925
Comments
Hi @nemkin Thank you for taking the time to open a discussion on this subject. I am one of @reingart, the maintainer of
My answer at the time was:
Now I'd be very happy to take in consideration the opinions & suggestions of |
Thank you for sharing these emails! It sounds like both fpdf and fpdf2 are in use by a large community and have differing priorities, so I'd refrain from asking for either of the two taking over the other. So personally, I feel the only problem is this repository sharing a module name with another popular repository for a similar usecase, with overlapping, but non-identical API, which causes a lot of confusion when people share scripts online. I'd argue most people, when they install dependencies, they'll do:
You can see how both of those steps result in unexpected and confusing results for this repository. Even though I have specified in my personal case which of the two repositories needs to be installed, it did not help, as noone expects having to pay attention to something like this, thus the error was unexpected on their side as well. Also I wanted to add here that this & the pypdf module in this organisation are really awesome, I've had quite a hard time editing pdf files before I found these, so thank you for maintaining and improving this project. 😊 Edit: Although I'm not familiar with Python module packaging, a suggestion for "graceful renaming" would be something like: Publish This way users will still have an fpdf module installed on their system, when they |
Thank you for your thoughtful & kind comments @nemkin 🙂 I guess that ideally from fpdf2 import ... But changing that now would be a major breaking change to perform in We could try to have both kind of imports to work for some time ( I'd be very happy to know the points of view of other contributors & users on the subject 🙂 |
Given how much more functionality fpdf2 offers, the level of compatibility that still exists between the two is in fact truly amazing. We maintain a list of the differences. Actual porting difficulties should be few and far between. The If I may be even more blunt than usual, I never understood why someone wanted to replicate a PHP API in Python (or any language, and it never was a particularly great API even by PHP standards). But that's what we have now, and we can only try to improve on it. While the original goal was to create a "simplistic" library, we have now settled on trying to keep it as simple and straightforward as possible, while offering more advanced features. In fact, the text shaping implemented with 2.7.5 is absolutely unique among Python libraries, and opens it up to a truly global audience. To @reingart s individual points:
On our side, we should probably document somehow that having both packages installed on the same machine can lead to problems due to the identical import name. This should really only happen to legacy users while transitioning to fpdf2. But we need to give those a fair warning, so they can take appropriate measures to mitigate the issue. |
I'd argue fpdf2 is simpler to work with comparing to the legacy fpdf. I have programs built before The arguments for renaming the library and unforking (#906) are valid and make complete sense, however it would cause so many other problems for current users I don't think it's worth it. |
We recently had another occurence of a user confusion between I took this opportunity to make some basic tests about the situations where both
All source files from both libraries are written by That's not ideal, but it means that we could easily add a check to try:
import .ttfonts # this module only exists in PyFPDF, it has been removed in fpdf2 since v2.5.7
warnings.warn("You have both PyFPDF & fpdf2 installed - To only keep fpdf2 run: pip uninstall --yes fpdf && pip install --upgrade fpdf2")
except ImportError:
pass # no PyFPDF installation detected Do you think such check would be a good idea @andersonhc & @gmischler? |
Thank for sharing - I haven't thought about how Python handles package installations in that way. Super interesting! |
Just a "bump" on this question / suggestion: unless you disagree, I'm planning on adding those 5 lines to |
Identifying a double install in Those few who actually need both installed on the same system should be able to keep them apart with the help of venv. |
A warning seemed better to me because an extra |
I wish there was a better way to break apart from fpdf but realistically it's never going to happen. |
I opened #1042 to introduce this warning |
fpdf2 is a fork of fpdf, which seems to be no longer maintained. Both projects have the
fpdf
module name, which is really confusing and causes issues due to API changes between the two.Error details
Consider for example seeing this python script:
Based on what you see, you'd want to run
pip install fpdf
in order to use the script, which succeeds. However that results in the following error, as the API has been changed in fpdf2.Looking up the error, you can see other people are having similar issues [1, 2, 3, 4].
It seems to me that the best solution would be to have
pip install fpdf
install fpdf2, but that requires permission from its maintainer.If not, there should be clear distinction between the two projects, e.g. use
import fpdf2
, so it is clear which one of the two a Python script was based on.I've commented this on your issue in the fpdf repository too.
The text was updated successfully, but these errors were encountered: