背景

背景

背景

说明指示安装 numpy在 Python 虚拟环境中(下面的日志)。日志显示警告和错误:尽管安装过程指示“成功”,但警告/错误表示不确定。话虽如此:

问题

  1. 与所述错误和警告相关的问题是什么?
  2. 有没有测试可以确认不会出现问题?
  3. 如何改进安装命令以避免相同的错误/警告?

日志

(deep_learning) user@nanite:~$ pip install numpy
WARNING: The directory '/home/user/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
WARNING: The directory '/home/user/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting numpy
  Downloading https://files.pythonhosted.org/packages/d3/4b/f9f4b96c0b1ba43d28a5bdc4b64f0b9d3fbcf31313a51bc766942866a7c7/numpy-1.16.4.zip (5.1MB)
     |████████████████████████████████| 5.1MB 942kB/s 
Building wheels for collected packages: numpy
  WARNING: Building wheel for numpy failed: [Errno 13] Permission denied: '/home/user/.cache/pip/wheels/6b'
Failed to build numpy
Installing collected packages: numpy
  Running setup.py install for numpy ... done
Successfully installed numpy-1.16.4

更新

权限:

(deep_learning) user@nanite:~$ ls -l /home/user/.cache/pip
total 12
drwx------ 5 root root 4096 Jun 28 22:31 http
-rw-r--r-- 1 root root   70 Jun 28 22:19 selfcheck.json
drwxr-xr-x 3 root root 4096 Jun 28 22:08 wheels

(deep_learning) user@nanite:~$ ls -l /home/user/.cache/
total 84
drwx------ 3 user user  4096 Apr 21 07:38 chromium
drwx------ 2 user user  4096 Jun 28 18:02 compizconfig-1
-rw-r--r-- 1 user user 20480 Jun 28 22:16 event-sound-cache.tdb.ebe5a0d15af94384af2e1f235d4e00f0.aarch64-unknown-linux-gnu
drwx------ 8 user user  4096 Apr 21 07:32 evolution
drwxr-xr-x 2 user user  4096 Apr 21 19:24 fontconfig
drwxr-xr-x 7 user user  4096 Apr 22 07:33 gnome-software
drwxr-xr-x 2 user user  4096 Jun 28 19:51 gstreamer-1.0
drwxr-xr-x 3 user user  4096 Apr 21 07:32 ibus
drwxr-xr-x 2 user user  4096 Apr 21 07:32 ibus-table
-rw-r--r-- 1 user user     0 Apr 21 21:47 motd.legal-displayed
drwxr-xr-x 4 root root  4096 Jun 28 22:19 pip
drwx------ 5 user user  4096 Apr 21 19:16 thumbnails
drwxr-xr-x 3 user user  4096 Apr 21 08:30 totem
drwxr-xr-x 2 user user  4096 Apr 22 07:57 unity-lens-photos
drwxr-xr-x 2 user user  4096 Apr 22 07:58 unity-lens-video
drwxr-xr-x 2 user user  4096 Apr 21 07:33 update-manager-core
drwx------ 2 user user  4096 Jun 28 18:03 wallpaper
-rw-r--r-- 1 user user    11 Jun 28 10:40 zeitgeist-vacuum.stamp
(deep_learning) user@nanite:~$

答案1

警告:该目录'/home/user/.cache/pip/http'或其父目录不属于当前用户,并且缓存已被禁用。请检查该目录的权限和所有者。如果使用 sudo 执行 pip,您可能需要 sudo 的 -H 标志。

警告:该目录'/home/user/.cache/pip'或其父目录不属于当前用户,并且缓存轮已被禁用。请检查该目录的权限和所有者。如果使用 sudo 执行 pip,您可能需要 sudo 的 -H 标志。

错误消息相当直接:它/home/user/.cache/pip说不属于当前用户。它告诉你检查该目录的权限和所有者。

您可以使用 来做到这一点ls -l /home/user/.cache/pip

它应该和主目录中的(几乎)所有文件一样,归用户所有。如果它不归用户所有,请使用以下命令更改所有权:

sudo chown -R $USER:$USER /home/user/.cache/pip

这里我们必须使用sudo,因为用户通常无法更改文件的所有权。

答案2

权限被拒绝错误意味着你必须使用sudo在安装语句之前。

sudo pip install numpy

那就可以了。

相关内容