
January 21st, 2013, 03:46 PM
|
|
Contributing User
|
|
Join Date: Nov 2012
Posts: 43
Time spent in forums: 15 h 59 m 28 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by ShadowCore Hi!
I'm trying to import a module that contains some information. The file is called config and the code to include it is:
Code:
import config
config.path("/home/raven/ShadowBot-0.0.1/")
The file IS in that path, but when I start the program it gives me a "No such module" error. |
I am not sure but I think you are trying to import sys module, then add a path to the sys.path section.
When I print my sys.path, it returns:
Code:
['C:\\Python26\\Lib\\idlelib', 'C:\\WINDOWS\\system32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\site-packages']
These are all the folders it will look for a module. According to Python's Documentation:
Quote: | When a module named spam is imported, the interpreter first searches for a built-in module with that name. If not found, it then searches for a file named spam.py in a list of directories given by the variable sys.path. |
Sooo I am assuming what you want to do is:
import sys
dir="C://Windows/ect"+"/home/raven/ShadowBot-0.0.1/"
sys.path.append(dir)
import config
I am not sure but I think you will need the full directory for this to work. Also not sure if this WILL work. The reason you're having problems importing a module that's undefined is because the path of that module isn't in sys.path.
|