安装TensorFlow时出现IOError: [Errno 28] No space left on device的错误。

34

我正在尝试使用以下命令在我的本地目录中安装TensorFlow。

export TF_BINARY_URL=http://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0-cp27-none-linux_x86_64.whl
pip install --install-option="--prefix=$PYTHONUSERBASE" --upgrade $TF_BINARY_URL

我遇到了以下错误:

IOError: [Errno 28] No space left on device

接着我运行了df命令,看到了以下内容:

Filesystem             1K-blocks       Used   Available Use% Mounted on
tmpfs                      10240      10240           0 100% /tmp
tmpfs                      10240      10240           0 100% /var/tmp

是否有方法可以在不下载临时文件到/tmp/var/tmp的情况下安装TF?谢谢。

6个回答

58
通常情况下,您可以设置环境变量“TMPDIR”以使用与“/tmp”或“/var/tmp”不同的目录,大多数程序将遵守此设置。
您可以尝试执行以下操作: $ export TMPDIR=$HOME/tmp 然后开始安装pip。

8
好的建议,易于使用。我进一步建议您这样运行它:TMPDIR=tmp pip install <package>因为如果在同一个shell中,您可能会忘记后面的导出操作。 - lingfish
4
请务必创建文件夹:mkdir -p $TMPDIR,不这样做会给我造成问题。 - fabian789
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html - outoftime
2
你的解决方案在我的情况下有效 @lingfish - user3503711

16
你可以使用'pip install -b /some/other/dir'来更改构建目录。
你也可以更改wheel目录,如此处所示: https://pip.pypa.io/en/stable/user_guide/#installation-bundles 运行pip help install将为您提供其他目录选项。
-b, --build <dir>           Directory to unpack packages into and build in.
-t, --target <dir>          Install packages into <dir>. By default this will not replace existing files/folders in <dir>. Use --upgrade to replace existing packages in <dir> with new versions.
-d, --download <dir>        Download packages into <dir> instead of installing them, regardless of what is already installed.
--src <dir>                 Directory to check out editable projects into. The default in a virtualenv is "<venv path>/src". The default for global installs is "<current dir>/src".

“-b --build”已被弃用,当设置“--build”标志时,C文件的编译仍在TMPDIR中进行。为我解决问题的是设置“TMPDIR”。 - Samuel

5
在/home/myuser下创建tmp文件夹,然后在终端中执行"export TMPDIR=/home/$USER/tmp"命令。

1
哟,实际上这个更有帮助。 - Sibish

5
export TMPDIR=/bigspace/space

为什么会出现磁盘空间错误?可能是由于 /tmp 目录没有足够的空间。
在 pip 安装过程中,pip 会使用 /tmp 目录执行安装所必须的操作(例如下载源码等)。
因此,如果你的 /tmp 目录没有足够的空间来满足包安装的需要,那么就会出现磁盘空间错误。
你可以使用下面的命令配置你的 /tmp 目录位置。

5

解决方案1: 在此解决方案中,Pip不会重新下载包,但在其他解决方案中会这样做。

使用 df -h 检查可用磁盘空间:

如果您只需要更改tmpfs大小,可以使用新大小在线重新安装它:

$ sudo mount -o remount,size=10G /tmp
$ sudo mount -o remount,size=10G /var/tmp

解决方案2:您可以为pip设置环境变量'TMPDIR'

$ export TMPDIR=$HOME/new/tmp/dir
$ pip install --install-option="--prefix=$PYTHONUSERBASE" --upgrade $TF_BINARY_URL

解决方案3: 使用自定义缓存/临时目录

$ pip install --cache-dir=$HOME/new/tmp/dir/  --install-option="--prefix=$PYTHONUSERBASE" --upgrade $TF_BINARY_URL

解决方法4: 没有缓存目录

pip install --no-cache-dir --install-option="--prefix=$PYTHONUSERBASE" --upgrade $TF_BINARY_URL

2

这适用于 Python3.9 和 pip 23.1。

您需要设置变量 TMPDIR 并指定 --cache-dir 选项。

TMPDIR=/mybigtemp pip3 --cache-dir /mybigtemp  install tensorflow tensorflow_probability

在帮助中查看所有pip安装选项:

pip3 help install

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接