35
AssertionError: Egg-link /home/daniel/other-rb/reviewboard does not match installed location of ReviewBoard (at /home/daniel/reviewboard)

I believe this was caused by me installing a package at an additional location using the same virtualenv.

How can I fix this problem? I'm guessing I need to redirect the Egg-link to match the installed location?

Stack trace:

(reviewboard-3.0) daniel@beepboop ~/reviewboard $ ./setup.py develop
/home/daniel/envs/reviewboard-3.0/local/lib/python2.7/site-packages/setuptools/dist.py:334: UserWarning: Normalizing '4.0alpha0' to '4.0a0'
  normalized_version,
running develop
Requirement already up-to-date: setuptools in /home/daniel/envs/reviewboard-3.0/lib/python2.7/site-packages
Requirement already up-to-date: appdirs>=1.4.0 in /home/daniel/envs/reviewboard-3.0/lib/python2.7/site-packages (from setuptools)
Requirement already up-to-date: packaging>=16.8 in /home/daniel/envs/reviewboard-3.0/lib/python2.7/site-packages (from setuptools)
Requirement already up-to-date: six>=1.6.0 in /usr/lib/python2.7/dist-packages (from setuptools)
Requirement already up-to-date: pyparsing in /home/daniel/envs/reviewboard-3.0/lib/python2.7/site-packages (from packaging>=16.8->setuptools)
Requirement already up-to-date: pip in /home/daniel/envs/reviewboard-3.0/lib/python2.7/site-packages
Obtaining file:///home/daniel/reviewboard
Requirement already satisfied: django-haystack<=2.4.999,>=2.3.1 in /usr/local/lib/python2.7/dist-packages (from ReviewBoard==4.0a0.dev0)
Requirement already satisfied: django-multiselectfield in /usr/local/lib/python2.7/dist-packages (from ReviewBoard==4.0a0.dev0)
Requirement already satisfied: Django<1.6.999,>=1.6.11 in /usr/local/lib/python2.7/dist-packages (from ReviewBoard==4.0a0.dev0)
Requirement already satisfied: django_evolution<=0.7.999,>=0.7.6 in /usr/local/lib/python2.7/dist-packages (from ReviewBoard==4.0a0.dev0)
Requirement already satisfied: Djblets<=0.10.999,>=0.10a0.dev in /home/daniel/djblets (from ReviewBoard==4.0a0.dev0)
Requirement already satisfied: docutils in /usr/local/lib/python2.7/dist-packages (from ReviewBoard==4.0a0.dev0)
Requirement already satisfied: markdown<2.4.999,>=2.4.0 in /usr/local/lib/python2.7/dist-packages (from ReviewBoard==4.0a0.dev0)
Requirement already satisfied: mimeparse>=0.1.3 in /usr/local/lib/python2.7/dist-packages (from ReviewBoard==4.0a0.dev0)
Requirement already satisfied: paramiko>=1.12 in /usr/lib/python2.7/dist-packages (from ReviewBoard==4.0a0.dev0)
Requirement already satisfied: pycrypto>=2.6 in /usr/lib/python2.7/dist-packages (from ReviewBoard==4.0a0.dev0)
Requirement already satisfied: Pygments>=2.1 in /usr/local/lib/python2.7/dist-packages (from ReviewBoard==4.0a0.dev0)
Requirement already satisfied: python-dateutil==1.5 in /usr/local/lib/python2.7/dist-packages (from ReviewBoard==4.0a0.dev0)
Requirement already satisfied: python-memcached in /usr/local/lib/python2.7/dist-packages (from ReviewBoard==4.0a0.dev0)
Requirement already satisfied: pytz in /usr/local/lib/python2.7/dist-packages (from ReviewBoard==4.0a0.dev0)
Requirement already satisfied: Whoosh>=2.6 in /usr/local/lib/python2.7/dist-packages (from ReviewBoard==4.0a0.dev0)
Requirement already satisfied: pillowfight in /usr/local/lib/python2.7/dist-packages (from Djblets<=0.10.999,>=0.10a0.dev->ReviewBoard==4.0a0.dev0)
Requirement already satisfied: django-pipeline==1.6.9 in /usr/local/lib/python2.7/dist-packages (from Djblets<=0.10.999,>=0.10a0.dev->ReviewBoard==4.0a0.dev0)
Requirement already satisfied: feedparser>=5.1.2 in /usr/lib/python2.7/dist-packages (from Djblets<=0.10.999,>=0.10a0.dev->ReviewBoard==4.0a0.dev0)
Requirement already satisfied: dnspython>=1.14.0 in /usr/local/lib/python2.7/dist-packages (from Djblets<=0.10.999,>=0.10a0.dev->ReviewBoard==4.0a0.dev0)
Requirement already satisfied: publicsuffix>=1.1 in /usr/local/lib/python2.7/dist-packages (from Djblets<=0.10.999,>=0.10a0.dev->ReviewBoard==4.0a0.dev0)
Requirement already satisfied: six>=1.4.0 in /usr/lib/python2.7/dist-packages (from python-memcached->ReviewBoard==4.0a0.dev0)
Requirement already satisfied: Pillow>=3.4.2 in /usr/local/lib/python2.7/dist-packages (from pillowfight->Djblets<=0.10.999,>=0.10a0.dev->ReviewBoard==4.0a0.dev0)
Requirement already satisfied: olefile in /usr/local/lib/python2.7/dist-packages (from Pillow>=3.4.2->pillowfight->Djblets<=0.10.999,>=0.10a0.dev->ReviewBoard==4.0a0.dev0)
Installing collected packages: ReviewBoard
  Found existing installation: ReviewBoard 4.0a0.dev0
Exception:
Traceback (most recent call last):
  File "/home/daniel/envs/reviewboard-3.0/local/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/home/daniel/envs/reviewboard-3.0/local/lib/python2.7/site-packages/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/home/daniel/envs/reviewboard-3.0/local/lib/python2.7/site-packages/pip/req/req_set.py", line 778, in install
    requirement.uninstall(auto_confirm=True)
  File "/home/daniel/envs/reviewboard-3.0/local/lib/python2.7/site-packages/pip/req/req_install.py", line 703, in uninstall
    '(at %s)' % (link_pointer, self.name, dist.location)
AssertionError: Egg-link /home/daniel/other-rb/reviewboard does not match installed location of ReviewBoard (at /home/daniel/reviewboard)
Traceback (most recent call last):
  File "./setup.py", line 434, in <module>
    'Topic :: Software Development :: Quality Assurance',
  File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/home/daniel/envs/reviewboard-3.0/local/lib/python2.7/site-packages/setuptools/command/develop.py", line 36, in run
    self.install_for_development()
  File "./setup.py", line 132, in install_for_development
    self._run_pip(['install', '-e', '.'])
  File "./setup.py", line 158, in _run_pip
    raise RuntimeError('Failed to run `%s`' % cmd)
RuntimeError: Failed to run `/home/daniel/envs/reviewboard-3.0/bin/python -m pip install -e .`
Daniel Paczuski Bak
  • 3,720
  • 8
  • 32
  • 78

6 Answers6

51

If you are using Python3.5 on Ubuntu:

rm ~/.local/lib/python3.5/site-packages/[Package name].egg-link

where [Package name] is the package that causes issues.

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
16

This problem happens if you move the source code directory after the egg-link file is created.

You can edit the proper egg-link file, /home/daniel/envs/reviewboard-3.0/local/lib/python2.7/site-packages/ReviewBoard.egg-link, replacing the line /home/daniel/other-rb/reviewboard with /home/daniel/reviewboard and retry.

Fish Monitor
  • 4,155
  • 3
  • 32
  • 53
  • 5
    Alternatively, you can delete the egg-info folder, and running `pip install -r requirements.txt` after that will add it to the location specified – Ed Harrod Nov 06 '17 at 10:52
  • Another egg-link path: `/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/[package].egg-link` – ahuigo May 31 '18 at 14:33
  • 1
    The interesting path on my Ubuntu system was `~/.local/lib/python3.5/site-packages` – Martin Thoma Sep 25 '18 at 09:30
10

You can silence the AssertionError by running Python in optimized mode, -O. And we can run the pip module through Python too, -m.

$ python -O -m pip uninstall <pkg-name>

Note: You may want to verify python -m pip is the same as pip. As sometimes the default Python and default pip can get out of sync.

$ pip -V
pip 20.3.1 from /usr/lib/python3.9/site-packages/pip (python 3.9)
$ python -m pip -V
pip 20.3.1 from /usr/lib/python3.9/site-packages/pip (python 3.9)
Peilonrayz
  • 3,129
  • 1
  • 25
  • 37
  • Running -O uninstall prompted me to remove the egg-link just like rm. Nice straightforward alternative. Thanks! – 0xDBFB7 Jul 23 '22 at 19:38
  • Running with `-O` skips all assertions. Not sure why pip contains such an assertion, but strangely this fixes it. – Teque5 Sep 12 '22 at 17:02
  • @Teque5 Why do you think pip shouldn't assert the file system is in the expected state before performing a dangerous operation? – Peilonrayz Sep 12 '22 at 17:05
  • @Peilonrayz The user is trying to remove a link. The target of the broken link doesn't exist. `pip` *should* attempt to remove the link, regardless if the target exists or not. The choice to assert an Error forces us to google a solution ∴ the assert should not exist. – Teque5 Sep 13 '22 at 20:21
2

If you're building your package with Python

import glob
import os
import sys

def get_egg_file(module_name):
    def f(packages):
        return glob.glob(
            os.path.join(os.path.dirname(os.path.dirname(sys.executable)),
                         'lib', 'python*', packages, module_name + '.egg-link'))

    return f('site-packages') or f('dist-packages')


egg_file = get_egg_file('YOUR_PACKAGE_NAME')
if egg_file:
    os.remove(egg_file[0])

Note that this should be executed in the target virtualenv or system python environment for sys.executable to resolve to what you want.

crizCraig
  • 8,487
  • 6
  • 54
  • 53
  • I had to remove the `python*` and pass in my interpreter-prefix (dirpath of sys.executable for the virtualenv), since I am using pexpect/wexpect to automate the updating of many virtualenvs and not actually using the virtualenv to uninstall things inside it. Additionally, I added a new arg to control whether I wanted to delete the EGG or the PTH file (since both seem necessary to delete if present). – nmz787 Aug 26 '20 at 10:07
1

Just delete your .tox folder. When you run tox again a new .tox/ directory gets generated with the correct paths.

Joe Gasewicz
  • 1,252
  • 15
  • 20
0

I fixed this by upgrading pip from 6 to 9.

Chris
  • 738
  • 8
  • 11