rpy2 Windows unable to unlink tempfile

Issue #132 new
Don Oxley created an issue

(posted earlier on StackOverflow - http://stackoverflow.com/questions/16992115/rpy2-windows-unable-to-unlink-tempfile).

I'm using Python 3.3, R-3.0.1, Win7-64. I'm getting an "Unable to unlike tempfile" in rpy2.robject (ln 48). Looking at it, some other process (presumably R) has hold of the file when Python is trying to release i

Comments (14)

  1. lorifan

    I experience the same issue with Python 2.7.3, Win7-32, R.14.2, Rpy2-2.30: "Unable to unlink tempfile c:\users\xyz\appdata\local\temp\tmpbqwhlz"

  2. Laurent Gautier

    This might be coming from robjects.robject.py (see below).

    Can you try editing the installed module and print the WindowsError ? (there might be clues about what is happening in the error message)

            if sys.platform == 'win32':
                self.__sink()
                s = tmpf.readlines()
                tmpf.close()
                try:
                    del tmpf
                    os.unlink(tfname)
                except WindowsError:
                    if os.path.exists(tfname):
                        print 'Unable to unlink tempfile %s' % tfname
                s = str.join(os.linesep, s)
    
  3. Laurent Gautier
    1. Find the file robject.py on your system. Start python and enter:
    import rpy2.robjects
    rpy2.robjects.__path__ # the file is in this directory
    
    1. Edit that file so the snippet above becomes:
            if sys.platform == 'win32':
                self.__sink()
                s = tmpf.readlines()
                tmpf.close()
                #try:
                del tmpf
                os.unlink(tfname)
                #except WindowsError:
                #    if os.path.exists(tfname):
                #        print 'Unable to unlink tempfile %s' % tfname
                s = str.join(os.linesep, s)
    
  4. Laurent Gautier

    Windows file locking has its mysterious ways.

    If @doxley does not object, I guess that you can close the issue as resolved then.

  5. chang nan243

    Hi Laurent, I am using python 2.7.5 and R 3.0.1, I have encounter the same trouble, as i finish editing the robjects.py as above, it has another error as: WindowsError: [Error 32] : 'c:\users\chn\appdata\local\temp\tmphkd3lg' can you help me to fix it ?

  6. tobiasBSI

    I get the "unable to unlink..." error using R-3.0.2, Python 2.7.5 and rpy2-2.3.8 on a Windows7-32 machine. Editing robjects.py as above results in the windows error stated above by chang nan243. I would be very grateful for any help to fix this!!! Thank you very much, Tobias

  7. Vitas Anderson

    Hi all, I'm getting the same problem too. My setup is: Win7 (64bit), R-3.0.2 (64 bit), Python 2.7.5 (Anaconda 64 bit)

  8. Log in to comment