安装python相信对学习python的朋友们来说肯定是小菜一碟。但是对于完全重装python时怎么把一大堆包快速安装好,很多朋友还是挺犯怵的,哇塞,pip list一屏都显示不完,怎么搞啊?
不要慌,跟着我一步步来搞定。
保存python包列表
pip list >list.txt
在cmd命令提示符输入以上命令,作用是将python所有的安装包列表输出到list.txt文件中。
![3a76236d5d1eec153def1f3cf9323ba7.png](https://i-blog.csdnimg.cn/blog_migrate/65e657bab3e0d4b02ff28ec9a73f67ca.jpeg)
重装以前一定要保存安装包列表。
处理list.txt文件
用notepad++打开刚刚的list.txt文件,去掉开头2行无用的信息,再转码成utf8,保存文件。
再写几行python脚本,代码如下:
import osos.chdir("D:/我的文档") # 注意刚刚的list.txt所在路径,要保存到这里with open("list.txt", mode='r', encoding='utf8') as f1: with open("list2.txt", mode='w', encoding='utf8') as f2: for i in f1: line = i.split() f2.write(line[0] + ' ')
运行脚本,检查list2.txt内容,看看是不是符合要求。
我的list2.txt文件内容如下:
altgraph argon2-cffi asgiref async-generator attrs backcall bleach cffi colorama Cython decorator defusedxml Django entrypoints future ipykernel ipython ipython-genutils ipywidgets jedi Jinja2 jsonschema jupyter jupyter-client jupyter-console jupyter-core jupyterlab-pygments llvmlite MarkupSafe mistune nbclient nbconvert nbformat nest-asyncio notebook numba numpy packaging pandas pandocfilters parso pefile pickleshare pip pkuseg prometheus-client prompt-toolkit pycparser pygame Pygments pyinstaller pyinstaller-hooks-contrib pyparsing PyQt5 PyQt5-sip pyrsistent python-dateutil pytz pywin32 pywin32-ctypes pywinpty pyzmq qtconsole QtPy Send2Trash setuptools six sqlparse terminado testpath tornado traitlets wcwidth webencodings wheel widgetsnbextension
这么一大堆如果一行行手工装得忙活好一会时间呢!
![1a32dde53a1e3469a33d98e45bedbf2b.png](https://i-blog.csdnimg.cn/blog_migrate/0c066a3a5cee04f4705418c07a437ba3.jpeg)
将安装包列表文件加工成一行。
配置国内源
安装python首先要配置国内源,首先进入自己电脑的用户目录,我的是“C:甥敳獲40859”,在该目录下创建pip目录,然后创建pip.ini文件(可以新建文本文件,然后改文件名)。
文件内容如下:
[global]index-url = https://mirrors.aliyun.com/pypi/simple/[install]trusted-host=mirrors.aliyun.com
重装系统或python
这一步自己完成,这里不再赘述。
重装python环境
系统和python重装完成后,现在需要安装python环境。注意:安装python最后有提示去除单行命令字符数量限制,一定要勾选。
- 更新pip,命令如下:
python -m pip install --upgrade pip
- 更新setuptools,命令如下:
pip install --upgrade setuptools
- 急速安装python环境
pip install altgraph argon2-cffi asgiref async-generator attrs backcall bleach cffi colorama Cython decorator defusedxml Django entrypoints future ipykernel ipython ipython-genutils ipywidgets jedi Jinja2 jsonschema jupyter jupyter-client jupyter-console jupyter-core jupyterlab-pygments llvmlite MarkupSafe mistune nbclient nbconvert nbformat nest-asyncio notebook numba numpy packaging pandas pandocfilters parso pefile pickleshare pip pkuseg prometheus-client prompt-toolkit pycparser pygame Pygments pyinstaller pyinstaller-hooks-contrib pyparsing PyQt5 PyQt5-sip pyrsistent python-dateutil pytz pywin32 pywin32-ctypes pywinpty pyzmq qtconsole QtPy Send2Trash setuptools six sqlparse terminado testpath tornado traitlets wcwidth webencodings wheel widgetsnbextension
注意:pip install后面加个空格,再后面的内容是从list2.txt中全部复制粘贴过来的。
![c3120eba73db8b3a7088d268ef91418f.png](https://i-blog.csdnimg.cn/blog_migrate/46f3ccdb7da7bdbeaefdd12b3ec34b82.jpeg)
急速重装python环境!