tflite-support installation issue in Kaggle
Hi @dsbyprateekg ,

It seems the issue is related to Kaggle environment. I found there is no issue with Google colab and may refer to the [gist](https://colab.research.google.com/gist/SuryanarayanaY/153ff07cb2eb8c066c3987e526a5a72d/60784.ipynb).

By looking at the logs you might need to install setup tools separately in Kaggle.

Please try `pip install setuptools` first and then try to install `tflite-support` and let us know if still having issue after this.

Thanks! @SuryanarayanaY I tried that but got same error. @dsbyprateekg ,

Could you please cross check the environment details using `pip list` and compare it with the Colab environment attached in gist above and let us know any differences. Also please confirm the setuptools version installed there.

I am not sure,but maybe can you try uninstalling `setuptools_scm` and then install `setuptools` and let us know if it works.

Thanks! Hi @dsbyprateekg 

To resolve this problem, you can try the following steps:

1. Ensure that you have all the necessary dependencies and prerequisites installed on your system. Refer to the official documentation of tflite-support for any specific requirements.

2. Update your pip package manager to the latest version by running the command:

>> pip install --upgrade pip

3. Check if you have the required development libraries and tools installed on your system. Some Python packages require certain system-level dependencies to build correctly. For example, on Ubuntu, you might need to install the build-essential package:

>> sudo apt-get install build-essential

4. Try installing the package again using the --no-binary flag to force a source build instead of using pre-compiled wheels:

>> pip install --no-binary :all: tflite-support

5. If the above steps don't resolve the issue, you can try cloning the tflite-support repository from GitHub and installing it directly from source:

>> git clone https://github.com/tensorflow/tflite-support.git
>> cd tflite-support
>> pip install . @yasirulhadi I will follow mentioned steps and update you soon. @yasirulhadi after following your suggested steps, installation was done successfully. See below logs-
![image](https://github.com/tensorflow/tensorflow/assets/30830541/92815309-9647-4019-8224-bcde712bdf01)

but now I am getting following error-
`ModuleNotFoundError: No module named 'tflite_support.metadata_writers'`

in this import `from tflite_support.metadata_writers import object_detector` Hi @dsbyprateekg 

The error message ModuleNotFoundError: No module named 'tflite_support.metadata_writers' suggests that the tflite_support.metadata_writers module is not found. This could indicate a problem with the installation or the package itself.

1. Double-check that the tflite-support package was installed correctly. You can verify this by running the following command and checking if tflite-support is listed:
>> pip list

2. Make sure you are using the correct import statement in your code. The tflite_support.metadata_writers module was introduced in a later version of the tflite-support package. If you are using an older version, it's possible that this module is not available. You can check the version of tflite-support installed by running:

>> pip show tflite-support

If you have an older version installed, you can upgrade to the latest version using:

>> pip install --upgrade tflite-support

3. Finally, ensure that you have imported the necessary submodules correctly. For example, if you're trying to import the object_detector module, make sure you have the following import statements:

>> from tflite_support.metadata_writers import object_detector
>> from tflite_support.metadata import metadata_schema_py_generated as _metadata_fb

4. If the issue persists, you might need to check the documentation or the source code of tflite-support.
 @yasirulhadi If you read older comments then you will come to know that !pip install tflite-support command is not working that's why I posted this issue.

If I use upgrade command with it then again I am facing following error which I posted as first post-  `ERROR: Could not build wheels for tflite-support, which is required to install pyproject.toml-based projects`

Also as per your suggested command to install tflit-support- `!pip install --no-binary :all: tflite-support`, I am able to see installed version as `tflite-support-0.1.0a1`-
![image](https://github.com/tensorflow/tensorflow/assets/30830541/16c61eb3-2d45-438c-a71c-26bbef7bca30)

I suggest you to please try yourself in kaggle environment and share me a working gist. @dsbyprateekg Let me try and work on it again. 
 @dsbyprateekg 

What's the current python version in your kaggle environment?

If it is 3.10.10 then change it to 3.7. In some environments Tensorflow library doesn't run off with python version higher than 3.7.

Once it is changed to 3.7, try to run the above commands I share and let me know.
Hopefully it would work!   @yasirulhadi we cannot change Python version in kaggle environment. @dsbyprateekg 
https://www.kaggle.com/code/taylorsamarel/change-python-version-on-kaggle-taylor-amarel?scriptVersionId=115764070 @yasirulhadi instead of changing Python version to older one, can this not be fixed by TF team to support Python 3.10 version? @dsbyprateekg 
It is not the issue with tensorflow but with Kaggle environment's python version. Some libraries don't support the upgrade and works well with the downgraded version. @dsbyprateekg ,

Can you report the issue to kaggle team. Its problem with Kaggle environment and we can't support issues with third party tools. Maybe you can refer the pip list as mentioned for checking the Colab environment packages with versions and try to install missing packages in kaggle environment.

 You can use Google Colab for free in case you want to train/test your model.

Thanks! @SuryanarayanaY Actually first I tried my TFLite model train/test/convert in Colab only but due to Python 3.10, there I faced issue while installing TFLite model maker library. So I have switched to Kaggle. Now in Kaggle I am able to train model but now issue is with TFLite-support library. @dsbyprateekg Were you able to change the python version? @yasirulhadi No, I have not.
So I did it on my personal laptop. Hi @dsbyprateekg 

The tflite-support has has known issue of not running on python 3.10 because of which the model maker installation is hindered in the colab as well.

You can try installing `pip install tflite-support==0.4.2` and see if it works.

Thanks. This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60784">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60784">No</a>

<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Build/Install

### Have you reproduced the bug with TF nightly?

Yes

### Source

source

### Tensorflow Version

2.12

### Custom Code

No

### OS Platform and Distribution

kaggle

### Mobile device

_No response_

### Python version

3.10.10

### Bazel version

_No response_

### GCC/Compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current Behaviour?

`!pip install tflite-support` gives following error-
`note: This error originates from a subprocess, and is likely not a problem with pip.`
`error: subprocess-exited-with-error`
`ERROR: Could not build wheels for tflite-support, which is required to install pyproject.toml-based projects`


### Standalone code to reproduce the issue

```shell
complete logs are attached already
```


### Relevant log output

```shell
Collecting tflite-support
  Downloading tflite-support-0.1.0a1.tar.gz (390 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 390.3/390.3 kB 7.2 MB/s eta 0:00:00
  Preparing metadata (setup.py) ... - \ done
Requirement already satisfied: pybind11>=2.4 in /opt/conda/lib/python3.10/site-packages (from tflite-support) (2.10.4)
Requirement already satisfied: absl-py>=0.7.0 in /opt/conda/lib/python3.10/site-packages (from tflite-support) (1.4.0)
Requirement already satisfied: numpy in /opt/conda/lib/python3.10/site-packages (from tflite-support) (1.23.5)
Building wheels for collected packages: tflite-support
  Building wheel for tflite-support (setup.py) ... - \ | / - error
  error: subprocess-exited-with-error
  
  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [140 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-3.10
      creating build/lib.linux-x86_64-3.10/tflite_support
      copying tflite_support/metadata_schema_py_generated.py -> build/lib.linux-x86_64-3.10/tflite_support
      copying tflite_support/__init__.py -> build/lib.linux-x86_64-3.10/tflite_support
      copying tflite_support/schema_py_generated.py -> build/lib.linux-x86_64-3.10/tflite_support
      copying tflite_support/metadata.py -> build/lib.linux-x86_64-3.10/tflite_support
      copying tflite_support/codegen.py -> build/lib.linux-x86_64-3.10/tflite_support
      running egg_info
      writing tflite_support.egg-info/PKG-INFO
      writing dependency_links to tflite_support.egg-info/dependency_links.txt
      writing entry points to tflite_support.egg-info/entry_points.txt
      writing requirements to tflite_support.egg-info/requires.txt
      writing top-level names to tflite_support.egg-info/top_level.txt
      /opt/conda/lib/python3.10/site-packages/setuptools_scm/integration.py:28: RuntimeWarning:
      ERROR: setuptools==41.6.0 is used in combination with setuptools_scm>=6.x
      
      Your build configuration is incomplete and previously worked by accident!
      setuptools_scm requires setuptools>=45
      
      
      This happens as setuptools is unable to replace itself when a activated build dependency
      requires a more recent setuptools version
      (it does not respect "setuptools>X" in setup_requires).
      
      
      setuptools>=31 is required for setup.cfg metadata support
      setuptools>=42 is required for pyproject.toml configuration support
      
      Suggested workarounds if applicable:
       - preinstalling build dependencies like setuptools_scm before running setup.py
       - installing setuptools_scm using the system package manager to ensure consistency
       - migrating from the deprecated setup_requires mechanism to pep517/518
         and using a pyproject.toml to declare build dependencies
         which are reliably pre-installed before running the build tools
      
        warnings.warn(
      reading manifest file 'tflite_support.egg-info/SOURCES.txt'
      reading manifest template 'MANIFEST.in'
      writing manifest file 'tflite_support.egg-info/SOURCES.txt'
      copying tflite_support/metadata_schema.fbs -> build/lib.linux-x86_64-3.10/tflite_support
      creating build/lib.linux-x86_64-3.10/tflite_support/flatbuffers
      copying tflite_support/flatbuffers/__init__.py -> build/lib.linux-x86_64-3.10/tflite_support/flatbuffers
      copying tflite_support/flatbuffers/builder.py -> build/lib.linux-x86_64-3.10/tflite_support/flatbuffers
      copying tflite_support/flatbuffers/compat.py -> build/lib.linux-x86_64-3.10/tflite_support/flatbuffers
      copying tflite_support/flatbuffers/encode.py -> build/lib.linux-x86_64-3.10/tflite_support/flatbuffers
      copying tflite_support/flatbuffers/number_types.py -> build/lib.linux-x86_64-3.10/tflite_support/flatbuffers
      copying tflite_support/flatbuffers/packer.py -> build/lib.linux-x86_64-3.10/tflite_support/flatbuffers
      copying tflite_support/flatbuffers/table.py -> build/lib.linux-x86_64-3.10/tflite_support/flatbuffers
      copying tflite_support/flatbuffers/util.py -> build/lib.linux-x86_64-3.10/tflite_support/flatbuffers
      running build_ext
      creating tmp
      gcc -pthread -B /opt/conda/compiler_compat -Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /opt/conda/include -fPIC -O2 -isystem /opt/conda/include -fPIC -I/opt/conda/include/python3.10 -c /tmp/tmpf6wu46to.cc -o tmp/tmpf6wu46to.o -std=c++14
      gcc -pthread -B /opt/conda/compiler_compat -Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /opt/conda/include -fPIC -O2 -isystem /opt/conda/include -fPIC -I/opt/conda/include/python3.10 -c /tmp/tmpchd3i2qh.cc -o tmp/tmpchd3i2qh.o -fvisibility=hidden
      building '_pywrap_codegen' extension
      creating build/temp.linux-x86_64-3.10
      creating build/temp.linux-x86_64-3.10/src
      creating build/temp.linux-x86_64-3.10/src/tensorflow
      creating build/temp.linux-x86_64-3.10/src/tensorflow/lite
      creating build/temp.linux-x86_64-3.10/src/tensorflow/lite/experimental
      creating build/temp.linux-x86_64-3.10/src/tensorflow/lite/experimental/support
      creating build/temp.linux-x86_64-3.10/src/tensorflow/lite/experimental/support/codegen
      gcc -pthread -B /opt/conda/compiler_compat -Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /opt/conda/include -fPIC -O2 -isystem /opt/conda/include -fPIC -I/opt/conda/lib/python3.10/site-packages/pybind11/include -I/opt/conda/lib/python3.10/site-packages/pybind11/include -Iinclude -Isrc -I/opt/conda/include/python3.10 -c src/tensorflow/lite/experimental/support/codegen/android_java_generator.cc -o build/temp.linux-x86_64-3.10/src/tensorflow/lite/experimental/support/codegen/android_java_generator.o -DVERSION_INFO="0.1.0a1" -std=c++14 -fvisibility=hidden
      In file included from include/flatbuffers/base.h:217,
                       from include/flatbuffers/flatbuffers.h:20,
                       from src/tensorflow/lite/experimental/support/metadata/metadata_schema_generated.h:21,
                       from src/tensorflow/lite/experimental/support/codegen/code_generator.h:25,
                       from src/tensorflow/lite/experimental/support/codegen/android_java_generator.h:23,
                       from src/tensorflow/lite/experimental/support/codegen/android_java_generator.cc:16:
      /opt/conda/include/absl/strings/string_view.h:52:26: error: ‘string_view’ in namespace ‘std’ does not name a type
         52 | using string_view = std::string_view;
            |                          ^~~~~~~~~~~
      /opt/conda/include/absl/strings/string_view.h:52:21: note: ‘std::string_view’ is only available from C++17 onwards
         52 | using string_view = std::string_view;
            |                     ^~~
      /opt/conda/include/absl/strings/string_view.h:686:8: error: ‘string_view’ does not name a type
        686 | inline string_view ClippedSubstr(string_view s, size_t pos,
            |        ^~~~~~~~~~~
      /opt/conda/include/absl/strings/string_view.h:697:11: error: ‘string_view’ does not name a type
        697 | constexpr string_view NullSafeStringView(const char* p) {
            |           ^~~~~~~~~~~
      In file included from include/flatbuffers/flatbuffers.h:20,
                       from src/tensorflow/lite/experimental/support/metadata/metadata_schema_generated.h:21,
                       from src/tensorflow/lite/experimental/support/codegen/code_generator.h:25,
                       from src/tensorflow/lite/experimental/support/codegen/android_java_generator.h:23,
                       from src/tensorflow/lite/experimental/support/codegen/android_java_generator.cc:16:
      include/flatbuffers/base.h:219:23: error: ‘string_view’ in namespace ‘absl’ does not name a type
        219 |         typedef absl::string_view string_view;
            |                       ^~~~~~~~~~~
      In file included from src/tensorflow/lite/experimental/support/metadata/metadata_schema_generated.h:21,
                       from src/tensorflow/lite/experimental/support/codegen/code_generator.h:25,
                       from src/tensorflow/lite/experimental/support/codegen/android_java_generator.h:23,
                       from src/tensorflow/lite/experimental/support/codegen/android_java_generator.cc:16:
      include/flatbuffers/flatbuffers.h:552:16: error: ‘string_view’ in namespace ‘flatbuffers’ does not name a type
        552 |   flatbuffers::string_view string_view() const {
            |                ^~~~~~~~~~~
      include/flatbuffers/flatbuffers.h:1478:44: error: ‘flatbuffers::string_view’ has not been declared
       1478 |   Offset<String> CreateString(flatbuffers::string_view str) {
            |                                            ^~~~~~~~~~~
      include/flatbuffers/flatbuffers.h: In member function ‘flatbuffers::Offset<flatbuffers::String> flatbuffers::FlatBufferBuilder::CreateString(int)’:
      include/flatbuffers/flatbuffers.h:1479:29: error: request for member ‘data’ in ‘str’, which is of non-class type ‘int’
       1479 |     return CreateString(str.data(), str.size());
            |                             ^~~~
      include/flatbuffers/flatbuffers.h:1479:41: error: request for member ‘size’ in ‘str’, which is of non-class type ‘int’
       1479 |     return CreateString(str.data(), str.size());
            |                                         ^~~~
      src/tensorflow/lite/experimental/support/codegen/android_java_generator.cc: In function ‘tflite::support::codegen::details_android_java::ModelInfo tflite::support::codegen::{anonymous}::CreateModelInfo(const tflite::ModelMetadata*, const string&, const string&, const string&, tflite::support::codegen::ErrorReporter*)’:
      src/tensorflow/lite/experimental/support/codegen/android_java_generator.cc:157:21: warning: comparison of integer expressions of different signedness: ‘int’ and ‘flatbuffers::uoffset_t’ {aka ‘unsigned int’} [-Wsign-compare]
        157 |   for (int i = 0; i < graph->input_tensor_metadata()->size(); i++) {
            |                   ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      src/tensorflow/lite/experimental/support/codegen/android_java_generator.cc:162:21: warning: comparison of integer expressions of different signedness: ‘int’ and ‘flatbuffers::uoffset_t’ {aka ‘unsigned int’} [-Wsign-compare]
        162 |   for (int i = 0; i < graph->output_tensor_metadata()->size(); i++) {
            |                   ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      src/tensorflow/lite/experimental/support/codegen/android_java_generator.cc: In function ‘bool tflite::support::codegen::{anonymous}::GenerateWrapperImports(tflite::support::codegen::CodeWriter*, const tflite::support::codegen::details_android_java::ModelInfo&, tflite::support::codegen::ErrorReporter*)’:
      src/tensorflow/lite/experimental/support/codegen/android_java_generator.cc:278:19: warning: loop variable ‘target’ creates a copy from type ‘const std::__cxx11::basic_string<char>’ [-Wrange-loop-construct]
        278 |   for (const auto target : imports) {
            |                   ^~~~~~
      src/tensorflow/lite/experimental/support/codegen/android_java_generator.cc:278:19: note: use reference type to prevent copying
        278 |   for (const auto target : imports) {
            |                   ^~~~~~
            |                   &
      src/tensorflow/lite/experimental/support/codegen/android_java_generator.cc: In function ‘bool tflite::support::codegen::{anonymous}::GenerateWrapperOutputs(tflite::support::codegen::CodeWriter*, const tflite::support::codegen::details_android_java::ModelInfo&, tflite::support::codegen::ErrorReporter*)’:
      src/tensorflow/lite/experimental/support/codegen/android_java_generator.cc:471:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<tflite::support::codegen::details_android_java::TensorInfo>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
        471 |     for (int i = 0; i < model.outputs.size(); i++) {
            |                     ~~^~~~~~~~~~~~~~~~~~~~~~
      src/tensorflow/lite/experimental/support/codegen/android_java_generator.cc: In function ‘bool tflite::support::codegen::{anonymous}::GenerateWrapperMetadata(tflite::support::codegen::CodeWriter*, const tflite::support::codegen::details_android_java::ModelInfo&, tflite::support::codegen::ErrorReporter*)’:
      src/tensorflow/lite/experimental/support/codegen/android_java_generator.cc:517:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<tflite::support::codegen::details_android_java::TensorInfo>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
        517 |     for (int i = 0; i < model.inputs.size(); i++) {
            |                     ~~^~~~~~~~~~~~~~~~~~~~~
      src/tensorflow/lite/experimental/support/codegen/android_java_generator.cc:536:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<tflite::support::codegen::details_android_java::TensorInfo>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
        536 |     for (int i = 0; i < model.outputs.size(); i++) {
            |                     ~~^~~~~~~~~~~~~~~~~~~~~~
      src/tensorflow/lite/experimental/support/codegen/android_java_generator.cc: In function ‘tflite::support::codegen::GenerationResult::File tflite::support::codegen::{anonymous}::GenerateDoc(const string&, const tflite::support::codegen::details_android_java::ModelInfo&, tflite::support::codegen::ErrorReporter*)’:
      src/tensorflow/lite/experimental/support/codegen/android_java_generator.cc:927:21: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
        927 |   for (int i = 0; i < lower.length(); i++) {
            |                   ~~^~~~~~~~~~~~~~~~
      error: command '/usr/bin/gcc' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for tflite-support
  Running setup.py clean for tflite-support
Failed to build tflite-support
ERROR: Could not build wheels for tflite-support, which is required to install pyproject.toml-based projects
```
</details>