27

I've tried searching around but haven't been able to find a good fix or anyone else with this specific error.

It happens after I try to install screen with apt-get install screen.

Error:

Setting up python3.6-minimal (3.6.1-1~14.04.york0) ...
Traceback (most recent call last):
  File "/usr/lib/python3.6/py_compile.py", line 6, in <module>
    import importlib._bootstrap_external
  File "/usr/lib/python3.6/importlib/__init__.py", line 57, in <module>
    import types
  File "/usr/lib/python3.6/types.py", line 171, in <module>
    import functools as _functools
  File "/usr/lib/python3.6/functools.py", line 23, in <module>
    from weakref import WeakKeyDictionary
  File "/usr/lib/python3.6/weakref.py", line 12, in <module>
    from _weakref import (
ImportError: cannot import name '_remove_dead_weakref'
dpkg: error processing package python3.6-minimal (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of python3.6:
 python3.6 depends on python3.6-minimal (= 3.6.1-1~14.04.york0); however:
  Package python3.6-minimal is not configured yet.

dpkg: error processing package python3.6 (--configure):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 python3.6-minimal
 python3.6
E: Sub-process /usr/bin/dpkg returned an error code (1)

Running Ubuntu 14.04.

Screen itself seems to have installed to it's latest version but the error message still has me worried.

Really at a loss here, any help is greatly appreciated.

antonlab
  • 371

6 Answers6

16

I recently ran into this issue when I was using Pycharm 2017.3.2 on Ubuntu 16.10.

My setup was:

I installed Python 3.6 from the python PPA. I had Python 3.6.0b4. However, I had just upgraded Ubuntu to 17.04, but had yet to reboot. When I rebooted my computer, it still was throwing that error. Therefore, I tried to see what the default python3.6 was in the terminal.

➜  ~ python3.6
Python 3.6.1 (default, Mar 22 2017, 06:17:05) 
[GCC 6.3.0 20170321] on linux
Type "help", "copyright", "credits" or "license" for more information.

Therefore, I realized that the Python that I had in my virtualenv might be outdated or pointing to an incorrect Python version.

Solution:

  • Made sure what version of Python 3.6 I had installed (3.6.1).
  • Removed my virtualenvironment.
  • Created new virtualenvironment using virtualenvwrapper: mkvirtualenv --python=python3.6

  • Installed the requirements with pip: pip install -r requirements.txt

tshepang
  • 1,967
Hectron
  • 161
  • Just ran into this on another laptop I had laying around. These steps helped resolve my issues. :D – Hectron Jun 11 '17 at 00:20
12

Happened to me after upgrading to Ubuntu 17.10. I fixed my python 2.7 virtualenv by going to its folder and entering:

virtualenv -p /usr/bin/python2.7 .
7

This happened to me after upgrading Ubuntu to 17.10.

I tried to run an application which was installed in a Python virtualenv.

I fixed it like this:

cd my-virtualenv-directory
virtualenv . --system-site-packages

The option --system-site-packages was needed because the application uses python-gtk from Ubuntu. I gues in most other cases it is not needed.

Now ImportError: cannot import name _remove_dead_weakref is gone :-)

guettli
  • 1,777
  • 1
    I faced this issue after upgrading to 18.04, and this fix worked for me too without needing to reinstall any of the virtual environments; thank you! – aspiring_sarge Jun 27 '18 at 09:21
4

I've recently run across a similar problem (my specific case was using a virtualenv after updating the system python installation). According to this debian bug report report, it seems that a local installation of python can interfere with the system one. Since you said you installed python from source, that is probably the problem. The linked bug report suggest not installing python into /usr/local (you can install to a different prefix using the --prefix=/some/other/directory flag to ./configure).

  • Interesting. I'm still quite new to linux but I'll see what I can find about doing that. – antonlab Apr 25 '17 at 01:46
  • I installed miniconda in my home and fortunately could solve the issue by opening a new shell after the one in which I set up miniconda. – Fred Schoen May 16 '17 at 10:08
0

I'm not sure why but using

python3 -m venv venv

instead of

virtualenv -p python3 venv

and then activating the venv or setting the paths manually, something like this

      export PYTHONPATH=.:\$PYTHONPATH
      VIRTUAL_ENV=`pwd`/venv
      export VIRTUAL_ENV
      PATH="\$VIRTUAL_ENV/bin:\$PATH"
      export PATH

worked for me.

I tried to do some quick searching of the different between virtualenv and python3 -m venv module...but didn't find anything.

Jerinaw
  • 281
0

I had the above error when I upgraded from Ubuntu 16.04 to 18.04, fixed like this (adjust target path to suit):

cp /usr/bin/python2.7 /home/username/virtualenvs/projectname/bin

The issue seems to be that an old version of the Python binary is in the virtualenvs/projectname/bin directory, which did not get upgraded during the OS upgrade.

A similar issue occured when upgrading from 14.04 to 16.04, I used a solution similar to the above to fix that, details: Python: no module named datetime?

StuBF
  • 1