Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to combine Python 32bit and 64bit modules

For one my Robotics projects, I am trying to grab an image from Nao Robot's camera and use Tensorflow for object recognition.

The problem is that the Robot's NaoQi API is built on Python2.7 32bit. (http://doc.aldebaran.com/1-14/dev/python/install_guide.html)

The Tensorflow Object recognition API works only with 64bit. (https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md and https://www.tensorflow.org/install/install_windows)

I am using Windows 10 and I have both Python 2.7 32 bit and 3.6 64bit installed and I am able to run the modules independently but I am unable to pass the image between the two.

Are there any workarounds to address this issue? Thank you.

like image 933
SingularRiver Avatar asked Mar 09 '26 15:03

SingularRiver


1 Answers

I don't think there is a way to have both modules work in the same interpreter if you say one is 32bit only and the other 64bit only.

So, consider running two interpreters, and having them communicate with each other with message exchange, remote procedure call, and such.

I strongly discourage to use shared memory sections, UNIX or TCP sockets, as there are too many low level details to handle that would distract you from the real objective of your work.

Instead, consider some high level library such as zeromq which has also python bindings and it's very simple to use: you can send binary data, strings or python objects along the wire, which would be automatically serialized and deserialized using pickle.

Useful readings:

  • Learning ØMQ with pyzmq
  • Client / Server (Request-reply pattern)
  • Serializing messages with PyZMQ

Example 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}")

Example 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")

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

Check the documentation.

like image 129
fferri Avatar answered Mar 11 '26 08:03

fferri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!