472,378 Members | 1,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,378 software developers and data experts.

python import problem (different versions of python)?

Newbie here with a (hopefully not) dumb question....tried searching around on the 'Net without success, so here goes....

I have been playing around with python. I wrote a script that sends an smtp email. Here is the link that I found explaining how such a script could be written Sending an Email

As you see it imports a module as follows: "import smtplib".

I am using a linux machine (ubuntu ditro). It has both python2.5 and python2.4 installed. I also have wxpython installed.

Here is the script:

Expand|Select|Wrap|Line Numbers
  1. #! /usr/bin/env python
  2.  
  3. def Email_func (Mess):
  4.  
  5.     import smtplib
  6.  
  7.     HeaderFile = '/home/***.***'
  8.     Header = open(HeaderFile, 'r')
  9.     MyAddress = Header.readline()
  10.     OppAddress = Header.readline()
  11.     Subject = Header.readline()
  12.     EmailFull = ''.join([MyAddress, OppAddress, Subject, Mess])
  13.  
  14.     # smtp sever settings
  15.  
  16.     smtpserver = 'mydomain.com'
  17.     AUTHREQUIRED = 1 # if you need to use SMTP AUTH set to 1
  18.     smtpuser = 'myname@mydomain.com'  # for SMTP AUTH, set SMTP username here
  19.     smtppass = '****'  # for SMTP AUTH, set SMTP password here
  20.  
  21.     # creating email address settings
  22.  
  23.     RECIPIENTS = [OppAddress, MyAddress]
  24.     SENDER = MyAddress
  25.  
  26.     # sending email
  27.  
  28.     session = smtplib.SMTP(smtpserver)
  29.     if AUTHREQUIRED:
  30.         session.login(smtpuser, smtppass)
  31.         print "Email successfully sent!"
  32.     smtpresult = session.sendmail(SENDER, RECIPIENTS, EmailFull)
  33.  
  34.     if smtpresult:
  35.         errstr = ""
  36.         for recip in smtpresult.keys():
  37.             errstr = """Could not delivery mail to: %s
  38.  
  39.     Server said: %s
  40.     %s
  41.  
  42.     %s""" % (recip, smtpresult[recip][0], smtpresult[recip][1], errstr)
  43.         raise smtplib.SMTPException, errstr
From the terminal, the script works fine. I then played around with tkinter, and I got the script to work from a GUI as well.

However, I then tried playing around with wxpython and when I tried to send the email thru the wxpython created GUI, I get the following error message:

Traceback (most recent call last):
File "/home/***/python_scripts/glade/email.py", line 40, in save
SendGame_func.EmailGame(self.text_ctrl_1.GetValue( ))
File "/home/****/python_scripts/glade/SendGame_func.py", line 5, in EmailGame
import smtplib
File "/usr/lib/python2.4/smtplib.py", line 49, in ?
from email.base64MIME import encode as encode_base64
ImportError: No module named base64MIME
I have looked around in my /usr/lib directory, and there is an smtplib in a python2.4 directory and one in the python2.5 directory.

I tried changing:

#! /usr/bin/env python
to

#! /usr/bin/python2.4
In both the above script and the GUI scripts. Result is the same, so I changed it to:

#! /usr/bin/python2.5
With the result that the wxpython script tells me:

Traceback (most recent call last):
File "/home/****/python_scripts/glade/email.py", line 5, in <module>
import wx
ImportError: No module named wx
Why am I getting this error in wxpython, but not tkinter and the terminal?
May 15 '07 #1
3 2317
bartonc
6,596 Expert 4TB
Newbie here with a (hopefully not) dumb question....tried searching around on the 'Net without success, so here goes....

I have been playing around with python. I wrote a script that sends an smtp email. Here is the link that I found explaining how such a script could be written Sending an Email

As you see it imports a module as follows: "import smtplib".

I am using a linux machine (ubuntu ditro). It has both python2.5 and python2.4 installed. I also have wxpython installed.

Here is the script:

Expand|Select|Wrap|Line Numbers
  1. #! /usr/bin/env python
  2.  
  3. def Email_func (Mess):
  4.  
  5.     import smtplib
  6.  
  7.     HeaderFile = '/home/***.***'
  8.     Header = open(HeaderFile, 'r')
  9.     MyAddress = Header.readline()
  10.     OppAddress = Header.readline()
  11.     Subject = Header.readline()
  12.     EmailFull = ''.join([MyAddress, OppAddress, Subject, Mess])
  13.  
  14.     # smtp sever settings
  15.  
  16.     smtpserver = 'mydomain.com'
  17.     AUTHREQUIRED = 1 # if you need to use SMTP AUTH set to 1
  18.     smtpuser = 'myname@mydomain.com'  # for SMTP AUTH, set SMTP username here
  19.     smtppass = '****'  # for SMTP AUTH, set SMTP password here
  20.  
  21.     # creating email address settings
  22.  
  23.     RECIPIENTS = [OppAddress, MyAddress]
  24.     SENDER = MyAddress
  25.  
  26.     # sending email
  27.  
  28.     session = smtplib.SMTP(smtpserver)
  29.     if AUTHREQUIRED:
  30.         session.login(smtpuser, smtppass)
  31.         print "Email successfully sent!"
  32.     smtpresult = session.sendmail(SENDER, RECIPIENTS, EmailFull)
  33.  
  34.     if smtpresult:
  35.         errstr = ""
  36.         for recip in smtpresult.keys():
  37.             errstr = """Could not delivery mail to: %s
  38.  
  39.     Server said: %s
  40.     %s
  41.  
  42.     %s""" % (recip, smtpresult[recip][0], smtpresult[recip][1], errstr)
  43.         raise smtplib.SMTPException, errstr
From the terminal, the script works fine. I then played around with tkinter, and I got the script to work from a GUI as well.

However, I then tried playing around with wxpython and when I tried to send the email thru the wxpython created GUI, I get the following error message:



I have looked around in my /usr/lib directory, and there is an smtplib in a python2.4 directory and one in the python2.5 directory.

I tried changing:



to



In both the above script and the GUI scripts. Result is the same, so I changed it to:



With the result that the wxpython script tells me:



Why am I getting this error in wxpython, but not tkinter and the terminal?
wx installs in the site-packages directory of the python version that is is compiled to run under (they're different). You'll need to have each wx site packagd installed in order to be able to switch versions of the interpreter.

Hope that helps,
Barton
May 15 '07 #2
wx installs in the site-packages directory of the python version that is is compiled to run under (they're different). You'll need to have each wx site packagd installed in order to be able to switch versions of the interpreter.

Hope that helps,
Barton
Yes, that is helpful. But what file am I looking for in "site-packages?" In the python2.5 directory there is no file or subdirectory that seems to reference wx. In python2.4, there are several files that seem to be wx related, plus a wxglade directory

Interestingly, the wxpython GUI that I am having ptroblems with was created with wxglade. After I posted above post, I added a email choice to a menu to a GIU that I hand coded with wxpython (the GUI was based on one I created following along this tutorial. That script calls the same email function as above, and it worked fine?

Is this just a thing with wxglade? Not sure what is in the source that makes the wxglade created script behave differently? All "imports" etc seem to be the same as the other wxpython script?

Thanks for bearing with me :-)
May 16 '07 #3
bartonc
6,596 Expert 4TB
Yes, that is helpful. But what file am I looking for in "site-packages?" In the python2.5 directory there is no file or subdirectory that seems to reference wx. In python2.4, there are several files that seem to be wx related, plus a wxglade directory

Interestingly, the wxpython GUI that I am having ptroblems with was created with wxglade. After I posted above post, I added a email choice to a menu to a GIU that I hand coded with wxpython (the GUI was based on one I created following along this tutorial. That script calls the same email function as above, and it worked fine?

Is this just a thing with wxglade? Not sure what is in the source that makes the wxglade created script behave differently? All "imports" etc seem to be the same as the other wxpython script?

Thanks for bearing with me :-)
The wx installation should be 1 directory (sorry, I'm not on my development machine at the moment) plus one .pth file that points to that directory and (I think) there's something like wxaddons directory (don't know what's in there).

Also, I'm on windows so the help that I can offer is limited in this regard.

I had problems with wxGlade on windows. I switched to Boa Constructor a long time ago. Boa is TRULY a miraculous piece of work!
May 17 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

54
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
6
by: manatlan | last post by:
I've got a trouble, and i think that anybody there can help me I've got a python script which i distribute in somes packages for *nix. This script is full of python and need python 2.4 ! And i'd...
11
by: John Nagle | last post by:
How naive (in the sense that compiler people use the term) is the current Python system? For example: def foo() : s = "This is a test" return(s) s2 = foo() How many times does the string...
4
by: andrea | last post by:
Hi everyone, I use python on macosx with textmate as editor (great program). I also use macport to install unix programs from the command line and I find it great too. Well I would like to have...
24
by: Joe Salmeri | last post by:
I just upgraded from Python 2.4.2 to Python 2.5.1 and have found some unexpected behavior that appears to be a bug in the os.stat module. My OS is Windows XP SP2 + all updates. I have several...
7
by: greg | last post by:
Thomas Philips wrote: Have a look in /Library/Frameworks/Python.framework/Versions/2.5 You can't -- this feature only exists in the Search window, which is a different kind of window...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...
0
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.