Skip to content

TensorFlow Serving examples with Python 3 support #406

Closed
@benelot

Description

@benelot

Hello everyone!

I already realized that the examples are not compatible with python3, but I thought that maybe at least the installation passes normally. If I run the mnist example, I am getting the following error, which seems to be related to tensorflow serving using the wrong python environment. I specified python3 in the tensorflow ./configure script, but it seems that the example still uses python and thus does not find tensorflow. Any ideas on how to test if my TensorFlow Serving instance works properly? Do I have to port the client in order to test my environment?

 > bazel-bin/tensorflow_serving/example/mnist_client --num_tests=1000 --server=localhost:9000     

Traceback (most recent call last):
  File "/home/ai/TFS/bazel/serving/bazel-bin/tensorflow_serving/example/mnist_client.runfiles/tf_serving/tensorflow_serving/example/mnist_client.py", line 37, in <module>
    import tensorflow as tf
  File "/home/ai/TFS/bazel/serving/bazel-bin/tensorflow_serving/example/mnist_client.runfiles/org_tensorflow/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/home/ai/TFS/bazel/serving/bazel-bin/tensorflow_serving/example/mnist_client.runfiles/org_tensorflow/tensorflow/python/__init__.py", line 51, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/home/ai/TFS/bazel/serving/bazel-bin/tensorflow_serving/example/mnist_client.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/home/ai/TFS/bazel/serving/bazel-bin/tensorflow_serving/example/mnist_client.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/home/ai/TFS/bazel/serving/bazel-bin/tensorflow_serving/example/mnist_client.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/home/ai/TFS/bazel/serving/bazel-bin/tensorflow_serving/example/mnist_client.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
ImportError: /home/ai/TFS/bazel/serving/bazel-bin/tensorflow_serving/example/mnist_client.runfiles/org_tensorflow/tensorflow/python/_pywrap_tensorflow_internal.so: undefined symbol: PyUnicode_AsUTF8String

Activity

haoliplus

haoliplus commented on Apr 26, 2017

@haoliplus

I get the same error with python2. Any idea to fix it?

MichaelFeng87

MichaelFeng87 commented on May 16, 2017

@MichaelFeng87

the same issue to me on python3

MichaelFeng87

MichaelFeng87 commented on May 16, 2017

@MichaelFeng87

@benelot @DarryO @chrisolston find a potential bug in bazel-bin/tensorflow_serving/example/mnist_export line 29:
PYTHON_BINARY = '/usr/bin/python' which should be the python version by self-adaptive accordingly.
in my env, PYTHON_BINARY = '/usr/bin/python3' likely

CR1AT0RS

CR1AT0RS commented on Oct 15, 2017

@CR1AT0RS

I tried to port this to Python 3 but it does not work :/

Error:
Traceback (most recent call last):
File "/home/teppi/Downloads/serving/bazel-bin/tensorflow_serving/example/mnist_saved_model.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/teppi/Downloads/serving/bazel-bin/tensorflow_serving/example/mnist_saved_model.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/teppi/Downloads/serving/bazel-bin/tensorflow_serving/example/mnist_saved_model.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "/home/teppi/anaconda3/lib/python3.6/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "/home/teppi/anaconda3/lib/python3.6/imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: /home/teppi/Downloads/serving/bazel-bin/tensorflow_serving/example/mnist_saved_model.runfiles/org_tensorflow/tensorflow/python/_pywrap_tensorflow_internal.so: undefined symbol: PyClass_Type

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/teppi/Downloads/serving/bazel-bin/tensorflow_serving/example/mnist_saved_model.runfiles/tf_serving/tensorflow_serving/example/mnist_saved_model.py", line 33, in
import tensorflow as tf
File "/home/teppi/Downloads/serving/bazel-bin/tensorflow_serving/example/mnist_saved_model.runfiles/org_tensorflow/tensorflow/init.py", line 24, in
from tensorflow.python import *
File "/home/teppi/Downloads/serving/bazel-bin/tensorflow_serving/example/mnist_saved_model.runfiles/org_tensorflow/tensorflow/python/init.py", line 49, in
from tensorflow.python import pywrap_tensorflow
File "/home/teppi/Downloads/serving/bazel-bin/tensorflow_serving/example/mnist_saved_model.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow.py", line 72, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/home/teppi/Downloads/serving/bazel-bin/tensorflow_serving/example/mnist_saved_model.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/teppi/Downloads/serving/bazel-bin/tensorflow_serving/example/mnist_saved_model.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/teppi/Downloads/serving/bazel-bin/tensorflow_serving/example/mnist_saved_model.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "/home/teppi/anaconda3/lib/python3.6/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "/home/teppi/anaconda3/lib/python3.6/imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: /home/teppi/Downloads/serving/bazel-bin/tensorflow_serving/example/mnist_saved_model.runfiles/org_tensorflow/tensorflow/python/_pywrap_tensorflow_internal.so: undefined symbol: PyClass_Type

Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.

zli2014

zli2014 commented on Nov 14, 2017

@zli2014

i get same error with python3.6.
when i run bazel test -c opt tensorflow_serving/.. . ,

i find it is import error
via read log /home/master/.cache/bazel/_bazel_master/c1898b8dc84af7e4a9b56eba1fa88a07/execroot/tf_serving/bazel-out/local-opt/bin/tensorflow_serving/model_servers/tensorflow_model_server_test.runfiles/org_tensorflow/tensorflow/python/pywrap_tensorflow.py , then i cat this file and find : from tensorflow.python.pywrap_tensorflow_internal import * ,but when i input this commant in python3 it is no problem , but python2 raise exception

CLIsVeryOK

CLIsVeryOK commented on Jun 14, 2018

@CLIsVeryOK

I met the problem when I run "bazel build -c opt tensorflow_serving/...", how can I solve it???

CLIsVeryOK

CLIsVeryOK commented on Jun 22, 2018

@CLIsVeryOK

finally I find pyclass_type is a python2 variable so we need to change the default interpreter into python2.7, but my previous default interpreter is python3.6 after I installed anaconda. I used the following lines in prompt to reset my enviroment:
$ export PATH
$ declare -p PATH # verify PATH is exported, denoted by the -x
declare -x PATH="<my usual path, omitted...>"
$ /usr/bin/env python -V # shows my own python buildPython 2.7.6
$ export -n PATH # un-export PATH
$ declare -p PATH
declare -- PATH="<my usual path, omitted...>"
$ /usr/bin/env python -V # shows the system (/usr/bin/python) versionPython 2.6.6

then rebuild the server and client, pyClass_type problem do not exist.

changed the title [-]Installing TensorFlow Serving with Python 3 support[/-] [+]TensorFlow Serving examples with Python 3 support[/+] on Jun 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @benelot@CR1AT0RS@MichaelFeng87@haoliplus@zli2014

        Issue actions

          TensorFlow Serving examples with Python 3 support · Issue #406 · tensorflow/serving