bioscrape icon indicating copy to clipboard operation
bioscrape copied to clipboard

ModuleNotFoundError when importing bioscrape from inside bioscrape directory.

Open ayush9pandey opened this issue 4 years ago • 5 comments

MWE to produce this error:

>> cd bioscrape/
>> python
>> import bioscrape
'Module not found error bioscrape.random not found'
(this is an error in __init__.py)

ayush9pandey avatar Apr 21 '20 08:04 ayush9pandey

As this error only occurs when importing from the root directory (which no one should do, ideally), but people end up creating their files in this root directory sometimes and end up with this error. If this was a pure python package, this error wouldn't exist but bioscrape import statements work from the compiled version only (i.e. the installed package in sites-packages).

What could be a good way to solve this issue? One way is to simply issue a warning or an error if someone tries to import bioscrape from the root directory (they should not be doing this). The other way is to some how force all the imports to look at sites-packages by default.

Any ideas @sclamons @WilliamIX ?

ayush9pandey avatar Apr 22 '20 09:04 ayush9pandey

@ayush9pandey I think an error or warning would be fine, maybe in init of the package?

WilliamIX avatar Jun 14 '21 19:06 WilliamIX

Yes, but how do we detect that the user is inside the directory? There must be a way tho, I didn't look closely for a solution. But if it can be done, cleanly we should do it

ayush9pandey avatar Jun 15 '21 02:06 ayush9pandey

Adding the package to src/ will solve this issue. Most other python packages do this, and it is probably the correct packaging practice.

ayush9pandey avatar Feb 21 '23 04:02 ayush9pandey

Fixed in documentation #165

ayush9pandey avatar Feb 21 '23 06:02 ayush9pandey