49

Possible Duplicate:
Unload a module in Python

After importing Numpy, lets say I want to delete/remove numpy import reference

import sys 
import numpy as np 

doMe()
   np.something()

#unimport np
#remove numpy from memory
2
  • possible duplicate: stackoverflow.com/a/487718/1107807 Commented Jan 8, 2012 at 21:03
  • Zaur, you would need to do that if you need to downgrade a package for different functionality. Commented Oct 24, 2019 at 14:52

1 Answer 1

47

Unloading a module from Python is not supported.

Sign up to request clarification or add additional context in comments.

4 Comments

del sys.modules["moduleName"] del moduleName
It may have worked in one instance, but this article explains why it should be discouraged and can catastrophically break things.
So, the conclusion is that you should NEVER change your software once you write it? Write it absolutely correctly the first time so that you never have to change it? Debugging software is for amateurs? That makes NO sense! Instead of telling people what NOT to do, why not tell people how they SHOULD replace an old version of a module with a new version?
@JDMorgan No. That's not the conclusion. Just restart the process. Simples.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.