O'Reilly Forums: Chapter 2: Problems With My Sys.path - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Chapter 2: Problems With My Sys.path IDLE can't find module, but my shell interpreter can???

#1 User is offline   Big_Pug 

  • New Member
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 29-December 12

Posted 29 December 2012 - 08:07 PM

I'm using Ubuntu 12, and Python 3.2 (with IDLE 3.2).

When I use the terminal Python interpreter, I can import my 'nester' module, but when I use IDLE, it tells me 'no module named nester' in red letters!

I've tried adding a .pth to site-packages. Also tried sticking

import sys
sys.path.append('/Python-3.2/my_modules')

at the end of site.py.

How on earth do I get IDLE to recognize that my module exists and works perfectly fine?
0

#2 User is offline   paulbarry 

  • Advanced Member
  • PipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 251
  • Joined: 20-August 09

Posted 30 December 2012 - 12:43 AM

IDLE can be fussy about its start-up directory. To find out which one its using, do this at the IDLE shell:

>>> import os
>>> os.getcwd()

That'll tell you where IDLE thinks it is. You can then change to your module's directory with:

>>> os.chdir('Python-3.2/my_modules')

and happily import nester.

Alternatively, invoke IDLE using these commands:

$ cd Python-3.2/my_modules
$ idle3

and nester will be in the default import path (as the directory you invoked IDLE from is always included in the default).

Later in the chapter, we use Python's setup tools to install nester into your Python environment, which gets rid of all of these types of issues.

Hope this helps.

--Paul.
0

#3 User is offline   Big_Pug 

  • New Member
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 29-December 12

Posted 30 December 2012 - 02:14 PM

You're a genius, it worked. Thank you so much!

For other Linux/Ubuntu users like me... I first reformatted my computer because it was having other issues. (It stopped installing stuff properly... Applications were refusing to start... It was madness.) So, I still don't know what the problem might have been, originally. But, I came back, re-installed my Python 3 and idle3, and used the second tactic here (opening idle3 from inside the module folder).

Anyway. Complete success!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users