Is py2exe not supported?

Asked by Kyle Bradshaw on 2015-11-03

I've been building a program that is centered around nfcpy. I attempted to compile it into an exe with py2exe, ran it, and was returned with the following error:

Traceback (most recent call last):
  File "NFCTest.py", line 8, in <module>
  File "nfc\clf\__init__.pyc", line 73, in __init__
IOError: [Errno 19] No such device

I verified that the interface (Sony RC-S380) is plugged in correctly. I verified that the code works when executed in .py form.
The problem only occurs in py2exe form.

I also attempted to build the simplest possible nfcpy program to exe, to ensure it's not a problem with my main program. Still no dice.

One problem I noticed with the py2exe build process is this message at the end:

The following modules appear to be missing
['clf.ContactlessFrontend', 'serial.tools.list_ports']

That could be related, but I'm unsure.
This isn't a mission critical problem for me, at current, but an interesting problem to me, nonetheless.

Question information

Language:
English Edit question
Status:
Solved
For:
nfcpy Edit question
Assignee:
No assignee Edit question
Solved by:
Kyle Bradshaw
Solved:
2015-11-11
Last query:
2015-11-11
Last reply:

Interesting. I've never attempted to use py2exe but it sounds like a nice idea.

I suggest that you try to enable debug logs (or temporarily convert some logs to simple print statements in nfc.clf.device.py) to get some more runtime information. To enable debug logs:

import logging
logging.basicConfig()
logging.getLogger("nfc.clf").setLevel(logging.DEBUG)

Kyle Bradshaw (kyle-8) said : #2

Aha, found the first stage of the problem.

INFO:nfc.clf:searching for reader on path usb
ERROR:nfc.clf.transport:python usb library not found
ERROR:nfc.clf.transport:python serial library not found
ERROR:nfc.clf:no reader available on path usb
Traceback (most recent call last):
  File "NFCTest.py", line 12, in <module>
  File "nfc\clf\__init__.pyc", line 73, in __init__
IOError: [Errno 19] No such device

I'll keep testing, and check to see if there's anything about the pyusb library and py2exe in conjunction.

Kyle Bradshaw (kyle-8) said : #3

Okay, I think I can circumvent the problem for my purposes, but the problem seems to lie in a conflict between the way py2exe handles included modules. It seems to not be including any modules that are being called by importlib.import_module. (Line 164 and 165 of Transport.py, for example.) Manually importing them in my NFCTest.py resulted in

INFO:nfc.clf:searching for reader on path usb
DEBUG:nfc.clf.transport:using pyusb version 1.x
DEBUG:nfc.clf.transport:path matches '^(usb|)$'
DEBUG:nfc.clf.device:loading rcs380 driver for usb:054c:06c3
Traceback (most recent call last):
  File "NFCTest.py", line 15, in <module>
  File "nfc\clf\__init__.pyc", line 72, in __init__
  File "nfc\clf\__init__.pyc", line 146, in open
  File "nfc\clf\device.pyc", line 82, in connect
  File "importlib\__init__.pyc", line 37, in import_module
ImportError: No module named rcs380

Which means that the code made it a step further. I'll go through and manually import any modules that would be requested by import_module.

Essentially though, this is not a problem with nfcpy itself.

Once again, Stephen, thanks for the assist.

That should be it. Dynamic module imports are for transports (serial, usb) and device drivers (rcs380, ...). Note that there are two fundamentally different versions of PyUSB, old 0.x and new 1.x. PyUSB 0.x is imported as "usb". PyUSB 1.x is imported as "usb.core" and "usb.util". You have PyUSB 1.x.