idle怎么运行空格行_想重装python但有很多包怎么办?不要慌,教你如何快速重装

本文介绍了如何在重装Python环境时快速处理并安装大量的Python包。首先,通过命令将已安装的包列表保存到文本文件,然后使用Python脚本处理这个文件,生成用于安装的一行命令。接着,配置国内源以提高下载速度,并在Python环境安装完成后,使用处理后的包列表一键安装所有依赖。这种方法大大节省了手动安装的时间。
摘要由CSDN通过智能技术生成

安装python相信对学习python的朋友们来说肯定是小菜一碟。但是对于完全重装python时怎么把一大堆包快速安装好,很多朋友还是挺犯怵的,哇塞,pip list一屏都显示不完,怎么搞啊?

不要慌,跟着我一步步来搞定。

保存python包列表

pip list >list.txt

在cmd命令提示符输入以上命令,作用是将python所有的安装包列表输出到list.txt文件中。

3a76236d5d1eec153def1f3cf9323ba7.png

重装以前一定要保存安装包列表。

处理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

将安装包列表文件加工成一行。

配置国内源

安装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最后有提示去除单行命令字符数量限制,一定要勾选。

  1. 更新pip,命令如下:
python -m pip install --upgrade pip
  1. 更新setuptools,命令如下:
pip install --upgrade setuptools
  1. 急速安装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

急速重装python环境!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值