You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Title mb Python module's name can get into the way
Priority bug Status chatting
Superseder Nosy List fukawi2, poeml
Assigned To poeml Keywords Packaging
The Python module's name "mb" can get into the way when it is being installed,
because it has the same name as the script "mb" / "mb.py".
This can lead to a very puzzling problem: Imports fail for mysterious reasons. I
have wasted a lot of time into debugging this pitfall in the past (in other
situations).
The issue is that the script "mb.py" imports the module named "mb", which leads to
importing itself instead of the module. This seems to happen when the script exists
with its ending ".py". The current directory is always the first in the search path
in Python, that's why.
This can be very hard to find out (as I learnt the hard way).
Issue migrated (2015-06-05) from old issue tracker http://mirrorbrain.org/issues/issue69
msg264 (view) Author: poeml Date: 2010-09-19.01:13:25
The Python module's name "mb" can get into the way when it is being installed,
because it has the same name as the script "mb" / "mb.py".
This can lead to a very puzzling problem: Imports fail for mysterious reasons. I
have wasted a lot of time into debugging this pitfall in the past (in other
situations).
The issue is that the script "mb.py" imports the module named "mb", which leads to
importing itself instead of the module. This seems to happen when the script exists
with its ending ".py". The current directory is always the first in the search path
in Python, that's why.
This can be very hard to find out (as I learnt the hard way).
https://bbs.archlinux.org/viewtopic.php?pid=825860
Maybe the script should be named mb-commandline.py instead; when packaging it, a
link named "mb" could be added.
The only other solution (I think) would be to rename the module (e.g. to Mb).
msg265 (view) Author: poeml Date: 2010-09-19.01:17:02
Just a note, starting such a script with "python -v" as interpreter would display
all imported files, which can elucidate this problem.
(end of migrated issue)
The text was updated successfully, but these errors were encountered: