python: problem loading module in DLL

Jan Brezina jbrezmorf@gmail.com
Fri Mar 4 23:16:00 GMT 2016


Hi,

we are developing a multiplatform application using C++ with the
embedded Python. The problem is that the import of the module 'binascii'
(located in python2.7/lib-dynload/binascii.dll)
fails when the C++ application (which eventually call the embedded
python script) is called from the Windows cmd. Resulting error message is:

'ImportError: No such file or directory\n'

However, the import works when the C++ application is called from the
cygwin shell. Import of other module, in particular 'time' (located in
python2.7/lib-dynload/time.dll), works in both cases. In fact it seems
that the python found the binascii.dll, but was unable to load it
somehow. If we create an auxiliary python2.7/lib-dynload/binascii.py
we get the same error, so we guess that the importer found binascii.dll
first but fail to load it and doesn't continue to find also binascii.py.

The behavior is similar to the issue
https://www.cygwin.com/ml/cygwin/2013-04/msg00408.html. We tried to
reinstall zlib and related packages without success.

>From our point of view it is a bug, but possibly such usage of the
embedded Python is unsupported and we were just lucky until now using
the modules that works only by chance.
Anyway if it is not a bug, can anybody provide some hint what is the
mechanism of loading DLL python modules and how to investigate the real
problem (hidden by the generic error message).

The code to reproduce the problem is on github:
https://github.com/x3mSpeedy/cygwin-python-issue

and also pasted at the end.

thank you for any help.

Jan Brezina and Jan Hybs


Cygwin version:
$ uname -a
CYGWIN_NT-6.1 Flow123d 2.4.1(0.293/5/3) 2016-01-24 11:26 x86_64 Cygwin

Windows version is:
Windows 7

Bug occures in both python2.7 and python3.4 version:
$ python2.7 --version
Python 2.7.10

$ python3.4 --version
Python 3.4.3

C++ code to reproduce the error:
-----------------------------------------------------------------------
#include <Python.h>
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[]) {
  Py_Initialize();
  cout << "Python path: " << (Py_GetPath()) << endl;
  cout << "Python prefix: " << (Py_GetPrefix()) << endl;
  cout << "Python exec prefix: " << (Py_GetExecPrefix()) << endl;
  cout << "------------------" << endl;
  cout << "Python version" << endl;
  PyRun_SimpleString("\nimport sys; print (sys.version_info)");
  cout << "------------------" << endl;
  cout << "Test: time module" << endl;
  PyRun_SimpleString("\nimport time as mod; print (mod, mod.__file__)"
                     "\nfor x in dir(mod):\n"
                     "\n  print ('{:20s}{}'.format(x, str(getattr(mod,
x, ''))[0:35]))"
                     );
  cout << "------------------" << endl;
  cout << "Test: binascii module" << endl;
  PyRun_SimpleString("\nimport binascii as mod; print (mod, mod.__file__)"
                     "\nfor x in dir(mod):\n"
                     "\n  print ('{:20s}{}'.format(x, str(getattr(mod,
x, ''))[0:35]))"
                     );
  Py_Finalize();
  return 0;
}
------------------------------------------------------------



-- 
------------------------
Mgr. Jan Brezina, Ph. D.
Technical University in Liberec, New technologies institute
http://www.nti.tul.cz/cz/WikiUser:Jan.Brezina

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list