[other] deepin20.9安装python3.12请帮忙审视步骤是否正确 Resolved
Tofloor
poster avatar
pho
deepin
2023-12-09 21:52
Author

1.cd Python-3.12.0

2.sudo ./configure prefix=/usr/local/python3.12 --with-openssl=/usr --enable-optimizations

3.make -j$(nproc)
提示:The necessary bits to build these optional modules were not found:
_dbm
To find the necessary bits, look in configure.ac and config.log.

Checked 111 modules (31 built-in, 78 shared, 1 n/a on linux-x86_64, 0 disabled, 1 missing, 0 failed on import)
make[1]: 离开目录“/home/pho/Downloads/Python-3.12.0”

4.sudo make

5.sudo make install
提示:Installing collected packages: pip
WARNING: The scripts pip3 and pip3.12 are installed in '/usr/local/python3.12/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-23.2.1
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

6.sudo ln -s /usr/local/python3.12/bin/python3.12 /usr/bin/python3
提示:ln: 无法创建符号链接'/usr/bin/python3': 文件已存在

7.sudo rm -rf /usr/bin/python3

8.sudo ln -s /usr/local/python3.12/bin/python3.12 /usr/bin/python3

9.ln -s /usr/local/python3.12/bin/pip3.12 /usr/bin/pip3
提示:无法创建符号链接'/usr/bin/pip3': 文件已存在

10.sudo rm -rf /usr/bin/pip3

11.sudo ln -s /usr/local/python3.12/bin/pip3.12 /usr/bin/pip3

12.vi ~/.bash_profile

按照网上的说法,将以下两行加入进入:

export PYTHON_HOME=/root/training/Python-3.12.0

export PATH=PYTHON_HOME/bin:PATH

就是这样:
截图_选择区域_20231209135639.png

退出后在终端输入:source~/.bash_profile。

提示:bash: source~/.bash_profile: 没有那个文件或目录。

又按照网上的说法,进行第13步。

13.sudo vi ~/.bashrc

在最下方加入:

export PATH="/path/to/python3.12/bin:$PATH

如下图:

截图_选择区域_20231209135925.png

保存退出。

14.source ~/.bashrc

15.输入python:默认的还是python2.6.7

最后我是这样做的:

截图_选择区域_20231209135027.png

————————————————

然后我在终端输入python,就是如下结果了:

截图_选择区域_20231209135516.png

Reply Favorite View the author
All Replies
忘记、过去
deepin
2023-12-09 22:05
#1

doubt 恭喜你,这下很可能系统里要用到默认的 python 2.7 和 3.7 的应用都跑不起来了......尤其是你直接替换了 /usr/bin 里面 python3 和 pip3 的软链接


要用 python 高版本为啥不上 miniconda 呢......

Reply View the author
pho
deepin
2023-12-09 22:07
#2
忘记、过去

doubt 恭喜你,这下很可能系统里要用到默认的 python 2.7 和 3.7 的应用都跑不起来了......尤其是你直接替换了 /usr/bin 里面 python3 和 pip3 的软链接


要用 python 高版本为啥不上 miniconda 呢......

如果不用虚拟环境,怎么解决?

Reply View the author
忘记、过去
deepin
2023-12-09 22:14
#3
pho

如果不用虚拟环境,怎么解决?

把你替换的软链接还原回去,只修改环境变量的话可能影响小一点吧......

Reply View the author
pho
deepin
2023-12-09 22:23
#4
It has been deleted!
pho
deepin
2023-12-09 22:32
#5
忘记、过去

把你替换的软链接还原回去,只修改环境变量的话可能影响小一点吧......

后果可能已经出现了,刚开始插U盘不识别,不过,我重启后能识别U盘。

Reply View the author
neko
deepin
Ecological co-builder
2023-12-10 02:47
#6
pho

如果不用虚拟环境,怎么解决?

添加PATH环境变量到/usr/bin的前面提高优先级,不必删除系统的pip和python

Reply View the author
pho
deepin
2023-12-11 04:14
#7

谢谢楼上几位,我又摸索了一段时间,这次搞得差不多了。参考了《安装python3.12踩坑笔记》https://bbs.deepin.org/post/263079,以及查阅WIKI,CSDN及观看B站视频,终于搞定。

Reply View the author