I want to revert my Python install back to its base state so I can start using virtualenv. Is there an easy way to uninstall only those packages that have been installed after Python was set up?
Asked
Active
Viewed 5.4k times
14
Giorgos Myrianthous
- 30,279
- 17
- 114
- 133
Cam
- 1,676
- 3
- 18
- 32
-
2Why not just uninstall everything including python? Also maybe add in what OS you are using. – Dan Jul 03 '19 at 13:02
-
3If you're using Ubuntu, don't uninstall Python. There's a lot of things that depend on it. – D Malan Jul 03 '19 at 13:05
-
1@Dan uninstalling Python won't remove pip or the packages it installed. – Cam Jul 03 '19 at 13:33
-
this solution worked for me https://stackoverflow.com/questions/11248073/what-is-the-easiest-way-to-remove-all-packages-installed-by-pip/67379806#67379806 – Sathiamoorthy Aug 03 '21 at 12:28
2 Answers
58
The following command should do the trick:
pip freeze > requirements.txt && pip uninstall -r requirements.txt -y
Alternatively you can skip the creation of any intermediate files (i.e. requirements.txt):
pip uninstall -y -r <(pip freeze)
Giorgos Myrianthous
- 30,279
- 17
- 114
- 133
9
do following
store all the pip packages in requirements.txt
python -m pip freeze > requirements.txtremove all pip packages which menetioned in requirements.txt
python -m pip uninstall -r requirements.txt
sahasrara62
- 7,680
- 2
- 24
- 37
-
When I did this, it thrown me a fatal python error `Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding`, which states that PYTHONHOME and PYTHONPATH is not set – Naras-KS Dec 12 '20 at 18:30
-
@Naras-KS this may [help you](https://stackoverflow.com/questions/30767191/fatal-python-error-py-initialize-unable-to-load-the-file-system-codec-importe) – sahasrara62 Dec 12 '20 at 19:33
-
Thanks for the information. The error persists even after specifying the respective path to the environment variables, which I did manually. So, I have uninstalled it and reinstalled the python @sahasrara62 – Naras-KS Dec 12 '20 at 19:46
-
i sugges you to create a new question stating your problem, so other can help you better – sahasrara62 Dec 12 '20 at 19:55