PyImport_ImportModule bug in ver 3.1.2?

健安 王 febwave at
Wed Jul 27 21:24:38 EDT 2011

	My Python version is 3.1.2.
	I am programming embedding c with python in windows.
	When I imported urllib.request  in my test py file,
PyImport_ImportModule always return NULL.
	But I imported re or cmd ,they work fine.
	I found urllib is folder, and request seems to be submodule.
	I don't know how to import it. I confirmed and application
are in same folder.
	Could you give me some advice?
	Thank you.

import sys
import urllib.request

CRLF = '\r\n'

def addValue(oper1,oper2):
      return (oper1 + oper2);

def ConnectURL(url):
            req = urllib.request.urlopen(url)
            response =
            return (req.getcode(),req.geturl())

      except BaseException as exp:

native code:

int APIENTRY _tWinMain(HINSTANCE hInstance,
					   HINSTANCE hPrevInstance,
					   LPTSTR    lpCmdLine,
					   int       nCmdShow)
	PyObject* pPyUtil	= NULL;
	PyObject* pPypfn	= NULL;
	PyObject* pPyArgs	= NULL;
	PyObject* pPyRet	= NULL;
	int		nRet		= 0;
	int		nValue		= 0;

	PyImport_ImportModule("sys");		// ok
PyImport_ImportModule("csv");		// ok

	PyImport_ImportModule("urllib");		// ok

	pPyUtil	= PyImport_ImportModule("myutil"); // failed ,
	if(pPyUtil != NULL)


	return 0;

More information about the Python-list mailing list