How can I fix the messed up python package environment of my laptop?

64 Views Asked by At

I used to work with anaconda jupyter notebook last semester for my AI course. I installed and used a lot of packages (globally - stupid mistake, i know) using anaconda. Sometime towards the end of the semester, all my packages just stopped working, and even deleting and reinstalling them didn't work. i left it and moved on, uninstalled anaconda, and thought it was fine.

now, i installed opencv and numpy globally and neither VScode nor Pycharm see it. the packages don't work. it reminded me of my previous semesters' issues and i realized that now, my package-installing space is most likely screwed. how do I reset it all and fix it? and how should I go about installing packages in the future?

I tried resetting everything and uninstalling everything from the root folder, tried uninstalling anaconda, but to no avail. i want to revert everything to before i started this mess.

i am prepared to offer screenshots in case you need to better understand the issue.

1

There are 1 best solutions below

5
Meysam Kermani On BEST ANSWER

To start fresh and fix the issues with your package management in Python, especially after installing packages globally using Anaconda, you can take the following steps:

Resetting Python Environment: Uninstall Anaconda:

Ensure that Anaconda is completely uninstalled from your system. You can follow the official Anaconda uninstallation instructions for your operating system. Resetting Python Environment:

Remove any remaining traces of Anaconda and Python from your system by deleting Anaconda-related folders and removing Anaconda/Python paths from your system variables. Reinstall Python:

Download and install the latest version of Python from the official Python website. This will provide you with a clean Python environment. Virtual Environments:

Create a virtual environment for your projects using venv or virtualenv . This allows you to install packages for each project separately without affecting the global environment. Package Management:

Install packages using the package manager pip within your virtual environments. Activate the desired environment and use pip install package-name to install packages locally for that specific project. Example Workflow for Creating Virtual Environment and Installing Packages:

# Create a new virtual environment
python -m venv myenv

# Activate the virtual environment
# On Windows
myenv\Scripts\activate
# On macOS or Linux
source myenv/bin/activate

# Install required packages (e.g., opencv and numpy)
pip install opencv-python numpy

# Work on your project within this virtual environment

# Deactivate the virtual environment once you are done
deactivate

By following these steps and working within isolated virtual environments for your projects, you can avoid the issues caused by global package installations and ensure a clean and organized Python development environment.

Feel free to ask if you need further clarification or encounter any issues during the process!