<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&#8217;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&#8217;t have imaplib installed.<BR>
<BR>
I&#8217;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, &quot;Kris Beyers&quot; &lt;kris_beyers@hotmail.com&gt; wrote:<BR>
<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Verdana, Helvetica, Arial"><SPAN STYLE='font-size:12.0px'>Hi<BR>
&nbsp;<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 &quot;imaplib&quot;, 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>
&nbsp;<BR>
Furthermore I included C:\Program Files\PythonNet in the same systemvariable, but that's nog part of the problem I guess.<BR>
&nbsp;<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>
&gt;&gt;&gt; import clr<BR>
<BR>
to import the Common Language Runtime and support .NET assemblies?<BR>
&nbsp;<BR>
&nbsp;<a href="http://www.urulive.com/blog/">&lt;http://www.urulive.com/blog/&gt;</a> <BR>
Uru Live IRC Chat: unreal.JustIRC.net #uru<BR>
<BR>
<BR>
----- Original Message ----<BR>
From: Kris Beyers &lt;kris_beyers@hotmail.com&gt;<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>
&nbsp;<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 &quot;import imaplib&quot; on top of the python script to support IMAP, the script fails to run at line with following code: &quot;func.Invoke(arguments)&quot;. Showing error message in the C# developer: &quot;&lt;null reference&gt;&quot;.<BR>
&nbsp;<BR>
I also tried to call PythonEngine.ImportModule(&quot;imaplib&quot;) first, but no change.<BR>
Is there a way to import the library? Thank you in advance.<BR>
&nbsp;<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/">&lt;http://www.sharpdevelop.net/&gt;</a> &nbsp;(open source)<BR>
&nbsp;<BR>
Regards,<BR>
Kris<BR>
&nbsp;<BR>
C#<BR>
***<BR>
try {<BR>
&nbsp;string imapUser = &quot;kris&quot;;<BR>
&nbsp;string imapPassword = &quot;a password&quot;;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;PythonEngine.Initialize();<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;PyObject[] arguments = new PyObject[2];<BR>
&nbsp;arguments[0] = PyObject.FromManagedObject(imapUser);<BR>
&nbsp;arguments[1] = PyObject.FromManagedObject(imapPassword);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;PyObject pyportal = PythonEngine.ImportModule(&quot;PyPortal&quot;);<BR>
&nbsp;PyObject func = pyportal.GetAttr(&quot;invoker&quot;);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;PyObject result = func.Invoke(arguments);<BR>
&nbsp;this.label1.Text = result.ToString();<BR>
} catch (Exception err) {<BR>
&nbsp;this.label1.Text = err.Message.ToString();<BR>
}<BR>
&nbsp;<BR>
The file PyPortal.py<BR>
***************<BR>
import imaplib &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# &nbsp;&lt;-- causes error<BR>
def invoker(imapUser, imapPassword):<BR>
&nbsp;&nbsp;&nbsp;&nbsp;messages = []<BR>
&nbsp;&nbsp;&nbsp;&nbsp;M = imaplib.IMAP4('imap.next.mail.yahoo.com')<BR>
&nbsp;&nbsp;&nbsp;&nbsp;M.login(imapUser, imapPassword)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;M.select()<BR>
&nbsp;&nbsp;&nbsp;&nbsp;typ, data = M.search(None, 'ALL')<BR>
&nbsp;&nbsp;&nbsp;&nbsp;for num in data[0].split():<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typ, data = M.fetch(num, '(RFC822)')<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.append('Message %s\n%s\n' % (num, data[0][1]))<BR>
&nbsp;&nbsp;&nbsp;&nbsp;M.close()<BR>
&nbsp;&nbsp;&nbsp;&nbsp;M.logout()<BR>
&nbsp;&nbsp;&nbsp;&nbsp;return '&lt;delimiter&gt;'.join(messages)<BR>
&nbsp;<BR>
&nbsp;<BR>
<BR>
het ultieme online mailprogramma! Ontdek Windows Live Hotmail, <a href="http://get.live.com/mail/overview">&lt;http://get.live.com/mail/overview&gt;</a> &nbsp;<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">&lt;http://us.rd.yahoo.com/evt=40705/*http://mrd.mail.yahoo.com/try_beta?.intl=ca&gt;</a> &nbsp;<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">&lt;http://get.live.com/mail/overview&gt;</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>