Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Invalid Python config directory

Posted on 2008-12-23
4
Medium Priority
?
1,576 Views
Last Modified: 2012-05-06
I am troubleshooting an install of Python 2.5.2 for Windows XP.  I can open up the command line without issue. - My problem is wih IDLE.  I know nothing about python, this is strictly "playing".

At the command line in the python directory I can try to start IDLE:
C:\Python25> python Lib/idlelib/idle.py
Warning: unable to create user config directory F:\.idlerc Check path and permissions.

Where is this path F:\coming from?  It needs to be C:\.
0
Comment
Question by:JoshuaPHG
  • 3
4 Comments
 
LVL 1

Author Comment

by:JoshuaPHG
ID: 23236738
I just temporarily set the %HOMEDRIVE% windows variable to C: and IDLE opened.  Aside from setting that, because it will screw up other things, where do I make that change in python?  I'm not gleaning anything from the config-main.def fille
0
 
LVL 15

Accepted Solution

by:
efn earned 750 total points
ID: 23237096
The message is coming from the GetUserCfgDir function in the IdleConf class.  To get the directory for the .idlerc file, it first calls os.path.expanduser('~').  This is supposed to get the pathname of your home directory.  If that doesn't work, it calls os.getcwd() to get the current directory.  You can try these commands in the Python interpreter to see what they generate in your environment.  You will have run "import os" first.  In my Windows XP environment, the first call yields my user directory under C:\Documents and Settings.  This is where the file is supposed to go according to the comments in config-main.def.

I realize that this doesn't solve your problem directly, but maybe you can figure out how to persuade Windows that your home directory is not F:.
0
 
LVL 1

Author Comment

by:JoshuaPHG
ID: 23237291
I in the Lib/idlelib directory I changed the configHandler.py script that you indicated.

Original:

def GetUserCfgDir(self):
        """
        Creates (if required) and returns a filesystem directory for storing
        user config files.

        """
        cfgDir = '.idlerc'
        userDir = os.path.expanduser('~')
        if userDir != '~': # expanduser() found user home dir
            if not os.path.exists(userDir):
                warn = ('\n Warning: os.path.expanduser("~") points to\n '+
                        userDir+',\n but the path does not exist.\n')
                sys.stderr.write(warn)
                userDir = '~'
        if userDir == "~": # still no path to home!
            # traditionally IDLE has defaulted to os.getcwd(), is this adequate?
            userDir = os.getcwd()
        userDir = os.path.join(userDir, cfgDir)
        if not os.path.exists(userDir):
            try:
                os.mkdir(userDir)
            except (OSError, IOError):
                warn = ('\n Warning: unable to create user config directory\n'+
                        userDir+'\n Check path and permissions.\n Exiting!\n\n')
                sys.stderr.write(warn)
                raise SystemExit
        return userDir

New:

def GetUserCfgDir(self):
        """
        Creates (if required) and returns a filesystem directory for storing
        user config files.

        """
        cfgDir = '.idlerc'
        userDir = os.getcwd()
        #userDir = os.path.expanduser('~')
        #if userDir != '~': # expanduser() found user home dir
        #    if not os.path.exists(userDir):
        #        warn = ('\n Warning: os.path.expanduser("~") points to\n '+
        #                userDir+',\n but the path does not exist.\n')
        #        sys.stderr.write(warn)
        #        userDir = '~'
        #if userDir == "~": # still no path to home!
        #    # traditionally IDLE has defaulted to os.getcwd(), is this adequate?
        #    userDir = os.getcwd()
        userDir = os.path.join(userDir, cfgDir)
        if not os.path.exists(userDir):
            try:
                os.mkdir(userDir)
            except (OSError, IOError):
                warn = ('\n Warning: unable to create user config directory\n'+
                        userDir+'\n Check path and permissions.\n Exiting!\n\n')
                sys.stderr.write(warn)
                raise SystemExit
        return userDir

It works now, but I don't really like it.  Essentially everything is remmed out except for the os.getcwd() part.  Maybe I should just have my HOMEDRIVE changed...

Any other thoughts before I close it out?
0
 
LVL 1

Author Comment

by:JoshuaPHG
ID: 23237445
Replaced userDir = os.getcwd() with  userDir = 'C:\\Documents and Settings\\' + os.getenv('username')

I'm a little happier now.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Six Sigma Control Plans
Starting up a Project
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question