2

Dreamhost upgraded a number of servers this weekend, including the one I was on. It broke my configuration, so as recommended I attempted to delete the virtual environment it was running on and attempted to re-set it up. However, when I try to navigate to the site, I get this:

Traceback (most recent call last):
  File "/home/thesp/mysite.com/env/lib/python2.7/site-packages/site.py", line 74, in <module>
    __boot()
  File "/home/thesp/mysite.com/env/lib/python2.7/site-packages/site.py", line 2, in __boot
    import sys, os, os.path
  File "/home/thesp/lib/python2.7/os.py", line 400, in <module>
    import UserDict
  File "/home/thesp/lib/python2.7/UserDict.py", line 83, in <module>
    import _abcoll
  File "/home/thesp/lib/python2.7/_abcoll.py", line 11, in <module>
    from abc import ABCMeta, abstractmethod
  File "/home/thesp/lib/python2.7/abc.py", line 8, in <module>
    from _weakrefset import WeakSet
ImportError: No module named _weakrefset

I've got Python 2.7.8 installed and running, and from shell access, both in and out of my virtual environment when I run Python, I'm pulling up the correct version (which is different from the native version installed, so it's finding my setup). Other posts which reference this error message seem to think it's a problem with not having an upgraded version of virtualenv, but its version is higher than the troublesome version. (I'm running 1.11.6.)

Weirder still, I can shell into Python, type from _weakrefset import WeakSet, and I don't get import errors. I'm running Django 1.6 and I can python manage.py runserver with no errors, but the web server is throwing up before it ever sees Django.

In the traceback, the first two lines are pulling from my virtual environment, but the remaining ones don't seem to be, and I have no idea why, or even if that's relevant.

Any advice on what I should do next? I've about pulled my hair out on this one! I can post any additional information that would help troubleshoot. Thanks!

Robin Levins
  • 53
  • 1
  • 6
  • 1
    "… the first two lines are pulling from my virtual environment, but the remaining ones don't seem to be, and I have no idea why, or even if that's relevant." That's almost certainly relevant. Do you have a `PYTHONPATH` variable in your environment? Or anything weird in the virtualenv's `site.py` file? Or any `.pth` files (maybe caused by accidentally using `easy_install` instead of `pip` within the virtualenv)? – abarnert Oct 07 '14 at 21:56
  • The PYTHONPATH is what I would hope it would be: `PYTHONPATH=/home/thesp/mysite.com/env/lib/python2.7/site-packages:` I do see two .pth files in my site's virtualenv directories: `./env/lib/python2.7/site-packages/easy-install.pth` `./env/lib/python2.7/site-packages/setuptools.pth` Where would I hunt down the virtualenv's site.py file? – Robin Levins Oct 07 '14 at 22:12
  • 1
    What's in the `.pth` files? Anything pointing back at the system (or user) stdlib or site-packages? Meanwhile, the `site.py` file is the first file in your traceback. – abarnert Oct 07 '14 at 22:28
  • Nothing interesting in the .pth files, as far as I can tell: ---**easy_install.pth**--- import sys; sys.__plen = len(sys.path) ./distribute-0.6.24-py2.7.egg ./pip-1.1-py2.7.egg ./setuptools-0.9.6-py2.7.egg ./virtualenv-1.11.6-py2.7.egg import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys, '__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new) ---**setuptools.pth**--- ./setuptools-0.9.6-py2.7.egg – Robin Levins Oct 07 '14 at 22:43
  • I don't see anything weird in the site.py file either. All it is doing is hitting `if __name__=='site': __boot()` on lines 73-74, then the first line of the __boot function is where it seems to have the problem. :/ – Robin Levins Oct 07 '14 at 22:44
  • Well, I'm out of ideas. When I get to a machine that has 2.7 with virtualenv later maybe I'll check back, but hopefully someone else can come up with the answer first… – abarnert Oct 07 '14 at 23:25
  • I think I've got a solution (see below) - thanks for your assistance, abarnert! – Robin Levins Oct 08 '14 at 14:29

1 Answers1

1

Well, I feel silly now. I went to the /home/thesp/lib/python2.7/ directory and downloaded _weakrefset.py, like so:

wget http://svn.python.org/projects/python/trunk/Lib/_weakrefset.py

...and now everything seems to be running fine. There was a _weakrefset.pyo file in the directory, so I'm not sure why _weakrefset.py never made it in, but this seems to have done the trick.

Now, that doesn't solve the mystery of why the stack trace switches directories like it does, but it's running now, so I'll take it for now!

Robin Levins
  • 53
  • 1
  • 6
  • 1
    It sounds like something is screwed up with your Python installation, and also with your virtual environment, so it might be safer to reinstall Python, reinstall `virtualenv`, and recreate the environment… but if this works for you, that may be good enough. At any rate, if this is the answer, accept it; don't let the fact that you wrote it stop you. – abarnert Oct 08 '14 at 18:33