Search code examples
pythonvirtualenvsetuptools

Removing the symlink doesn't clear a package from the corresponding virtualenv


I just set up a sample project via setuptools. The setup.py is:

from setuptools import setup

setup(
    name='test_project',
    version='0.1',
    packages=['test_project'],
    zip_safe=False
)

I added this package to my virtualenv via python setup.py develop which placed a corresponding symlink in my virtualenv: ./lib/python2.7/site-packages/test-project.egg-link.

To remove the package I thought it would be sufficient to remove just the symlink from the virtualenv. However after removing the symlink python -c "import test_project" still succeeds. Are there any caches which I need to remove in addition?

(I created the virtualenv with the option --system-site-packages if that is of any importance; the package is not installed system-wide, i.e. python -c "import test_project" fails outside of the virtualenv.)

(I have this problem with both Python 2 and Python 3.)


Solution

  • You'll have to remove your package from the easy-install.pth in your site-packages. It should be ./lib/python2.7/site-packages/easy-install.pth in your case.

    I find it a lot more convenient to install development versions of python packages via pip with pip install -e . from the project directory (or pip install -e [projectpath] from anywhere). Packages installed that way can be easily removed with pip uninstall [packagename]