This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

python: problem loading module in DLL


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/
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

The behavior is similar to the issue 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:

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[]) {
  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]))"
  return 0;

Mgr. Jan Brezina, Ph. D.
Technical University in Liberec, New technologies institute

Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]