26

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.

4
  • How exactly did you install python3.6 on 14.04? Apr 20, 2017 at 14:04
  • @steeldriver jonathanf repository: askubuntu.com/questions/865554/…
    – antonlab
    Apr 20, 2017 at 14:06
  • 2
    Maybe it's an issue with that ppa? Apr 20, 2017 at 14:53
  • @steeldriver I may have also installed python3.6 using another method (I think it's called from source?) so there may be conflicting stuff. Trying to figure out how to reinstall properly right now,
    – antonlab
    Apr 20, 2017 at 15:03

5 Answers 5

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

1
  • Just ran into this on another laptop I had laying around. These steps helped resolve my issues. :D
    – Hectron
    Jun 11, 2017 at 0: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 .
2
  • 2
    Thanks, this also worked after an upgrade from 16.04 to 18.04. Sep 7, 2018 at 10:36
  • Another Thanks. This solution was low effort, and worked like a charm after updating to 18.04 from 16.04.
    – BillMan
    Mar 18, 2020 at 15:17
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 :-)

1
  • 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! Jun 27, 2018 at 9: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).

2
  • Interesting. I'm still quite new to linux but I'll see what I can find about doing that.
    – antonlab
    Apr 25, 2017 at 1: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. May 16, 2017 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.