setuptools: ImportError: cannot import name 'tarfile' from 'backports' and RemoveError: 'setuptools' is a dependency of conda and cannot be removed from conda's operating environment.

setuptools version

setuptools==75.2.0

Python version

Python 3.11.5

Environment information

Conda base environment

Description

I tried to update anaconda navigator using conda update -n base conda, but it then ran into this error

(base) C:\Users\namgi>conda update -n base conda
Channels:
 - conda-forge
 - defaults
 - anaconda
Platform: win-64
Collecting package metadata (repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: C:\Users\namgi\anaconda3

  added / updated specs:
    - conda


The following packages will be UPDATED:

  openssl                                  3.3.2-h2466b09_0 --> 3.4.0-h2466b09_0
  wordcloud                           1.9.3-py311he736701_2 --> 1.9.4-py311he736701_0


Proceed ([y]/n)? y


Downloading and Extracting Packages:

Preparing transaction: done
Verifying transaction: failed

RemoveError: 'setuptools' is a dependency of conda and cannot be removed from
conda's operating environment.

I tried debugging but I cannot find anything helpful. After that, I opened anaconda navigator but It didn’t work, I then used anaconda-navigator in anaconda prompt then find this

(base) C:\Users\namgi>anaconda-navigator
Traceback (most recent call last):
  File "C:\Users\namgi\anaconda3\Scripts\anaconda-navigator-script.py", line 6, in <module>
    from anaconda_navigator.app.main import main
  File "C:\Users\namgi\anaconda3\Lib\site-packages\anaconda_navigator\app\main.py", line 19, in <module>
    from anaconda_navigator.app.start import start_app
  File "C:\Users\namgi\anaconda3\Lib\site-packages\anaconda_navigator\app\start.py", line 32, in <module>
    from anaconda_navigator.widgets.main_window import MainWindow
  File "C:\Users\namgi\anaconda3\Lib\site-packages\anaconda_navigator\widgets\main_window\__init__.py", line 28, in <module>
    from anaconda_navigator.api.anaconda_api import AnacondaAPI
  File "C:\Users\namgi\anaconda3\Lib\site-packages\anaconda_navigator\api\anaconda_api.py", line 29, in <module>
    from anaconda_navigator.api.client_api import ClientAPI
  File "C:\Users\namgi\anaconda3\Lib\site-packages\anaconda_navigator\api\client_api.py", line 21, in <module>
    import binstar_client
  File "C:\Users\namgi\anaconda3\Lib\site-packages\binstar_client\__init__.py", line 15, in <module>
    from pkg_resources import parse_version as pv
  File "C:\Users\namgi\anaconda3\Lib\site-packages\pkg_resources\__init__.py", line 95, in <module>
    from jaraco.text import drop_comment, join_continuation, yield_lines
  File "C:\Users\namgi\anaconda3\Lib\site-packages\setuptools\_vendor\jaraco\text\__init__.py", line 12, in <module>
    from jaraco.context import ExceptionTrap
  File "C:\Users\namgi\anaconda3\Lib\site-packages\setuptools\_vendor\jaraco\context.py", line 17, in <module>
    from backports import tarfile
ImportError: cannot import name 'tarfile' from 'backports' (C:\Users\namgi\anaconda3\Lib\site-packages\backports\__init__.py)

I search many issues ImportError: cannot import name ‘tarfile’ from ‘backports’ #5, [BUG] 71.0.0 fails with backports.tarfile on Python 3.8 when other backports imported #4476, Reset the backports module when enabling vendored packages. #4486, Setup: Fix package installation woes with setuptools/backports.tarfile, and PyInstaller #201, [BUG] 71.0.0 fails PyInstaller builds #4477, [BUG] 71.0.4 and 71.1.0 fail with ImportError: cannot import name ‘tarfile’ from ‘backports’ #4509

the common solution is to change version but what should i downgrade to

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 18 (10 by maintainers)

Most upvoted comments

Installing via pip helped me to solve the issue, I tried some steps from above without success:

pip install backports.tarfile

Hi @nguyenphucnamgiang could you please install the latest version of backports.tarfile>=1.2 in your enviornment and see if it works?

thank you @abravalheri, I will move to conda now

Ah ok, thank you. that clarified the problem.

In this case, it seems like something to be discussed with conda maintainers, as it looks like a behaviour introduced by conda itself.

I don’t even have backports.tarfile in my base environment

Umm, backports is supposed to be a namespace, so there might be other backports.* packages installed that are interfering with this.

I can see that you have a file C:\Users\namgi\anaconda3\Lib\site-packages\backports\__init__.py. That is weird and probably the origin of the problem because backports.tarfile expects backports to be a namespace.

I suppose you can try:

  • Removing C:\Users\namgi\anaconda3\Lib\site-packages\backports\__init__.py

OR

  1. Temporarily renaming C:\Users\namgi\anaconda3\Lib\site-packages\backports\__init__.py to something else like _bkp.py
  2. Either installing backports.tarfile>=1.2 or setuptools[core]
  3. You may be able to return the file to its original name now that backports.tarfile>=1.2 is installed…

Umm, is it a deadlock? You cannot install backports.tarfile>=1.2 because setuptools don’t work and setuptools cannot work because you cannot install backports.tarfile>=1.2?

Can you try the following:

  • Completely uninstall backports.tarfile
  • Then install backports.tarfile>=1.2

If that does not work, you might have to start a fresh virtual environment 😢.