Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup: Fix package installation woes with setuptools/backports.tarfile, and PyInstaller #201

Merged
merged 2 commits into from
Jul 18, 2024

Conversation

amotl
Copy link
Member

@amotl amotl commented Jul 17, 2024

About

Check why GH-196 fails, and resolve it.

Investigations

Details I

Fails on Python 3.8.

-- https://github.com/crate/cratedb-toolkit/actions/runs/9982521975/job/27589490156?pr=196#step:6:229

/path/to/lib/python3.8/site-packages/setuptools/_vendor/jaraco/context.py:17: ImportError
ImportError: cannot import name 'tarfile' from 'backports' (/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/backports/__init__.py)

Details II

Fails on all test matrix slots.

PyInstaller.exceptions.ImportErrorWhenRunningHook: Failed to import module __PyInstaller_hooks_0_importlib_metadata required by hook for module /opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/site-packages/PyInstaller/hooks/hook-importlib_metadata.py. Please check whether module __PyInstaller_hooks_0_importlib_metadata actually exists and whether the hook is compatible with your version of /opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/site-packages/PyInstaller/hooks/hook-importlib_metadata.py: You might want to read more about hooks in the manual and provide a pull-request to improve PyInstaller.

-- https://github.com/crate/cratedb-toolkit/actions/runs/9983011865/job/27589798960?pr=201#step:5:198

References

Solution

Downgrading to setuptools<71 on the two spots where this happened worked just well, apparently?

amotl added 2 commits July 18, 2024 01:50
/path/to/lib/python3.8/site-packages/setuptools/_vendor/jaraco/context.py:17: ImportError

ImportError: cannot import name 'tarfile' from 'backports' (/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/backports/__init__.py)
PyInstaller.exceptions.ImportErrorWhenRunningHook: Failed to import module __PyInstaller_hooks_0_importlib_metadata required by hook for module /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/PyInstaller/hooks/hook-importlib_metadata.py.
@amotl amotl force-pushed the amo/fix-backports-tarfile branch from 4d87261 to a4ba5e8 Compare July 17, 2024 23:52
@amotl amotl changed the title Setup: Fix ImportError: cannot import name 'tarfile' from 'backports' Setup: Fix package installation woes with setuptools/backports.tarfile, and PyInstaller Jul 17, 2024
@amotl amotl marked this pull request as ready for review July 18, 2024 00:03
@amotl amotl merged commit 731e007 into main Jul 18, 2024
11 checks passed
@amotl amotl deleted the amo/fix-backports-tarfile branch July 18, 2024 00:03
@nayanjha16
Copy link

nayanjha16 commented Aug 9, 2024

I am still facing the same issue even after changing the versions of setuptools. I tried downgrading it to <71 as well. Doesn't seem to work for me.

Still getting the error ImportError: cannot import name 'tarfile' from 'backports' on importing mlflow.

{
	"name": "ImportError",
	"message": "cannot import name 'tarfile' from 'backports' (c:\\Users\\NayanAnand\\anaconda3\\lib\\site-packages\\backports\\__init__.py)",
	"stack": "---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
~\\AppData\\Local\\Temp\\ipykernel_25044\\2545141633.py in <module>
      3 from sklearn.ensemble import RandomForestRegressor
      4 
----> 5 from mlflow import MlflowClient

c:\\Users\\NayanAnand\\anaconda3\\lib\\site-packages\\mlflow\\__init__.py in <module>
     32 
     33 __version__ = VERSION
---> 34 from mlflow import (
     35     artifacts,  # noqa: F401
     36     client,  # noqa: F401

c:\\Users\\NayanAnand\\anaconda3\\lib\\site-packages\\mlflow\\models\\__init__.py in <module>
     42 )
     43 from mlflow.models.flavor_backend import FlavorBackend
---> 44 from mlflow.models.model import Model, get_model_info, set_model
     45 from mlflow.models.model_config import ModelConfig
     46 from mlflow.models.python_api import build_docker

c:\\Users\\NayanAnand\\anaconda3\\lib\\site-packages\\mlflow\\models\\model.py in <module>
     26 from mlflow.utils.databricks_utils import get_databricks_runtime_version, is_in_databricks_runtime
     27 from mlflow.utils.docstring_utils import LOG_MODEL_PARAM_DOCS, format_docstring
---> 28 from mlflow.utils.environment import (
     29     _CONDA_ENV_FILE_NAME,
     30     _PYTHON_ENV_FILE_NAME,

c:\\Users\\NayanAnand\\anaconda3\\lib\\site-packages\\mlflow\\utils\\environment.py in <module>
     22 from mlflow.utils.os import is_windows
     23 from mlflow.utils.process import _exec_cmd
---> 24 from mlflow.utils.requirements_utils import (
     25     _infer_requirements,
     26     _parse_requirements,

c:\\Users\\NayanAnand\\anaconda3\\lib\\site-packages\\mlflow\\utils\\requirements_utils.py in <module>
     18 
     19 import importlib_metadata
---> 20 import pkg_resources  # noqa: TID251
     21 from packaging.requirements import Requirement
     22 from packaging.version import InvalidVersion, Version

c:\\Users\\NayanAnand\\anaconda3\\lib\\site-packages\\pkg_resources\\__init__.py in <module>
     93 
     94 import packaging.specifiers
---> 95 from jaraco.text import (
     96     yield_lines,
     97     drop_comment,

c:\\Users\\NayanAnand\\anaconda3\\lib\\site-packages\\setuptools\\_vendor\\jaraco\\text\\__init__.py in <module>
     10 
     11 from jaraco.functools import compose, method_cache
---> 12 from jaraco.context import ExceptionTrap
     13 
     14 

c:\\Users\\NayanAnand\\anaconda3\\lib\\site-packages\\setuptools\\_vendor\\jaraco\\context.py in <module>
     15 
     16 if sys.version_info < (3, 12):
---> 17     from backports import tarfile
     18 else:
     19     import tarfile

ImportError: cannot import name 'tarfile' from 'backports' (c:\\Users\\NayanAnand\\anaconda3\\lib\\site-packages\\backports\\__init__.py)"
}

Any suggestions on how to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants