You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

OpenSUSE系统下Python3.6下载及多版本切换问题咨询

解决OpenSUSE上Python3.6安装与版本切换问题

Hey there! Let's work through your Python 3.6 installation and version switching issues on openSUSE step by step. First, let's clear up a couple of missteps from your earlier attempts:

  • openSUSE uses zypper as its default package manager, not yum—that's why your yum command failed.
  • The URL you added in YaST was a direct link to a Python source tarball, not a valid software repository. YaST needs a proper RPM repo source to pull packages from, hence the prompt to change the URL.

一、Python3.6的安装目录选择

方式1:通过官方仓库安装(推荐)

You can get Python 3.6 via openSUSE's official Python development repository. Packages installed this way will go into standard system directories, which avoids messing with system dependencies:

  • 可执行文件:/usr/bin/python3.6
  • 库文件:/usr/lib64/python3.6(64位系统)或/usr/lib/python3.6(32位系统)

操作步骤:

  1. 打开终端,添加官方Python开发仓库:
sudo zypper addrepo devel:languages:python
  1. 刷新仓库列表并安装Python 3.6:
sudo zypper refresh
sudo zypper install python36

方式2:源码编译安装

If you prefer to compile from source, it's best to install Python 3.6 into the /usr/local directory (the standard spot for custom-installed software) to avoid overwriting system Python files. For example:

  • 配置源码时指定--prefix=/usr/local/python36,这样文件会被放在:
    • 可执行文件:/usr/local/python36/bin/python3.6
    • 库文件:/usr/local/python36/lib/python3.6

绝对不要把自定义Python版本直接安装到/usr/bin——这会破坏依赖系统预装Python 2.7.5或3.3的系统工具。

二、切换到Python3.6的方法

方法1:使用update-alternatives(最稳妥)

这个工具可以帮你管理多个Python版本,同时不破坏系统默认配置:

  1. 将Python3.6添加到备选版本列表:
# 仓库安装的Python3.6
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1

# 源码编译的Python3.6
sudo update-alternatives --install /usr/bin/python3 python3 /usr/local/python36/bin/python3.6 1
  1. 切换默认的python3版本为3.6:
sudo update-alternatives --config python3

根据屏幕提示输入对应Python3.6的编号即可完成切换。

方法2:临时切换(仅当前终端会话有效)

如果只是单次会话需要使用Python3.6,直接调用它的可执行文件即可:

python3.6

或者临时调整PATH环境变量:

# 针对源码编译的Python3.6
export PATH=/usr/local/python36/bin:$PATH

方法3:永久切换(用户级生效)

编辑你的shell配置文件(比如~/.bashrc~/.zshrc,取决于你使用的shell),添加别名:

# 仓库安装的Python3.6
alias python3='/usr/bin/python3.6'

# 源码编译的Python3.6
alias python3='/usr/local/python36/bin/python3.6'

保存文件后,执行source ~/.bashrc(或对应配置文件路径)立即生效。之后打开新终端时,python3就会指向3.6版本。

三、满足Anaconda安装需求

快速说明:Anaconda自带独立的Python环境,所以它其实不严格依赖系统的Python版本。但如果你需要系统Python3.6可用,只要通过上面的方法确保python3指向3.6即可。

另外,安装Anaconda后,你也可以创建一个专门的Python3.6虚拟环境:

conda create -n py36_env python=3.6
conda activate py36_env

这样就能获得一个干净的、专用于项目的Python3.6环境。


内容的提问来源于stack exchange,提问作者Rhea

火山引擎 最新活动