使用pip安装Tensorflow时权限被拒绝

时间:2018-03-07 12:11:55

标签: python python-2.7 tensorflow pip

当我尝试使用pip install tensorflow安装Tensorflow时,我遇到了以下异常:

Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_set.py", line 784, in install
    **kwargs
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/wheel.py", line 345, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/wheel.py", line 323, in clobber
    shutil.copyfile(srcfile, destfile)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 83, in copyfile
    with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/protobuf-3.5.2-py2.7-nspkg.pth'

这是什么意思?如何安装tensorflow包?

当我使用:sudo pip install tensorflow时,我现在得到了这个例外:

Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_set.py", line 778, in install
    requirement.uninstall(auto_confirm=True)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 754, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_uninstall.py", line 115, in remove
    renames(path, new_path)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/utils/__init__.py", line 267, in renames
    shutil.move(old, new)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
    copy2(src, real_dst)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
    copystat(src, dst)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat
    os.chflags(dst, st.st_flags)
OSError: [Errno 1] Operation not permitted: '/var/folders/n6/bfff99yn3nnc46h_gh5tc7fm0000gn/T/pip-TI9hQ_-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'

而不是说否认它说操作不允许

4 个答案:

答案 0 :(得分:3)

您的用户看起来没有权限在您的系统中安装软件包(适用于所有用户)。以下是如何解决Linux,macOS和Windows的这个问题:

Linux / macOS

在您的终端中,您可以仅为您的用户安装该软件包,如下所示:

pip install <package> --user

<强> OR

您可以使用终端中的susudoroot 安装软件包:

sudo pip install <package>

在命令提示符下,您可以仅为您的用户安装软件包,如下所示:

pip install <package> --user

<强> OR

您可以按照以下步骤以管理员身份安装软件包

  1. 使用Run This Program As An Administrator选项以管理员身份运行命令提示符。
  2. 运行命令pip install <package>

答案 1 :(得分:2)

你应该运行它 sudo pip

答案 2 :(得分:2)

这显然是权限问题。

如果您使用的是Ubuntu或Liux OS,请尝试使用:

sudo pip install tensorflow

如果您使用的是Windows:

以管理员身份运行命令提示符并运行pip install tensorflow

为了更好地摆脱此类问题,请使用Anaconda

答案 3 :(得分:0)

您需要使用管理员权限进行安装。这可以使用sudo命令完成。

我建议同时指定Python解释器以及使用pip来阻止pip应安装到的地方的混淆。默认情况下,有两个版本加上您自己安装的版本。

要在2.7上安装,您可以使用:

sudo python -m pip install tensorflow

要在3.6上安装,您可以使用:

sudo python36 -m pip install tensorflow

对于3.5你可以使用它:

sudo python3 -m pip install tensorflow

要说明每个Python的版本,您可以使用which python