Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

import error in python

I get the following error

Traceback (most recent call last):
File "myemail.py", line 1, in <module>
  import smtplib
File "/usr/lib/python2.6/smtplib.py", line 46, in <module>
  import email.utils
File "/home/nikhil/Desktop/bujji/email.py", line 2, in <module>
ImportError: No module named MIMEMultipart

when i run the code example

I tried to google out the error but nothing worked.

like image 660
nikhil Avatar asked Aug 07 '11 06:08

nikhil


People also ask

Why can't I import modules in Python?

This is caused by the fact that the version of Python you're running your script with is not configured to search for modules where you've installed them. This happens when you use the wrong installation of pip to install packages.

How do I get Python to import?

You can manually go and check the PYTHONPATH variable contents to find the directories from where these built in modules are being imported. Running "python -v"from the command line tells you what is being imported and from where. This is useful if you want to know the location of built in modules.

What is import command in Python?

In Python, you use the import keyword to make code in one module available in another. Imports in Python are important for structuring your code effectively. Using imports properly will make you more productive, allowing you to reuse code while keeping your projects maintainable.


2 Answers

You've stomped on the email package in the stdlib by naming a script email.py. Rename it.

like image 197
Ignacio Vazquez-Abrams Avatar answered Jan 01 '23 21:01

Ignacio Vazquez-Abrams


Don't have enough reputation to comment on Ignacio Vazquez-Abrams's answer but make sure that not only do you remove email.py put also things like email.py~ and email.pyc

like image 35
Peter Lonjers Avatar answered Jan 01 '23 21:01

Peter Lonjers