#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Location
    Sweden
    Posts
    3
    Rep Power
    0

    Import module problem


    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.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    43
    Rep Power
    2
    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:

    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.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Location
    Sweden
    Posts
    3
    Rep Power
    0
    I actually got it working the same minute that you replied to me. I first had to rename the file from config to config.py and then just add "from config import *" and it worked! But thank you for the fast reply

IMN logo majestic logo threadwatch logo seochat tools logo