最近按着看到python教程学着安装python3.6,因为宝塔是默认python2.7的,升级过程也比较麻烦,看了好几个大佬的博客才安装好,最后是用了python一键安装脚本。
wget https://www.moerats.com/usr/shell/Python3/CentOS_Python3.6.sh && sh CentOS_Python3.6.sh
但是意外又出现了,宝塔后台打不开了,搜索一大堆教程就目前这篇比较适合我,在linux输入对应指令,宝塔面板就能正常打开了。

===================================================================
原理是因为Python2 和Python3 不兼容,而塔宝是使用Python2写的,导致升级Python3 之后面板无法启动了。
安装Python 3.7
1
| wget <span class="hljs-symbol">https:</span>/<span class="hljs-regexp">/www.python.org/ftp</span><span class="hljs-regexp">/python/</span><span class="hljs-number">3.7</span>.<span class="hljs-number">0</span>/Python-<span class="hljs-number">3.7</span>.<span class="hljs-number">0</span>.tgz |
下载完成后到下载目录下,解压
1
| <span class="hljs-selector-tag">tar</span> <span class="hljs-selector-tag">-zxvf</span> <span class="hljs-selector-tag">Python-3</span><span class="hljs-selector-class">.7</span><span class="hljs-selector-class">.0</span><span class="hljs-selector-class">.tgz</span> |
进入解压缩后的文件夹
1
| <span class="hljs-selector-tag">cd</span> <span class="hljs-selector-tag">Python-3</span><span class="hljs-selector-class">.7</span><span class="hljs-selector-class">.0</span> |
在编译前先在/usr/local建一个文件夹python3.7.0(作为python的安装路径,以免覆盖老的版本)
1
| <span class="hljs-keyword">mkdir</span> /usr/<span class="hljs-keyword">local</span>/python3.<span class="hljs-number">7.0</span> |
在解压缩后的目录下编译(make)安装(make install)
1 2 3
| ./configure --prefix=<span class="hljs-regexp">/usr/</span>local/python3<span class="hljs-number">.7</span><span class="hljs-number">.0</span> --<span class="hljs-keyword">with</span>-ssl
make
make install |
这个时候好多人会用软链更更换Python版本,如果更换之后就其实宝塔面板还是正常运行的,但是当你重启服务器之后就gg了,如果你尝试重启面板会出现一下提示
1 2 3 4 5 6 7 8 9 10 11 12
| [root@localhost ~]<span class="hljs-comment"># service bt restart</span>
Stopping Bt-Tasks... <span class="hljs-keyword">done</span>
Stopping Bt-Panel... <span class="hljs-keyword">done</span>
Starting Bt-Panel... File <span class="hljs-string">"main.py"</span>, line 32
except Exception,ex:
^
SyntaxError: invalid syntax
failed
------------------------------------------------------
RuntimeError: Bad magic number <span class="hljs-keyword">in</span> .pyc file
------------------------------------------------------ |
所以我们需要移除软链还原原来的Python版本
1 2
| <span class="hljs-attribute">rm</span> -rf /usr/bin/python
ln -s /usr/bin/python2.<span class="hljs-number">7</span> /usr/bin/python |
这时候重启一下面板会看到
1 2 3 4 5
| [root@localhost ~]<span class="hljs-comment"># service bt restart</span>
Stopping Bt-Tasks... <span class="hljs-keyword">done</span>
Stopping Bt-Panel... <span class="hljs-keyword">done</span>
Starting Bt-Panel... <span class="hljs-keyword">done</span>
Starting Bt-Tasks... <span class="hljs-keyword">done</span> |
大家会说那怎么使用python3开发,命令行执行py文件之后使用python3命令即可
1
| <span class="hljs-attribute">python3</span> xxxx.py |
原文传送门->https://my.oschina.net/bileel/blog/2222172