February 22, 2024

Got tensorflow symbol already exposed error? This is how you fix old TensorFlow examples

Got tensorflow symbol already exposed error? This is how you fix old TensorFlow examples

Suffering suddenly from tensorflow.python.util.tf_export.symbolalreadyexposederror: symbol zeros is already exposed as () on your package install? Maybe pinning your package dependency list back in time can help.

One huge benefit of StableBuild's PyPi mirror is that it can help you resurrect old Python examples easily; without having to manually piece back together a correct dependency list. For example, you want to get OlafenwaMoses/ImageAI revision e76f87212a (published Oct. 15, 2020) working to classify an image. The install instructions no longer work:


# clone the repository
git clone https://github.com/OlafenwaMoses/ImageAI

cd ImageAI

git checkout e76f87212a6e53b6271f7a225e20ca3df9b1d18e
# download weights and example image

cp data-images/holo2.jpg ./examples/
wget -O examples/hololens-ex-60--loss-2.76.h5 https://github.com/OlafenwaMoses/ImageAI/releases/download/essential-v4/hololens-ex-60--loss-2.76.h5
# create a new virtual environment and install dependencies

python3.8 -m venv .venv
source .venv/bin/activate

pip3 install -r requirements.txt

python3 setup.py install
# try and classify an image (fails!)

cd examples/
python3 custom_detection.py

# Traceback (most recent call last):

# ...

# tensorflow.python.util.tf_export.SymbolAlreadyExposedError: Symbol Zeros is already exposed as ().

Most likely this example worked when it was published on Oct. 15, 2020 - so use that date as the pin date, and install the dependencies using StableBuild instead. If we try again you will see that it works now. Even though the original dependency has vanished.


cd ImageAI

# create a new virtual environmentpython3.8 -m venv .venv-sbsource .venv-sb/bin/activate
# install dependencies, but pin on 2020-10-15

pip3 install \
-i https://YOUR-API-KEY.pypimirror.stablebuild.com/2020-10-15 \
-r requirements.txtpython3 setup.py install # try and classify an image (succeeds!)

cd examples/python3 custom_detection.py

# hololens: 87.66432404518127: [23, 45, 90, 79]
# hololens: 89.25175070762634: [191, 64, 243, 93]
# hololens: 64.49641585350037: [437, 76, 514, 127]
# hololens: 91.78624749183655: [380, 109, 423, 134]

For more information on to use  our historic PyPi mirror visit our our docs page.


Sign up for StableBuild today!

Want more stable and reproducible builds? Sign up for Stablebuild for FREE now.