PYTHON设置默认清华源

2024-06-15 23:48
文章标签 python 设置 默认 清华

本文主要是介绍PYTHON设置默认清华源,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

首先打开windows的运行窗口输入 %appdata% ,或者打开目“C:\Users\Administrator\AppData\Roaming”

在这里插入图片描述

在新弹出的窗口新建一个pip的文件夹,进入文件夹后,创建一个pip.ini的文件,在文件中写入如下内容:

[global]timeout = 6000index-url = https://pypi.tuna.tsinghua.edu.cn/simpletrusted-host = pypi.tuna.tsinghua.edu.cn

文件内容保存好后,使用pip安装第三方库即可从清华源下载。

在这里插入图片描述

问题一:python安装django报错

[C:\~]$ pip install django
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
ERROR: Exception:
Traceback (most recent call last):File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\cli\base_command.py", line 173, in _mainstatus = self.run(options, args)File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\cli\req_command.py", line 203, in wrapperreturn func(self, options, args)File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\commands\install.py", line 315, in runrequirement_set = resolver.resolve(File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\resolution\resolvelib\resolver.py", line 94, in resolveresult = self._result = resolver.resolve(File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 472, in resolvestate = resolution.resolve(requirements, max_rounds=max_rounds)File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 341, in resolveself._add_to_criteria(self.state.criteria, r, parent=None)File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 172, in _add_to_criteriaif not criterion.candidates:File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\resolvelib\structs.py", line 151, in __bool__return bool(self._sequence)File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 140, in __bool__return any(self)File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 128, in <genexpr>return (c for c in iterator if id(c) not in self._incompatible_ids)File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 29, in _iter_builtfor version, func in infos:File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\resolution\resolvelib\factory.py", line 272, in iter_index_candidate_infosresult = self._finder.find_best_candidate(File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\index\package_finder.py", line 851, in find_best_candidatecandidates = self.find_all_candidates(project_name)File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\index\package_finder.py", line 798, in find_all_candidatespage_candidates = list(page_candidates_it)File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\index\sources.py", line 134, in page_candidatesyield from self._candidates_from_page(self._link)File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\index\package_finder.py", line 758, in process_project_urlhtml_page = self._link_collector.fetch_page(project_url)File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\index\collector.py", line 490, in fetch_pagereturn _get_html_page(location, session=self.session)File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\index\collector.py", line 400, in _get_html_pageresp = _get_html_response(url, session=session)File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\index\collector.py", line 115, in _get_html_responseresp = session.get(File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\requests\sessions.py", line 555, in getreturn self.request('GET', url, **kwargs)File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_internal\network\session.py", line 454, in requestreturn super().request(method, url, *args, **kwargs)File "C:\Users\Admin剋istrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\requests\sessions.py", line 542, in requestresp = self.send(prep, **send_kwargs)File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\requests\sessions.py", line 655, in sendr = adapter.send(request, **kwargs)File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\cachecontrol\adapter.py", line 53, in sendresp = super(CacheControlAdapter, self).send(request, **kw)File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\requests\adapters.py", line 439, in sendresp = conn.urlopen(File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\urllib3\connectionpool.py", line 696, in urlopenself._prepare_proxy(conn)File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\urllib3\connectionpool.py", line 964, in _prepare_proxyconn.connect()File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\urllib3\connection.py", line 359, in connectconn = self._connect_tls_proxy(hostname, conn)File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\urllib3\connection.py", line 500, in _connect_tls_proxyreturn ssl_wrap_socket(File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\urllib3\util\ssl_.py", line 453, in ssl_wrap_socketssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls)File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\pip\_vendor\urllib3\util\ssl_.py", line 495, in _ssl_wrap_socket_implreturn ssl_context.wrap_socket(sock)File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 500, in wrap_socketreturn self.sslsocket_class._create(File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 997, in _createraise ValueError("check_hostname requires server_hostname")
ValueError: check_hostname requires server_hostname

可以看到最后一行报错:ValueError: check_hostname requires server_hostname

解决办法:查看电脑是否有代理的存在,如果有代理需要关闭代理。

问题二:pip安装第三方库报错

[root@localhost ~]# python -m pip install ipython
/usr/local/bin/python: No module named pip

解决办法如下:
python3可以使用这个脚本,https://bootstrap.pypa.io/get-pip.py

python2可以使用如下脚本

# python2解决办法
[root@localhost ~]# wget https://bootstrap.pypa.io/pip/2.7/get-pip.py[root@localhost ~]# python get-pip.py 
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting pip<21.0Downloading pip-20.3.4-py2.py3-none-any.whl (1.5 MB)|████████████████████████████████| 1.5 MB 93 kB/s 
Collecting wheelDownloading wheel-0.37.1-py2.py3-none-any.whl (35 kB)
Installing collected packages: pip, wheel
Successfully installed pip-20.3.4 wheel-0.37.1[root@localhost ~]# pip -V
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
pip 20.3.4 from /usr/lib/python2.7/site-packages/pip (python 2.7)

这篇关于PYTHON设置默认清华源的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1064928

相关文章

Python将博客内容html导出为Markdown格式

《Python将博客内容html导出为Markdown格式》Python将博客内容html导出为Markdown格式,通过博客url地址抓取文章,分析并提取出文章标题和内容,将内容构建成html,再转... 目录一、为什么要搞?二、准备如何搞?三、说搞咱就搞!抓取文章提取内容构建html转存markdown

Python获取中国节假日数据记录入JSON文件

《Python获取中国节假日数据记录入JSON文件》项目系统内置的日历应用为了提升用户体验,特别设置了在调休日期显示“休”的UI图标功能,那么问题是这些调休数据从哪里来呢?我尝试一种更为智能的方法:P... 目录节假日数据获取存入jsON文件节假日数据读取封装完整代码项目系统内置的日历应用为了提升用户体验,

Python FastAPI+Celery+RabbitMQ实现分布式图片水印处理系统

《PythonFastAPI+Celery+RabbitMQ实现分布式图片水印处理系统》这篇文章主要为大家详细介绍了PythonFastAPI如何结合Celery以及RabbitMQ实现简单的分布式... 实现思路FastAPI 服务器Celery 任务队列RabbitMQ 作为消息代理定时任务处理完整

Python Websockets库的使用指南

《PythonWebsockets库的使用指南》pythonwebsockets库是一个用于创建WebSocket服务器和客户端的Python库,它提供了一种简单的方式来实现实时通信,支持异步和同步... 目录一、WebSocket 简介二、python 的 websockets 库安装三、完整代码示例1.

揭秘Python Socket网络编程的7种硬核用法

《揭秘PythonSocket网络编程的7种硬核用法》Socket不仅能做聊天室,还能干一大堆硬核操作,这篇文章就带大家看看Python网络编程的7种超实用玩法,感兴趣的小伙伴可以跟随小编一起... 目录1.端口扫描器:探测开放端口2.简易 HTTP 服务器:10 秒搭个网页3.局域网游戏:多人联机对战4.

使用Python实现快速搭建本地HTTP服务器

《使用Python实现快速搭建本地HTTP服务器》:本文主要介绍如何使用Python快速搭建本地HTTP服务器,轻松实现一键HTTP文件共享,同时结合二维码技术,让访问更简单,感兴趣的小伙伴可以了... 目录1. 概述2. 快速搭建 HTTP 文件共享服务2.1 核心思路2.2 代码实现2.3 代码解读3.

Python使用自带的base64库进行base64编码和解码

《Python使用自带的base64库进行base64编码和解码》在Python中,处理数据的编码和解码是数据传输和存储中非常普遍的需求,其中,Base64是一种常用的编码方案,本文我将详细介绍如何使... 目录引言使用python的base64库进行编码和解码编码函数解码函数Base64编码的应用场景注意

Python基于wxPython和FFmpeg开发一个视频标签工具

《Python基于wxPython和FFmpeg开发一个视频标签工具》在当今数字媒体时代,视频内容的管理和标记变得越来越重要,无论是研究人员需要对实验视频进行时间点标记,还是个人用户希望对家庭视频进行... 目录引言1. 应用概述2. 技术栈分析2.1 核心库和模块2.2 wxpython作为GUI选择的优

Python如何使用__slots__实现节省内存和性能优化

《Python如何使用__slots__实现节省内存和性能优化》你有想过,一个小小的__slots__能让你的Python类内存消耗直接减半吗,没错,今天咱们要聊的就是这个让人眼前一亮的技巧,感兴趣的... 目录背景:内存吃得满满的类__slots__:你的内存管理小助手举个大概的例子:看看效果如何?1.

Python+PyQt5实现多屏幕协同播放功能

《Python+PyQt5实现多屏幕协同播放功能》在现代会议展示、数字广告、展览展示等场景中,多屏幕协同播放已成为刚需,下面我们就来看看如何利用Python和PyQt5开发一套功能强大的跨屏播控系统吧... 目录一、项目概述:突破传统播放限制二、核心技术解析2.1 多屏管理机制2.2 播放引擎设计2.3 专