473,395 Members | 2,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 2413
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.