使用conda更新python版本

目录


一、更新原因

        原因是本来使用的是具有python3.6.3版本的conda环境,但是因为python内存堆栈溢出的bug问题。现在需要将Python的版本更新到3.8.8或3.9.2及以上。在更新的过程还是有几个细节需要注意下,这边做个记录。

        方法有两种,一种是conda install命令更新,另一种是直接下载sh更新。前者比较繁琐且容易出错。第二种相对简单很多。

        第二种方式

        第二种方式简单,这边简单讲一下。下载sh后直接拷贝到对应linux目录后安装,具体可参考这篇文章:linux安装anaconda3环境-CSDN博客 。sh下载地址是:Index of / ,其中部分的anaconda对应的python列表如下(都是一个一个安装后 python -V 试出来的):

Anaconda3-2020.07-Linux-x86_64.shpython3.8.3
Anaconda3-2020.11-Linux-x86_64.shpython3.8.5
Anaconda3-2021.04-Linux-x86_64.shpython3.8.8
Anaconda3-2021.11-Linux-x86_64.shpython3.9.7

二、步骤(第一种方式)

        2.1、添加conda下载镜像

        这个是为了让你在下载的时候使用国内镜像源地址下载,有效提高下载速度。

# 将下面内容添加到 ~/.condarc
channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - defaults
show_channel_urls: true
default_channels:
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
custom_channels:
  conda-forge: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
ssl_verify: false

        2.3、更新conda版本

        如果conda的版本跟python的版本不兼容了。具体体现于下面的报错:

[root@finance205 home]# conda -V
Traceback (most recent call last):
  File "/root/anaconda3/bin/conda", line 7, in <module>
    from conda.cli import main
ModuleNotFoundError: No module named 'conda'

        我们只需升级下conda版本即可,升级命令如下:

conda update conda

        2.2、conda更新python

conda install python=3.8.8

三、验证

        如果升级的python版本跨度太大,则要注意一些语法或函数参数在搞版本里是否有弃用更改等情况。如果在conda install python 不指定python=多少版本,那么会默认给你安装最新的。

        上面操作完成后,可以验证下我们的conda及python安装情况:

# 查看conda版本
conda -V

# 查看python版本
python -V

四、离线安装

        如果是离线的话,使用第二种方式方便一些。得注意需要同步离线安装bzip2包。

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
xiaoxingxing的头像xiaoxingxing管理团队
上一篇 2023年4月29日
下一篇 2023年4月29日

相关推荐