Can't import fastai to local Jupyter notebook

0

I am trying to run a notebook locally and so I want to import the following packages:

import pandas as pd

from fastai import *
from fastai.vision import *
from fastai.callbacks.hooks import *
from pathlib import Path
import os, git, glob, shutil

But it is throwing this error:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-2-10b32c200355> in <module>
      1 import pandas as pd
      2 
----> 3 from fastai import *
      4 from fastai.vision import *
      5 from fastai.callbacks.hooks import *

ModuleNotFoundError: No module named 'fastai'

This shouldn’t be the case because I already have fastai installed on my machine via pip. Is there a way to use my local libraries on a notebook that is also local?

Do you have both a native Python installation and anaconda side by side? Or do you have several conda environments? In the latter case https://github.com/Anaconda-Platform/nb_conda_kernels could be an interesting tool for you to keep track of your current environment.

I have no conda installed. I try to avoid it as best as I can. I just have the standalone jupyterlabs and notebook installed.

If a library is installed, then it is installed and Jupyter does not create any disturbances on that topic. Therefore, I guess that either the installation failed and you did not realize that or you installed it somewhere else, e.g. you have Python 2 and Python 3 side by side on your machine and happened to use the ‘wrong’ pip for Jupyter.

I do have both Python versions installed side by side. What pip do I use for Python 3? And why do I need to use pip again on Jupyter when the library is installed?

And it is 100% installed on my machine. I can use these libraries on Pycharm.

Then I bet you accidentally installed fastai for the wrong Pyrhon version. Please look deeply into how to use pip properly and send the command line logs in case you persist to have troubles.

I tried using pip3. I think I got it working. I will post updates. Thank you.

Do you have any update on this? I am also running into same problem. I am trying to run notebook locally and it says ModuleNotFoundError: No module named ‘fastai’. But I can do !pip list | grep fastai and I can see 2.7.13 coming!

Update? Most likely you are dealing with the same situation 1kastner is describing above in the last post by him and not understanding 1kastner’s advice how to fix.

If you do !pip list | grep fastai and see it on your system, it doesn’t mean Jupyter is able to use that. Jupyter can only use things installed to certain environments unless you otherwise connect it. You don’t tell us how you installed fastai to wherever you installed it; however, it’s concerning that you are using !pip and not %pip. Try this to install it to the environment that Jupyter is using:

  • Open the Jupyter .ipynb file where you want to use fastai in your Jupyter
  • Make a new cell near the top and run %pip install fastai.
  • Let that run entirely and then restart the kernel.
  • It probably isn’t necessary for this package, but if you were installing something more complicated like ipywidgets or an extension, I’d say to even shut down Jupyter and restart it, or at least try refreshing the browser page to let the changes propagate entirely.
  • Finally, when the kernel has been restarted (and the browser page refreshed/Jupyter restarted for complex packages) then try the appropriate import statement. For this case, you can use from fastai.text.all import *, based on one of the many import commands listed at fastai’s quickstart page.

Later you can try %pip list | grep fastai and see what that says. (Most likely, if you examine the results from %pip list vs. !pip list, , or if you ran %pip list before doing what I suggested, there’d be some difference.).
You should read more about things here and substitute ‘fastai’ in place of ‘selenium’.

When I use %pip install fastai I get following error

Failed to build bcolz lxml
ERROR: Could not build wheels for bcolz, lxml, which is required to install pyproject.toml-based projects

So I ran following command also
%pip install bcolz but this also failed

Failed to build bcolz
ERROR: Could not build wheels for bcolz, which is required to install pyproject.toml-based projects

When I run !pip install fastai in jupyter notebook it succeeds without any complaint. Strangely I install it in Jupyter notebook and can use it in terminal without any issues!

Below are the log outputs of attempts to try installing lxml and bcolz!

%pip install lxml

Requirement already satisfied: lxml in /opt/homebrew/Cellar/jupyterlab/4.0.10/libexec/lib/python3.12/site-packages (5.1.0)
Note: you may need to restart the kernel to use updated packages.

%pip install bcolz

Collecting bcolz
  Using cached bcolz-1.2.1.tar.gz (1.5 MB)
  Preparing metadata (setup.py) ... done
Collecting numpy>=1.7 (from bcolz)
  Using cached numpy-1.26.3-cp312-cp312-macosx_11_0_arm64.whl.metadata (61 kB)
Using cached numpy-1.26.3-cp312-cp312-macosx_11_0_arm64.whl (13.7 MB)
Building wheels for collected packages: bcolz
  Building wheel for bcolz (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [111 lines of output]
      /private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-install-xphqykjk/bcolz_04533703bde743f7826034d3ef7cc2a5/setup.py:23: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
        from pkg_resources import resource_filename
      /opt/homebrew/lib/python3.12/site-packages/setuptools/__init__.py:80: _DeprecatedInstaller: setuptools.installer and fetch_build_eggs are deprecated.
      !!
      
              ********************************************************************************
              Requirements should be satisfied by a PEP 517 installer.
              If you are using pip, you can try `pip install --use-pep517`.
              ********************************************************************************
      
      !!
        dist.fetch_build_eggs(dist.setup_requires)
      WARNING setuptools_scm.pyproject_reading toml section missing 'pyproject.toml does not contain a tool.setuptools_scm section'
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.macosx-13-arm64-cpython-312
      creating build/lib.macosx-13-arm64-cpython-312/bcolz
      copying bcolz/py2help_tests.py -> build/lib.macosx-13-arm64-cpython-312/bcolz
      copying bcolz/version.py -> build/lib.macosx-13-arm64-cpython-312/bcolz
      copying bcolz/toplevel.py -> build/lib.macosx-13-arm64-cpython-312/bcolz
      copying bcolz/ctable.py -> build/lib.macosx-13-arm64-cpython-312/bcolz
      copying bcolz/__init__.py -> build/lib.macosx-13-arm64-cpython-312/bcolz
      copying bcolz/utils.py -> build/lib.macosx-13-arm64-cpython-312/bcolz
      copying bcolz/chunked_eval.py -> build/lib.macosx-13-arm64-cpython-312/bcolz
      copying bcolz/defaults.py -> build/lib.macosx-13-arm64-cpython-312/bcolz
      copying bcolz/attrs.py -> build/lib.macosx-13-arm64-cpython-312/bcolz
      copying bcolz/py2help.py -> build/lib.macosx-13-arm64-cpython-312/bcolz
      copying bcolz/arrayprint.py -> build/lib.macosx-13-arm64-cpython-312/bcolz
      creating build/lib.macosx-13-arm64-cpython-312/bcolz/tests
      copying bcolz/tests/test_ndcarray.py -> build/lib.macosx-13-arm64-cpython-312/bcolz/tests
      copying bcolz/tests/test_carray_objects.py -> build/lib.macosx-13-arm64-cpython-312/bcolz/tests
      copying bcolz/tests/test_attrs.py -> build/lib.macosx-13-arm64-cpython-312/bcolz/tests
      copying bcolz/tests/__init__.py -> build/lib.macosx-13-arm64-cpython-312/bcolz/tests
      copying bcolz/tests/all.py -> build/lib.macosx-13-arm64-cpython-312/bcolz/tests
      copying bcolz/tests/common.py -> build/lib.macosx-13-arm64-cpython-312/bcolz/tests
      copying bcolz/tests/test_queries.py -> build/lib.macosx-13-arm64-cpython-312/bcolz/tests
      copying bcolz/tests/test_ctable.py -> build/lib.macosx-13-arm64-cpython-312/bcolz/tests
      copying bcolz/tests/test_carray.py -> build/lib.macosx-13-arm64-cpython-312/bcolz/tests
      copying bcolz/carray_ext.pxd -> build/lib.macosx-13-arm64-cpython-312/bcolz
      running build_ext
      Compiling bcolz/carray_ext.pyx because it changed.
      [1/1] Cythonizing bcolz/carray_ext.pyx
      /private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-install-xphqykjk/bcolz_04533703bde743f7826034d3ef7cc2a5/.eggs/Cython-3.0.8-py3.12.egg/Cython/Compiler/Main.py:381: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-install-xphqykjk/bcolz_04533703bde743f7826034d3ef7cc2a5/bcolz/carray_ext.pxd
        tree = Parsing.p_module(s, pxd, full_module_name)
      
      Error compiling Cython file:
      ------------------------------------------------------------
      ...
              # Create the final container and fill it
              out = carray([], dtype=newdtype, cparams=self.cparams,
                             expectedlen=newlen,
                             rootdir=rootdir, mode='w')
              if newlen < ilen:
                  rsize = isize / newlen
                                ^
      ------------------------------------------------------------
      
      bcolz/carray_ext.pyx:1685:26: Cannot assign type 'double' to 'npy_intp'
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-install-xphqykjk/bcolz_04533703bde743f7826034d3ef7cc2a5/setup.py", line 161, in <module>
          setup(
        File "/opt/homebrew/lib/python3.12/site-packages/setuptools/__init__.py", line 103, in setup
          return distutils.core.setup(**attrs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/opt/homebrew/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 185, in setup
          return run_commands(dist)
                 ^^^^^^^^^^^^^^^^^^
        File "/opt/homebrew/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
          dist.run_commands()
        File "/opt/homebrew/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
          self.run_command(cmd)
        File "/opt/homebrew/lib/python3.12/site-packages/setuptools/dist.py", line 963, in run_command
          super().run_command(command)
        File "/opt/homebrew/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/opt/homebrew/lib/python3.12/site-packages/wheel/bdist_wheel.py", line 368, in run
          self.run_command("build")
        File "/opt/homebrew/lib/python3.12/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
          self.distribution.run_command(command)
        File "/opt/homebrew/lib/python3.12/site-packages/setuptools/dist.py", line 963, in run_command
          super().run_command(command)
        File "/opt/homebrew/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/opt/homebrew/lib/python3.12/site-packages/setuptools/_distutils/command/build.py", line 131, in run
          self.run_command(cmd_name)
        File "/opt/homebrew/lib/python3.12/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
          self.distribution.run_command(command)
        File "/opt/homebrew/lib/python3.12/site-packages/setuptools/dist.py", line 963, in run_command
          super().run_command(command)
        File "/opt/homebrew/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/opt/homebrew/lib/python3.12/site-packages/setuptools/_distutils/command/build_ext.py", line 345, in run
          self.build_extensions()
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-install-xphqykjk/bcolz_04533703bde743f7826034d3ef7cc2a5/setup.py", line 77, in build_extensions
          cython_build_ext.build_extensions(self)
        File "/opt/homebrew/lib/python3.12/site-packages/setuptools/_distutils/command/build_ext.py", line 467, in build_extensions
          self._build_extensions_serial()
        File "/opt/homebrew/lib/python3.12/site-packages/setuptools/_distutils/command/build_ext.py", line 493, in _build_extensions_serial
          self.build_extension(ext)
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-install-xphqykjk/bcolz_04533703bde743f7826034d3ef7cc2a5/.eggs/Cython-3.0.8-py3.12.egg/Cython/Distutils/build_ext.py", line 130, in build_extension
          new_ext = cythonize(
                    ^^^^^^^^^^
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-install-xphqykjk/bcolz_04533703bde743f7826034d3ef7cc2a5/.eggs/Cython-3.0.8-py3.12.egg/Cython/Build/Dependencies.py", line 1154, in cythonize
          cythonize_one(*args)
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-install-xphqykjk/bcolz_04533703bde743f7826034d3ef7cc2a5/.eggs/Cython-3.0.8-py3.12.egg/Cython/Build/Dependencies.py", line 1321, in cythonize_one
          raise CompileError(None, pyx_file)
      Cython.Compiler.Errors.CompileError: bcolz/carray_ext.pyx
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for bcolz
  Running setup.py clean for bcolz
Failed to build bcolz
ERROR: Could not build wheels for bcolz, which is required to install pyproject.toml-based projects
Note: you may need to restart the kernel to use updated packages.

%pip install --use-pep517 bcolz

  Using cached bcolz-1.2.1.tar.gz (1.5 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Collecting numpy>=1.7 (from bcolz)
  Using cached numpy-1.26.3-cp312-cp312-macosx_11_0_arm64.whl.metadata (61 kB)
Using cached numpy-1.26.3-cp312-cp312-macosx_11_0_arm64.whl (13.7 MB)
Building wheels for collected packages: bcolz
  Building wheel for bcolz (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for bcolz (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [113 lines of output]
      <string>:23: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
      WARNING setuptools_scm.pyproject_reading toml section missing 'pyproject.toml does not contain a tool.setuptools_scm section'
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.macosx-13-arm64-cpython-312
      creating build/lib.macosx-13-arm64-cpython-312/bcolz
      copying bcolz/py2help_tests.py -> build/lib.macosx-13-arm64-cpython-312/bcolz
      copying bcolz/version.py -> build/lib.macosx-13-arm64-cpython-312/bcolz
      copying bcolz/toplevel.py -> build/lib.macosx-13-arm64-cpython-312/bcolz
      copying bcolz/ctable.py -> build/lib.macosx-13-arm64-cpython-312/bcolz
      copying bcolz/__init__.py -> build/lib.macosx-13-arm64-cpython-312/bcolz
      copying bcolz/utils.py -> build/lib.macosx-13-arm64-cpython-312/bcolz
      copying bcolz/chunked_eval.py -> build/lib.macosx-13-arm64-cpython-312/bcolz
      copying bcolz/defaults.py -> build/lib.macosx-13-arm64-cpython-312/bcolz
      copying bcolz/attrs.py -> build/lib.macosx-13-arm64-cpython-312/bcolz
      copying bcolz/py2help.py -> build/lib.macosx-13-arm64-cpython-312/bcolz
      copying bcolz/arrayprint.py -> build/lib.macosx-13-arm64-cpython-312/bcolz
      creating build/lib.macosx-13-arm64-cpython-312/bcolz/tests
      copying bcolz/tests/test_ndcarray.py -> build/lib.macosx-13-arm64-cpython-312/bcolz/tests
      copying bcolz/tests/test_carray_objects.py -> build/lib.macosx-13-arm64-cpython-312/bcolz/tests
      copying bcolz/tests/test_attrs.py -> build/lib.macosx-13-arm64-cpython-312/bcolz/tests
      copying bcolz/tests/__init__.py -> build/lib.macosx-13-arm64-cpython-312/bcolz/tests
      copying bcolz/tests/all.py -> build/lib.macosx-13-arm64-cpython-312/bcolz/tests
      copying bcolz/tests/common.py -> build/lib.macosx-13-arm64-cpython-312/bcolz/tests
      copying bcolz/tests/test_queries.py -> build/lib.macosx-13-arm64-cpython-312/bcolz/tests
      copying bcolz/tests/test_ctable.py -> build/lib.macosx-13-arm64-cpython-312/bcolz/tests
      copying bcolz/tests/test_carray.py -> build/lib.macosx-13-arm64-cpython-312/bcolz/tests
      copying bcolz/carray_ext.pxd -> build/lib.macosx-13-arm64-cpython-312/bcolz
      running build_ext
      Compiling bcolz/carray_ext.pyx because it changed.
      [1/1] Cythonizing bcolz/carray_ext.pyx
      /private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-build-env-m3s458ec/normal/lib/python3.12/site-packages/Cython/Compiler/Main.py:381: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-install-rr8_2r31/bcolz_d374897891334aac8e8095723e5b4c5f/bcolz/carray_ext.pxd
        tree = Parsing.p_module(s, pxd, full_module_name)
      
      Error compiling Cython file:
      ------------------------------------------------------------
      ...
              # Create the final container and fill it
              out = carray([], dtype=newdtype, cparams=self.cparams,
                             expectedlen=newlen,
                             rootdir=rootdir, mode='w')
              if newlen < ilen:
                  rsize = isize / newlen
                                ^
      ------------------------------------------------------------
      
      bcolz/carray_ext.pyx:1685:26: Cannot assign type 'double' to 'npy_intp'
      Traceback (most recent call last):
        File "/opt/homebrew/Cellar/jupyterlab/4.0.10/libexec/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/opt/homebrew/Cellar/jupyterlab/4.0.10/libexec/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/opt/homebrew/Cellar/jupyterlab/4.0.10/libexec/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 251, in build_wheel
          return _build_backend().build_wheel(wheel_directory, config_settings,
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-build-env-m3s458ec/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 404, in build_wheel
          return self._build_with_temp_dir(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-build-env-m3s458ec/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 389, in _build_with_temp_dir
          self.run_setup()
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-build-env-m3s458ec/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 480, in run_setup
          super(_BuildMetaLegacyBackend, self).run_setup(setup_script=setup_script)
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-build-env-m3s458ec/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 311, in run_setup
          exec(code, locals())
        File "<string>", line 161, in <module>
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-build-env-m3s458ec/overlay/lib/python3.12/site-packages/setuptools/__init__.py", line 103, in setup
          return distutils.core.setup(**attrs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-build-env-m3s458ec/overlay/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 185, in setup
          return run_commands(dist)
                 ^^^^^^^^^^^^^^^^^^
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-build-env-m3s458ec/overlay/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
          dist.run_commands()
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-build-env-m3s458ec/overlay/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
          self.run_command(cmd)
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-build-env-m3s458ec/overlay/lib/python3.12/site-packages/setuptools/dist.py", line 963, in run_command
          super().run_command(command)
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-build-env-m3s458ec/overlay/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-build-env-m3s458ec/overlay/lib/python3.12/site-packages/wheel/bdist_wheel.py", line 368, in run
          self.run_command("build")
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-build-env-m3s458ec/overlay/lib/python3.12/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
          self.distribution.run_command(command)
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-build-env-m3s458ec/overlay/lib/python3.12/site-packages/setuptools/dist.py", line 963, in run_command
          super().run_command(command)
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-build-env-m3s458ec/overlay/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-build-env-m3s458ec/overlay/lib/python3.12/site-packages/setuptools/_distutils/command/build.py", line 131, in run
          self.run_command(cmd_name)
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-build-env-m3s458ec/overlay/lib/python3.12/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
          self.distribution.run_command(command)
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-build-env-m3s458ec/overlay/lib/python3.12/site-packages/setuptools/dist.py", line 963, in run_command
          super().run_command(command)
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-build-env-m3s458ec/overlay/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-build-env-m3s458ec/overlay/lib/python3.12/site-packages/setuptools/_distutils/command/build_ext.py", line 345, in run
          self.build_extensions()
        File "<string>", line 77, in build_extensions
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-build-env-m3s458ec/overlay/lib/python3.12/site-packages/setuptools/_distutils/command/build_ext.py", line 467, in build_extensions
          self._build_extensions_serial()
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-build-env-m3s458ec/overlay/lib/python3.12/site-packages/setuptools/_distutils/command/build_ext.py", line 493, in _build_extensions_serial
          self.build_extension(ext)
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-build-env-m3s458ec/normal/lib/python3.12/site-packages/Cython/Distutils/build_ext.py", line 130, in build_extension
          new_ext = cythonize(
                    ^^^^^^^^^^
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-build-env-m3s458ec/normal/lib/python3.12/site-packages/Cython/Build/Dependencies.py", line 1154, in cythonize
          cythonize_one(*args)
        File "/private/var/folders/mh/x1j9_31x1yjfm8lv47m9dg_80000gr/T/pip-build-env-m3s458ec/normal/lib/python3.12/site-packages/Cython/Build/Dependencies.py", line 1321, in cythonize_one
          raise CompileError(None, pyx_file)
      Cython.Compiler.Errors.CompileError: bcolz/carray_ext.pyx
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for bcolz
Failed to build bcolz
ERROR: Could not build wheels for bcolz, which is required to install pyproject.toml-based projects
Note: you may need to restart the kernel to use updated packages.``

Hopefully though you are starting to understand the point about the multiple environments. (Your comment, “When I run !pip install fastai in jupyter notebook it succeeds without any complaint”, makes me wonder though. That you already knew from !pip list in your original post.) Your environment needs to be compatible and it seems the one Jupyter has isn’t. Sometimes using the lastest software like you appear to be trying gets you in this situation.

You could try pointing Jupyter at the environment where it works?
According to here and seeing a lot of things about that if you search the terms ‘bcolz fastai’ it can be tricky to get the correct combinations in the correct environment without using Anaconda, which is the suggested route by the fastai documentation. That doesn’t use the cutting edge software versions and instead uses versions it knows goes together, that is if you use the defaults without specifying overriding versions.

tl;dr - I made it work. Thanks for prompt response.

First I checked the python version being used by jupyter and it was 3.12. The python environment which I was using on command line was 3.11. I tried importing fastai in on command line while running python 3.12 and it failed. Then I used python 3.12 to update fastai on command line and it didnt allow me. It complained that this is a managed environment and I cant update it which was pretty strange so I left it.

Then I went ahead and rm -rf jupypter*, python3.11 and 3.12 folders! Thinking that I am rid of both pythons, I used python on command line, and lo and behold, its still running! Now it is running 3.9. Its path was /usr/bin/python3 unlike 3.11 and 3.12 which was in /Cellar/python@3.11/3.11.6_1/bin/. I wanted to rid this also but system didn’t allow me despite doing sudo rm -rf /usr/bin/python*. Then I took chance and did pip3 install jupyter. It installed.

Then on notebook I checked python version and it was 3.9!! No wonder now that fastai worked correctly. Now I have lot more questions :slight_smile:

  1. Why I am not able to delete python 3.9 from my system using sudo. Below is the output of ls -al python3

-rwxr-xr-x 76 root wheel 167136 Dec 1 23:00 python3

  1. Why I was not able to run pip install for python 3.12 environment ? Was it because Jupyter installed it?

  2. Why for python3.9 jupyter didn’t install its own python version.

  3. If Jupyter was not the one who installed python 3.12 then why I was not able to update fastai there

Thanks a lot for your help @fomightez

1 Like

Glad it is working.

As to your questions…

We aren’t going to be able to answer them based on what you’ve supplied.
Importantly, it isn’t going to help you much even if you got the answers. It boils down to mixing and matching versions and which one you are using, not keeping the environments straight, and that is a recipe for disaster. It seems you started cleaning things up and had better success.

Some related comments to help you with your questions…
I gathered from one of your recent replies that you were on a Mac because I saw homebrew. There’s a lot out there about Macs and installing Python and then Jupyter. I suggest you read some of the recent ones by reputable folks in the Python and Jupyter realms Some of this is discussed in links I reference here. I’d suggest the Anaconda Distribution because it keeps things isolated, but it does add more complexity to manage and so others disfavor suggesting that. And always specify your system in posts for forums such as this.

The system Python on a Mac isn’t meant for you to touch or use. It’s part of the stuff to keep your Mac working.

You may not have been able to run the pip install with 3.12 because the developers didn’t provide support for that version yet?

I agree with you that there is no point in digging the incompatibility of versions further. Yes I am using Mac and first time starting into ML and Python. Will look more into the documentation as I move along the fast ai course. Thanks once again.