Python – How to combine Python 32-bit and 64-bit modules

How to combine Python 32-bit and 64-bit modules… here is a solution to the problem.

How to combine Python 32-bit and 64-bit modules

For one of my robotics projects, I tried to take images from Nao Robot’s camera and use Tensorflow for object recognition.

The problem is that the bot’s NaoQi API is built on Python 2.7 32-bit.
(http://doc.aldebaran.com/1-14/dev/python/install_guide.html )

The Tensorflow Object Recognition API is only available for 64-bit. ( https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md and https://www.tensorflow.org/install/install_windows)

I’m using Windows 10, I have Python 2.7 32-bit and 3.6 64-bit installed at the same time, I am able to run modules independently, but I can’t pass images between the two.

Is there a workaround to resolve this issue? Thank you.

Solution

If you say that one is only 32-bit and the other is only 64-bit, I don’t think there is a way to get both modules to work in the same interpreter.

Therefore, consider running two interpreters to communicate with each other through message exchange, remote procedure calls, and so on.

I’m strongly against using shared memory sections, UNIX, or TCP sockets because there are so many low-level details to work on, which distracts you from the real goal of your work.

Instead, consider some high-level libraries such as zeromq also python bindings and it’s very simple to use: you can send binary data, strings, or Python objects online, which will be automatically serialized and deserialized using pickle.

Useful reading:

Sample client:

import zmq

context = zmq. Context()
socket = context.socket(zmq. REQ)
socket.connect("tcp://localhost:5555")

print("Sending request...")
socket.send_string("Hello")
#  Get the reply.
message = socket.recv_string()
print(f"Received reply: {message}")

Sample server:

import zmq

context = zmq. Context()
socket = context.socket(zmq. REP)
socket.bind("tcp://*:5555")

while True:
    message = socket.recv_string()
    print(f"Received request: {message}")
    socket.send_string("Hello")

Similar to socket.send_string(), you have socket.send_json() and socket.send_pyobj().

Check the documentation

Related Problems and Solutions