当我尝试使用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'
而不是说否认它说操作不允许
答案 0 :(得分:3)
您的用户看起来没有权限在您的系统中安装软件包(适用于所有用户)。以下是如何解决Linux,macOS和Windows的这个问题:
在您的终端中,您可以仅为您的用户安装该软件包,如下所示:
pip install <package> --user
<强> OR 强>
您可以使用终端中的su
或sudo
来以root
安装软件包:
sudo pip install <package>
在命令提示符下,您可以仅为您的用户安装软件包,如下所示:
pip install <package> --user
<强> OR 强>
您可以按照以下步骤以管理员身份安装软件包:
Run This Program As An Administrator
选项以管理员身份运行命令提示符。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