<HTML>
<HEAD>
<TITLE>Re: [Python.NET] Unable to import library imaplib</TITLE>
</HEAD>
<BODY>
<FONT FACE="Verdana, Helvetica, Arial"><SPAN STYLE='font-size:12.0px'>Note that the latest PythonNet is built for and includes 2.4, not 2.5, unless you’ve built <BR>
your own version.<BR>
<BR>
That probably means that pythonnet is looking at the PYTHONPATH for 2.4, which <BR>
probably doesn’t have imaplib installed.<BR>
<BR>
I’d suggest making sure to install imaplib in the site-packages used by your <BR>
PythonNet/2.4 installation...<BR>
<BR>
-Brian<BR>
<BR>
<BR>
On 4/11/07 5:16 AM, "Kris Beyers" <kris_beyers@hotmail.com> wrote:<BR>
<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Verdana, Helvetica, Arial"><SPAN STYLE='font-size:12.0px'>Hi<BR>
<BR>
I can import CLR, but not imaplib. Although imaplib is part of the standard python library, and I suppose I didn't need CLR.<BR>
I also tried different combinations of case of the word "imaplib", since the import statement is case sensitive.<BR>
Currently I have the latest Python version 25, and installed the latest PythonNet afterwards (PythonNet 1.0 release candidate 2).<BR>
Also tried to include the path to the C:\Python25\Lib in the systemvariable PATH, where imaplib.py resides.<BR>
<BR>
Furthermore I included C:\Program Files\PythonNet in the same systemvariable, but that's nog part of the problem I guess.<BR>
<BR>
Regards,<BR>
Kris<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Verdana, Helvetica, Arial"><SPAN STYLE='font-size:12.0px'><HR ALIGN=CENTER SIZE="3" WIDTH="100%">Date: Tue, 10 Apr 2007 19:39:43 -0700<BR>
From: dvpdiner2@yahoo.com<BR>
Subject: Re: [Python.NET] Unable to import library imaplib<BR>
To: kris_beyers@hotmail.com<BR>
CC: pythondotnet@python.org<BR>
<BR>
Did you use (in Python)<BR>
<BR>
>>> import clr<BR>
<BR>
to import the Common Language Runtime and support .NET assemblies?<BR>
<BR>
<a href="http://www.urulive.com/blog/"><http://www.urulive.com/blog/></a> <BR>
Uru Live IRC Chat: unreal.JustIRC.net #uru<BR>
<BR>
<BR>
----- Original Message ----<BR>
From: Kris Beyers <kris_beyers@hotmail.com><BR>
To: pythondotnet@python.org<BR>
Sent: Tuesday, April 10, 2007 1:31:35 PM<BR>
Subject: [Python.NET] Unable to import library imaplib<BR>
<BR>
Hi<BR>
<BR>
I'm trying to make a python script (which would be called from a C# application) and communicates with an IMAP server.<BR>
Passing variables from C# to python and back is no problem, but when I type "import imaplib" on top of the python script to support IMAP, the script fails to run at line with following code: "func.Invoke(arguments)". Showing error message in the C# developer: "<null reference>".<BR>
<BR>
I also tried to call PythonEngine.ImportModule("imaplib") first, but no change.<BR>
Is there a way to import the library? Thank you in advance.<BR>
<BR>
Tip: Just found out about an amazing C# developer <a href="http://www.sharpdevelop.net">http://www.sharpdevelop.net</a> <a href="http://www.sharpdevelop.net/"><http://www.sharpdevelop.net/></a> (open source)<BR>
<BR>
Regards,<BR>
Kris<BR>
<BR>
C#<BR>
***<BR>
try {<BR>
string imapUser = "kris";<BR>
string imapPassword = "a password";<BR>
<BR>
PythonEngine.Initialize();<BR>
<BR>
PyObject[] arguments = new PyObject[2];<BR>
arguments[0] = PyObject.FromManagedObject(imapUser);<BR>
arguments[1] = PyObject.FromManagedObject(imapPassword);<BR>
<BR>
PyObject pyportal = PythonEngine.ImportModule("PyPortal");<BR>
PyObject func = pyportal.GetAttr("invoker");<BR>
<BR>
PyObject result = func.Invoke(arguments);<BR>
this.label1.Text = result.ToString();<BR>
} catch (Exception err) {<BR>
this.label1.Text = err.Message.ToString();<BR>
}<BR>
<BR>
The file PyPortal.py<BR>
***************<BR>
import imaplib # <-- causes error<BR>
def invoker(imapUser, imapPassword):<BR>
messages = []<BR>
M = imaplib.IMAP4('imap.next.mail.yahoo.com')<BR>
M.login(imapUser, imapPassword)<BR>
M.select()<BR>
typ, data = M.search(None, 'ALL')<BR>
for num in data[0].split():<BR>
typ, data = M.fetch(num, '(RFC822)')<BR>
messages.append('Message %s\n%s\n' % (num, data[0][1]))<BR>
M.close()<BR>
M.logout()<BR>
return '<delimiter>'.join(messages)<BR>
<BR>
<BR>
<BR>
het ultieme online mailprogramma! Ontdek Windows Live Hotmail, <a href="http://get.live.com/mail/overview"><http://get.live.com/mail/overview></a> <BR>
_________________________________________________<BR>
Python.NET mailing list - PythonDotNet@python.org<BR>
<a href="http://mail.python.org/mailman/listinfo/pythondotnet">http://mail.python.org/mailman/listinfo/pythondotnet</a><BR>
<BR>
<BR>
<HR ALIGN=CENTER SIZE="1" WIDTH="100%">Now you can have a huge leap forward in email:<B> get the new Yahoo! Mail.</B> <a href="http://us.rd.yahoo.com/evt=40705/*http://mrd.mail.yahoo.com/try_beta?.intl=ca"><http://us.rd.yahoo.com/evt=40705/*http://mrd.mail.yahoo.com/try_beta?.intl=ca></a> <BR>
</SPAN></FONT></BLOCKQUOTE><FONT FACE="Verdana, Helvetica, Arial"><SPAN STYLE='font-size:12.0px'><BR>
<HR ALIGN=CENTER SIZE="3" WIDTH="100%">het ultieme online mailprogramma! Ontdek Windows Live Hotmail, <a href="http://get.live.com/mail/overview"><http://get.live.com/mail/overview></a> <BR>
<HR ALIGN=CENTER SIZE="3" WIDTH="95%"></SPAN></FONT><FONT SIZE="2"><FONT FACE="Monaco, Courier New"><SPAN STYLE='font-size:10.0px'>_________________________________________________<BR>
Python.NET mailing list - PythonDotNet@python.org<BR>
<a href="http://mail.python.org/mailman/listinfo/pythondotnet">http://mail.python.org/mailman/listinfo/pythondotnet</a><BR>
</SPAN></FONT></FONT></BLOCKQUOTE><FONT SIZE="2"><FONT FACE="Monaco, Courier New"><SPAN STYLE='font-size:10.0px'><BR>
</SPAN></FONT></FONT>
</BODY>
</HTML>