What’s the best way to temporarily hide an installed module from a python script to test how it handles environments that don’t have the module installed?
I’d like to avoid having to uninstall the module just to test.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Setting
sys.modules['numpy']=Nonemakes Python think that it has already tried and failed to importnumpy. Subsequent attempts at importingnumpynow raiseImportError:Deleting
sys.modules['numpy']allowsnumpyto be imported as normal: