Python 找不到可用的临时目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16996125/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
No usable temporary directory found
提问by OpenCurious
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.
该目录的权限为 root 拥有的 777。
采纳答案by Atul Arvind
This kind of error occured in two case
这种错误发生在两种情况
- permission(should be drwxrwxrwt and owened by root)
- space
- 权限(应该是drwxrwxrwt并且由root拥有)
- 空间
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
将列出 unix 上的磁盘使用情况并获得类似的输出
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 28G 15G 12G 58% /
If the root(mounted on /) usage is 100%.
如果 root(mounted on /) 使用率为 100%。
You need to clean the tmp directory or restart the machine or make some space on the root.
您需要清理 tmp 目录或重新启动机器或在根目录上腾出一些空间。
回答by Chris Mutel
This error can occur when the file system has been switched to read-only mode.
当文件系统切换到只读模式时,可能会发生此错误。
回答by Ajit K'sagar
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
[root@master 色调]# 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
已使用的文件系统大小 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
[root@master log]#服务hue启动
Starting hue: [ OK ]
起始色调:[确定]
[root@master log]#
[root@master 日志]#
回答by Edwin Ikechukwu Okonkwo
definately a disk space issue,
绝对是磁盘空间问题,
on terminal, type df -hyou should see output like below ( notice the 100% on one of the filesystems)
在终端上,键入df -h您应该会看到如下输出(注意文件系统之一上的 100%)
$ 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 /
在这种情况下,您需要通过删除路径根上的文件、工件文件夹等来腾出空间 /
回答by Roozbeh Zabihollahi
I had the same problem while running a python script in Docker. The following command fixed it for me:
我在 Docker 中运行 python 脚本时遇到了同样的问题。以下命令为我修复了它:
docker rmi $(docker images --quiet --filter "dangling=true")
回答by Yuukoo
Problem can also occur if inodeare full.
如果inode已满,也会出现问题。
You can type df -i
你可以输入 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
回答by and1er
I had the same issue on the Windows 7x64 machine. It was OK with disk space and permissions.
我在 Windows 7x64 机器上遇到了同样的问题。磁盘空间和权限没问题。
When I excecuted
当我执行
tempfile.mkdtemp(prefix='MyPrefix_')
manually in python console the directory %TEMP%\MyPrefix_xxxxwas successfully created.
But when I did the same from script I received the error IOError: [Errno 2] No usable temporary directory found in [...].
手动在python控制台%TEMP%\MyPrefix_xxxx中成功创建目录。但是当我从脚本中做同样的事情时,我收到了错误IOError: [Errno 2] No usable temporary directory found in [...]。
I solved the problem using dirparameter:
我使用dir参数解决了这个问题:
# '.' is a default value for example
tempfile.mkdtemp(prefix='MyPrefix_', dir=os.environ.get('TEMP', '.'))
After that from script it worked well.
之后从脚本它运行良好。
回答by L. Taylor
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.
我今天早些时候遇到了这个问题。我在去吃午饭之前开始了一个嵌入在 jupyter 中的查询,然后我返回到 jupyter 抛出了某种类型的错误(不记得它到底是什么)。当我尝试在终端中重新启动 jupyter 时,出现了 OP 问题中描述的错误(没有可用的临时目录)。上面的答案不起作用,所以我尝试重新启动我的整个 VM,此时我得到了这里描述的错误。按照该线程的最佳答案中的说明进行操作后,问题已解决。

