该方法可用于pip install 库的拒绝访问问题
参考资料:https://www.cnblogs.com/liaojiafa/p/5100550.html
C:\Program Files\Python35\Scripts>pip install requests
Collecting requests
Using cached requests-2.18.4-py2.py3-none-any.whl
Collecting certifi>=2017.4.17 (from requests)
Using cached certifi-2017.11.5-py2.py3-none-any.whl
Collecting chardet<3.1.0,>=3.0.2 (from requests)
Using cached chardet-3.0.4-py2.py3-none-any.whl
Collecting urllib3<1.23,>=1.21.1 (from requests)
Using cached urllib3-1.22-py2.py3-none-any.whl
Collecting idna<2.7,>=2.5 (from requests)
Using cached idna-2.6-py2.py3-none-any.whl
Installing collected packages: certifi, chardet, urllib3, idna, requests
Exception:
Traceback (most recent call last):
File "c:\program files\python35\lib\site-packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "c:\program files\python35\lib\site-packages\pip\commands\install.py", line 342, in run
prefix=options.prefix_path,
File "c:\program files\python35\lib\site-packages\pip\req\req_set.py", line 784, in install
**kwargs
File "c:\program files\python35\lib\site-packages\pip\req\req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "c:\program files\python35\lib\site-packages\pip\req\req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "c:\program files\python35\lib\site-packages\pip\wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "c:\program files\python35\lib\site-packages\pip\wheel.py", line 316, in clobber
ensure_dir(destdir)
File "c:\program files\python35\lib\site-packages\pip\utils\__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "c:\program files\python35\lib\os.py", line 241, in makedirs
mkdir(name, mode)
PermissionError: [WinError 5] 拒绝访问。: 'c:\\program files\\python35\\Lib\\site-packages\\certifi'
以上Exception:后为报错内容,很明显是权限问题 PermissionError
我电脑上的python35路径 C:\Program Files\Python35\Scripts
进入Program Files文件夹,找到Python35文件夹,右键点击属性
进入安全一栏中:
点击当前登录的用户Users,点击“编辑”
会看到Users的权限框里有很多没有优选的空白小框,为了方便起见,把所有的空白小框全部打上勾。
点击“应用”——》“确定”
然后就会发现import requests不会出错了:
^^