_lzma seems to fail fastbook import

I suffer the following ModuleNotFoundError when trying to import fastbook.
This on my local machine.
I’ve not had this failure in Colab.

I’ve been looking at the lzma source code and see the import of _lzma.
I’m curious if/how others have resolved this.
I saw one unanswered post on this topic from 2019…
Any feedback would be appreciated…
Thank you…

In [2]: import fastbook
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[2], line 1
----> 1 import fastbook

File ~/dvlp/python/fastai/venv3.9_fastai/lib/python3.9/site-packages/fastbook/__init__.py:3
      1 __version__ = "0.0.29"
      2 import matplotlib as mpl, pkgutil, requests, time
----> 3 from fastai.vision.all import *
      4 from fastdownload import download_url
      5 from pandas.api.types import CategoricalDtype

File ~/dvlp/python/fastai/venv3.9_fastai/lib/python3.9/site-packages/fastai/vision/all.py:1
----> 1 from . import models
      2 from ..basics import *
      3 from ..callback.all import *

File ~/dvlp/python/fastai/venv3.9_fastai/lib/python3.9/site-packages/fastai/vision/models/__init__.py:3
      1 from . import xresnet
      2 from . import unet
----> 3 from .tvm import *

File ~/dvlp/python/fastai/venv3.9_fastai/lib/python3.9/site-packages/fastai/vision/models/tvm.py:1
----> 1 from torchvision.models import *
      2 import types as _t
      4 _g = globals()

File ~/dvlp/python/fastai/venv3.9_fastai/lib/python3.9/site-packages/torchvision/__init__.py:5
      2 import warnings
      4 import torch
----> 5 from torchvision import datasets, io, models, ops, transforms, utils
      7 from .extension import _HAS_OPS
      9 try:

File ~/dvlp/python/fastai/venv3.9_fastai/lib/python3.9/site-packages/torchvision/datasets/__init__.py:1
----> 1 from ._optical_flow import FlyingChairs, FlyingThings3D, HD1K, KittiFlow, Sintel
      2 from ._stereo_matching import (
      3     CarlaStereo,
      4     CREStereo,
   (...)
     12     SintelStereo,
     13 )
     14 from .caltech import Caltech101, Caltech256

File ~/dvlp/python/fastai/venv3.9_fastai/lib/python3.9/site-packages/torchvision/datasets/_optical_flow.py:12
      9 from PIL import Image
     11 from ..io.image import _read_png_16
---> 12 from .utils import _read_pfm, verify_str_arg
     13 from .vision import VisionDataset
     16 __all__ = (
     17     "KittiFlow",
     18     "Sintel",
   (...)
     21     "HD1K",
     22 )

File ~/dvlp/python/fastai/venv3.9_fastai/lib/python3.9/site-packages/torchvision/datasets/utils.py:6
      4 import hashlib
      5 import itertools
----> 6 import lzma
      7 import os
      8 import os.path

File /usr/local/lib/python3.9/lzma.py:27
     25 import io
     26 import os
---> 27 from _lzma import *
     28 from _lzma import _encode_filter_properties, _decode_filter_properties
     29 import _compression

ModuleNotFoundError: No module named '_lzma'

In [3]: import lzma
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[3], line 1
----> 1 import lzma

File /usr/local/lib/python3.9/lzma.py:27
     25 import io
     26 import os
---> 27 from _lzma import *
     28 from _lzma import _encode_filter_properties, _decode_filter_properties
     29 import _compression

ModuleNotFoundError: No module named '_lzma'

221227

As update:
My local machine is a Lenovo 730s with Ubuntu 18.04 and no Cuda.
I revisited the https://docs.fast.ai/ doc and under ’ Installing’ section noticed the sentence:

"
To install with pip, use: pip install fastai. If you install with pip, you should install PyTorch first by following the PyTorch installation instructions.
"

  1. I deleted my current Python3.9 venv and started over.
  2. I created a new Python3.9 venv and updated my pip.
  3. I installed Jupyter Notebook,
  4. At the Pytorch ‘Get Started’ page I selected my installation as: Stable (1.13.1) : Linux : PIP : Python : CPU which provided a pip install command as:
    pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu
    This installed ok.
  5. pip install fastai then ran ok as previously.
  6. pip install fastbook then ran ok as previously.
  7. I opened an ipython repl.
  8. import fastai seemed to import ok.
  9. import fastbook failed with the same stack trace as provided above.

Attempting to from fastai.vision.all import * will obviously fail as well…

Thank you for any advice.

crumb for later:

221229
Issue Resolved.

I believe I have found this error due to an incomplete python build and install…
Currently the local machine runs Ubuntu 18.04 with system Python 3.6.
Further installs of python versions have been done as altinstall(s) to /usr/local/bin.

  • Based on the StackOverflow link above, others have found liblzma-dev and lzma libraries should be installed to the system prior to make altinstall of additional Python versions.
  • They were not present on this local machine.
  • It seems probable that if lzma libraries are not present, make altinstall of Python may just ‘skip over’, potentially leaving an incomplete Python install that may raise error down the road…?

As this local machine did not yet have python3.10 installed, rather than blow out previous versions and reinstall I decided to:

  1. apt install liblzma-dev liblzma-doc lzma per comments in the link above.
  2. Install new Python3.10 from /opt as an altinstall to /usr/local/bin
  3. Create a new “venv3.10” based on the fresh Python3.10.
  4. activate new “venv3.10”
  5. pip install fastbook
  6. and from an ipython repl under the new “venv3.10” verify I can now import fastbook and from fastai.vision.all import *

Issue seems resolved.