Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Tensorflow Tfjs Tensorflowjs Pip Install

From Leeroopedia


Knowledge Sources
Domains Tooling, Deployment
Principle Principle:Tensorflow_Tfjs_Converter_Installation
Type External Tool Doc
Last Updated 2026-02-10 00:00 GMT

Environment:Tensorflow_Tfjs_Python_Converter

Overview

This implementation documents the concrete installation procedure for the tensorflowjs Python pip package, which provides the tensorflowjs_converter CLI tool and the tensorflowjs_wizard interactive tool. These tools are used to convert Python TensorFlow models into the TensorFlow.js format for browser and Node.js deployment.

Installation Command

Basic Installation

pip install tensorflowjs

Version-Pinned Installation

# Install a specific version matching your target TF.js runtime
pip install tensorflowjs==4.17.0

# Install the latest version
pip install --upgrade tensorflowjs

Virtual Environment Installation (Recommended)

# Create and activate a virtual environment
python -m venv tfjs_env
source tfjs_env/bin/activate  # Linux/macOS
# tfjs_env\Scripts\activate   # Windows

# Install tensorflowjs within the virtual environment
pip install tensorflowjs

Conda Environment Installation

# Create a conda environment
conda create -n tfjs python=3.10
conda activate tfjs

# Install via pip within the conda environment
pip install tensorflowjs

Inputs and Outputs

Inputs

  • A Python environment (Python 3.9 or later recommended) with pip available
  • Network access to the Python Package Index (PyPI) at pypi.org
  • Optionally, a specific version number for reproducible builds

Outputs

After successful installation, the following tools are available:

Tool Location Description
tensorflowjs_converter In PATH (e.g., ~/.local/bin/ or venv/bin/) CLI tool for batch model conversion
tensorflowjs_wizard In PATH Interactive CLI wizard that guides through conversion options
tensorflowjs Python module Site-packages Python API for programmatic conversion

Verification

After installation, verify the tools are correctly installed and accessible:

# Verify the converter CLI is available
tensorflowjs_converter --version

# Verify the wizard is available
tensorflowjs_wizard --help

# Verify the Python module is importable
python -c "import tensorflowjs; print(tensorflowjs.__version__)"

# List the full set of converter options
tensorflowjs_converter --help

Expected output from --help includes usage information showing all supported --input_format and --output_format values, quantization flags, and other conversion options.

Dependencies

The tensorflowjs package installs the following key dependencies (versions depend on the tensorflowjs version):

Dependency Purpose Notes
tensorflow Core TF runtime for reading model formats Major version must be compatible with tensorflowjs version
tensorflow-hub Support for TF Hub module conversion Required for --input_format=tf_hub
numpy Numerical operations on weight data Used for weight data manipulation during conversion
six Python 2/3 compatibility utilities Transitive dependency
h5py HDF5 file reading/writing Required for --input_format=keras (HDF5 models)
packaging Version parsing and comparison For version compatibility checks

Version Compatibility Matrix

tensorflowjs Version TensorFlow Version TF.js Runtime Version Python Version
4.17.x 2.15.x 4.17.x 3.9 - 3.11
4.10.x - 4.16.x 2.13.x - 2.15.x 4.10.x - 4.16.x 3.9 - 3.11
4.0.x - 4.9.x 2.11.x - 2.13.x 4.0.x - 4.9.x 3.8 - 3.11
3.x 2.8.x - 2.10.x 3.x 3.7 - 3.10

Note: Always check the PyPI page for the latest compatibility information, as these ranges evolve with each release.

The tensorflowjs_wizard

The tensorflowjs_wizard provides an interactive alternative to the CLI converter:

tensorflowjs_wizard

The wizard prompts for:

  1. Input model format — Select from the list of supported formats
  2. Input model path — Path to the source model
  3. Output format — Select the target TF.js format
  4. Output directory — Where to write the converted model
  5. Quantization — Whether and how to quantize weights
  6. Weight sharding — Shard size configuration

This is useful for one-off conversions or for users unfamiliar with the CLI flags.

Programmatic Usage

The tensorflowjs Python module can also be used programmatically for conversion within Python scripts or CI/CD pipelines:

import tensorflowjs as tfjs

# Convert a Keras model object directly (no file I/O for input)
import tensorflow as tf
model = tf.keras.applications.MobileNetV2(weights='imagenet')
tfjs.converters.save_keras_model(model, '/tmp/tfjs_mobilenet')

# Convert from SavedModel path
tfjs.converters.convert_tf_saved_model(
    '/tmp/my_saved_model',
    '/tmp/tfjs_output',
    signature_def='serving_default',
    saved_model_tags='serve'
)

Common Issues

Issue Cause Resolution
Command not found: tensorflowjs_converter pip installed to a path not in PATH Use pip show tensorflowjs to find the install location; add the scripts directory to PATH, or use python -m tensorflowjs.converters.converter_wrapper
TensorFlow version mismatch tensorflowjs requires a specific TF version Install a compatible TensorFlow version, or upgrade/downgrade tensorflowjs
Permission denied during install System-level pip without sudo Use pip install --user tensorflowjs or install in a virtual environment
ImportError: No module named tensorflowjs Python environment mismatch Ensure you are using the same Python environment where tensorflowjs was installed
GPU-related errors TensorFlow GPU build conflicts Use pip install tensorflow-cpu if GPU support is not needed for conversion

CI/CD Integration

For automated pipelines, pin the exact version and include verification:

# requirements-converter.txt
tensorflowjs==4.17.0

# CI step
pip install -r requirements-converter.txt
tensorflowjs_converter --version  # Verify installation
tensorflowjs_converter \
    --input_format=tf_saved_model \
    --output_format=tfjs_graph_model \
    /path/to/saved_model \
    /path/to/output

See Also

Environments

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment