0

I accidentally installed a lib site package and I am unable to remove it. When I run my python script, it is unable to import a file as it is looking for my file in the wrong directory.

from lib import mailparser // This is the line of the code that is failing. I want it to look for a lib folder in my directory of my project, not in my system

It isn't a problem with my code as it was working before and I am not looking to change it.

When I run my script, I am receiving this error:

ImportError: cannot import name 'mailparser' from 'lib' (/usr/local/lib/python3.7/site-packages/lib/__init__.py)

Here it is looking for a lib folder in my system, not in my project directory. Subsequently, I try to uninstall the lib site package but I receive this:

WARNING: Skipping lib as it is not installed.

Why is from lib import mailparser looking for a folder on my system and not in my project directory as this was working before!

2 Answers2

0

This was my solution:

sudo rm -rf /usr/local/lib/python3.7/site-packages/lib/

I wouldn't recommend this to anyone else as I don't know what future problems I will face because of it. However, it worked for me and my code is now looking in the correct directory.

I tried pip uninstall lib but it was not uninstalling this module so I had to do a force remove.

0

Run this without your virtualenv:

pip uninstall -y <package_name>

to uninstall it from /user/local/lib

However, in order to use the package in your project directory, you must have a virtualenv set up.

cd <project_dir>
virtualenv -v venv
source venv/bin/activate  # don't forget this before running your code

pip install <package>

Then you should be able to run your code in project directory

Ron Marcelino
  • 463
  • 3
  • 8