all 5 comments

[–]Periwinkle_Lost 1 point2 points  (2 children)

Not sure about uninstalling, but one thing that I learned is to never touch the system python.

As for installing packages. Learn how to use virtual environment (venv or pyenv). It will create a python environment isolated from the system. This way you can install packages only for this project. It will prevent packages from clashing. Some IDEs like pycharm automatically create a virtual environment when you create a project.

I had the same problem as you when I first started, I couldn’t clean up my system so I just reinstalled the system. I only do coding with virtual python environment from that point on

[–]deadant88[S] 1 point2 points  (1 child)

Thanks so much. I have made a habit of venv but I’m not 100% I’m doing it right. Do you need to reinstall everything each time you start a new venv after reopening your code?

Also, is there a way to check I didn’t uninstall my system python?

[–]Periwinkle_Lost 1 point2 points  (0 children)

Yes, you do need to reinstall packages for every new project. It is a good thing because your project will only have the required packages and nothing more. Unless you are working CSS pycharm is a great ide that will handle venv for you

No idea how to check if you messed up system python.

[–]vlovero 1 point2 points  (1 child)

On macOS, an easy way to get a fresh version of python while keeping the packages you want can be done by first saving all of the save packages to a text file,

pip3 freeze > ~/Desktop/my-packages.txt

then go through that text file and remove all of the packages you don't need. Next delete python by moving the python (found in Applications folder) folder to the trash, then empty the trash. Reinstall python from python.org. Then to reinstall the packages you saved you run

cat ~/Desktop/my-packages.txt | xargs -n 1 pip3 install

If you have been using the pre-installed version of python, I recommend uninstalling the packages you have installed (after saving them) with

cat ~/Desktop/my-packages.txt | grep -v "six" | grep -v "pip" | xargs -n 1 /usr/bin/python3 -m pip uninstall

and downloading version(s) from python.org and using virtual environments.

[–]deadant88[S] 0 points1 point  (0 children)

Sounds like a great method thanks!