0

When I run the script, I had this ImportError:

$ python ~/Dropbox/code/py/ZoteroFindOrphanedFiles.py 
Traceback (most recent call last):
  File "/home/zane/Dropbox/code/py/ZoteroFindOrphanedFiles.py", line 1, in <module>
    import sqlite3
  File "/usr/lib/python3.2/sqlite3/__init__.py", line 23, in <module>
    from sqlite3.dbapi2 import *
  File "/usr/lib/python3.2/sqlite3/dbapi2.py", line 23, in <module>
    import datetime
  File "/usr/lib/python3.2/datetime.py", line 20, in <module>
    import math as _math
  File "/home/zane/Dropbox/code/py/math.py", line 3, in <module>
    from nzmath.rational import Integer, Rational
ImportError: No module named nzmath.rational

But I don't have it when running the interactive session:

$ python
Python 3.2.3 (default, Apr 23 2012, 23:14:44) 
[GCC 4.7.0 20120414 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> 

Why is that?

2
  • Its failing on the line "from nzmath.rational import Integer, Rational" Commented Jul 31, 2012 at 20:13
  • Can you try importing Integer from nzmath.rational on interactive session? After that compare sys.path from both sessions. Commented Jul 31, 2012 at 20:14

3 Answers 3

3

Here is the problem:

  import math as _math
File "/home/zane/Dropbox/code/py/math.py", line 3, in <module>

You have your own module called math.py, but this is the same as a standard Python module of the same name. This is not recommended.

The solution is to rename your math.py to something else, and don't forget to delete the math.pyc in the same directory (otherwise you'll still have the same problem).

Sign up to request clarification or add additional context in comments.

1 Comment

right, it's a stupid mistake. I should have read the error message more carefully.
0

You have a local file /home/zane/Dropbox/code/py/math.py which is getting imported instead of the standard lib math module.

The solution is to rename your /home/zane/Dropbox/code/py/math.py to something else.

The problem occurs when you call a script in the /home/zane/Dropbox/code/py directory since this adds this directory to the beginning of sys.path and thus this directory gets searched first when Python tries to import modules.

Comments

0

You have a file called math.py in the script's directory, and this shadows the stdlib math module. Rename the file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.