Search code examples
pythonvirtualenvpip

How can I remove unused packages from virtualenv?


How can I keep track of the packages when I install them using pip inside a virtualenv?

It seems like a mess now; if I install package A, it automatically install its dependancies; B, C and D. Then I decide to use package N instead which installs its dependancies as well.

Now when I remove package A, its dependancies are not automatically removed.

How I can keep my virtualenv clean? Is there a tool to check for unused packages and remove them?


Solution

  • Making virtualenvs is relatively cheap. You could just create a new virtualenv whenever you get into this situation and run your pip install again.

    Not very elegant, but it gets the job done. Of course you need to be maintaining some requirements file for the pip install and it will go faster if you have some local index or cache for pip.