66

I am trying to find a temp directory , but when i am trying to get the directory using

tempfile.gettempdir()

it's giving me error of

 File "/usr/lib/python2.6/tempfile.py", line 254, in gettempdir
    tempdir = _get_default_tempdir()
  File "/usr/lib/python2.6/tempfile.py", line 201, in _get_default_tempdir
    ("No usable temporary directory found in %s" % dirlist))
IOError: [Errno 2] No usable temporary directory found in ['/tmp', '/var/tmp', '/usr/tmp', '/home/openerp/openerp-server']

The permission on the directory is 777 owned by root.

OpenCurious
  • 2,386
  • 4
  • 19
  • 25
  • 6
    I only know of this issue turning up if the disk is full, since the method finds a valid directory by attempting to write a temporary file. I don't suppose that's your issue? – Sajjan Singh Jun 08 '13 at 04:47
  • 2
    @BhajunSingh: I was shocked by your claim that Python would determine which directly to use by actually trying to create a file there. But it's true: http://hg.python.org/cpython/file/2.7/Lib/tempfile.py#l176 - see `_get_default_tempdir()`. It seems very strange not to just use `os.access()` to check if a directory can be written to. – John Zwinck Jun 08 '13 at 04:57
  • I think @BhajunSingh is right, the disk is probably full. http://stackoverflow.com/questions/7518297/new-error-in-supervisord-on-ubuntu – Brent Washburne Jun 08 '13 at 04:59
  • @BrentWashburne I have checked that answer, then after i'll check the disk usage. – OpenCurious Jun 08 '13 at 05:04

9 Answers9

94

This kind of error occured in two case

  1. permission(should be drwxrwxrwt and owened by root)
  2. space

To check space(disk usage)just run the command on terminal

df -h

Will list the disk usage on unix and get the output like

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda5        28G   15G   12G  58% /

If the root(mounted on /) usage is 100%.

You need to clean the tmp directory or restart the machine or make some space on the root.

Atul Arvind
  • 13,690
  • 5
  • 43
  • 54
11

Problem can also occur if inode are full.

You can type df -i

# df -i
Filesystem      Inodes   IUsed  IFree IUse% Mounted on
udev            253841     322 253519    1% /dev
tmpfs           255838     430 255408    1% /run
/dev/xvda1     5120000 5120000      0  100% /
tmpfs           255838       1 255837    1% /dev/shm
tmpfs           255838       7 255831    1% /run/lock
tmpfs           255838      16 255822    1% /sys/fs/cgroup
tmpfs           255838       4 255834    1% /run/user/1000
Yuukoo
  • 111
  • 1
  • 3
  • 1
    Upvote this. Because this is definitely another reason causing this problem. I was caching a lot of logs that crossed the inode limit. Type df -I and if something is 100% then you need to clear such files. Logged files and caching of data in different files must be the possible issue. – vineetv2821993 Feb 13 '20 at 19:09
  • Either you will run out of space or you will run out the number of files you can create. – vineetv2821993 Feb 13 '20 at 19:10
10

This error can occur when the file system has been switched to read-only mode.

Chris Mutel
  • 1,501
  • 1
  • 9
  • 9
7

I had the same problem while running a python script in Docker. The following command fixed it for me:

docker rmi $(docker images --quiet --filter "dangling=true")
Roozbeh Zabihollahi
  • 6,557
  • 41
  • 36
4

I got the same issue when there was no space on /.

Issue:

File "/usr/lib64/python2.6/tempfile.py", line 201, in _get_default_tempdir("No usable temporary directory found in %s" % dirlist))
IOError: [Errno 2] No usable temporary directory found in ['/tmp', '/var/tmp', '/usr/tmp', '/']  [FAILED] 

[root@master hue]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/vg_master-lv_root

             35G   34G     0 100%     /

tmpfs
7.8G 72K 7.8G 1% /dev/shm

/dev/sda1
477M 34M 418M 8% /boot

When I cleared out some space then it worked fine for me.

[root@master log]# service hue start

Starting hue: [ OK ]

[root@master log]#

Ajit K'sagar
  • 1,418
  • 11
  • 11
  • I work on a virtual machine on my university's container and your answer didn't help me. The problem still exists! – Sara Oct 20 '20 at 20:38
1

definately a disk space issue,

on terminal, type df -h you should see output like below ( notice the 100% on one of the filesystems)

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            992M     0  992M   0% /dev
tmpfs           200M   21M  179M  11% /run
/dev/xvda1      7.8G  7.8G  0  100% /
tmpfs          1000M     0 1000M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs          1000M     0 1000M   0% /sys/fs/cgroup
tmpfs           200M     0  200M   0% /run/user/997
tmpfs           200M     0  200M   0% /run/user/1042

in this case, you need to make space by deleting files, artifacts folders e.t.c on path root /

Edwin O.
  • 3,671
  • 33
  • 37
1

I had the same issue on the Windows 7x64 machine. It was OK with disk space and permissions.

When I excecuted

tempfile.mkdtemp(prefix='MyPrefix_')

manually in python console the directory %TEMP%\MyPrefix_xxxx was successfully created. But when I did the same from script I received the error IOError: [Errno 2] No usable temporary directory found in [...].

I solved the problem using dir parameter:

 # '.' is a default value for example
 tempfile.mkdtemp(prefix='MyPrefix_', dir=os.environ.get('TEMP', '.')) 

After that from script it worked well.

and1er
  • 459
  • 5
  • 14
0

I ran into this issue earlier today. I started a query embedded in jupyter before going to lunch, and I returned to jupyter throwing some type of error (can't remember what it was exactly). When I tried restarting jupyter in the terminal, I got the error described in OP's question (no usable temporary directory). The answers above didn't work, so I tried restarting my entire VM, at which point I got the error described here. After following the instructions in that thread's top answer, the problem was resolved.

L. Taylor
  • 23
  • 4
  • Hi, Welcome to SO. fyi This should be a comment rather than an answer – bagerard Oct 02 '19 at 18:41
  • Thanks- can you elaborate? I thought that if someone consulted this thread for an answer to OP's question, they may be interested in the solution I provided. Since it doesn't really fit into the conversation of any of the other answers, I don't know where I would have commented. – L. Taylor Oct 02 '19 at 19:43
0

I got this when my root drive (/dev/sda1) was corrupted on my Ubuntu.

Rebooted, got the error /dev/sda1 contains a file system with errors.

Followed instructions here: https://askubuntu.com/questions/885062/root-file-system-requires-manual-fsck, which was to fsck -y <dev/xxx reported to have error> twice. Then exit to reboot.

Kashyap
  • 12,510
  • 8
  • 55
  • 90