安装python3
参考:https://www.yuzhi100.com/tutorial/centos/centos-anzhuang-python36
CentOS7系统自带的Python版本是Python2.7,如需使用Python3.6,需要自行安装Python3.6。
(1)安装IUS软件源
1 2 3 4
| #安装EPEL依赖 sudo yum install epel-release #安装IUS软件源 sudo yum install https://centos7.iuscommunity.org/ius-release.rpm
|
(2)安装Python3.6
1
| sudo yum install python36u
|
安装Python3完成后的shell命令为python3.6,为了使用方便,创建一个到python3的符号链接
1 2 3
| # rm /bin/python # sudo ln -s /bin/python3.6 /bin/python sudo ln -s /bin/python3.6 /bin/python3
|
(3)安装pip3
安装完成python36u并没有安装pip,安/装pip
1
| sudo yum install python36u-pip
|
安装pip完成后的shell命令为pip3.6,为了使用方便,创建一个到pip3的符号链接
1 2
| sudo ln -s /bin/pip3.6 /bin/pip sudo ln -s /bin/pip3.6 /bin/pip3
|
(4) 遇到的问题
1、使用yum命令报错File “/usr/bin/yum”, line 30 except KeyboardInterrupt, e:
1 2 3 4 5 6 7 8
| [root@10-41-140-1 ~]# yum install zsh File "/usr/bin/yum", line 30 except KeyboardInterrupt, e: ^ SyntaxError: invalid syntax [root@10-41-140-1 ~]# rm /bin/python rm: remove symbolic link ‘/bin/python’? y [root@10-41-140-1 ~]# sudo ln -s /bin/python2.7 /bin/python
|
问题出现原因:
yum包管理是使用python2.x写的,将python2.x升级到python3.1.3以后,由于python版本语法兼容性导致问题出现
解决办法: python软连接到指向python2.7
参考:https://blog.csdn.net/zsl10/article/details/52315319
安装zsh
参考:https://www.jianshu.com/p/556ff130fc65
(1)安装zsh包
(2)切换默认shell为zsh
(3)重启终端,让修改的配置生效
(4)安装oh-my-zsh
4.1 安装git
4.2 通过curl安装
1
| curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh
|
4.2 或者通过wget安装
1
| wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O - | sh
|
4.3 修改oh-my-zsh主题
查看oh my zsh主题
修改主题
可以看到默认的主题是ZSH_THEME=”robbyrussell” 改成自己喜欢的即可.
4.4 重启终端,主题生效
虚拟环境
(1) 安装virtualenv相关依赖
1 2
| sudo pip install virtualenv sudo pip install virtualenvwrapper
|
(2)修改 .zshrc
1 2 3
| ➜ ~ where is virtualenvwrapper.sh is not found /usr/bin/virtualenvwrapper.sh
|
1 2 3 4
| 复制内容,进入.zshrc export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 export WORKON_HOME=$HOME/.virtualenvs source /usr/bin/virtualenvwrapper.sh
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| ➜ ~ vim .zshrc ➜ ~ source .zshrc virtualenvwrapper.user_scripts creating /root/.virtualenvs/premkproject virtualenvwrapper.user_scripts creating /root/.virtualenvs/postmkproject virtualenvwrapper.user_scripts creating /root/.virtualenvs/initialize virtualenvwrapper.user_scripts creating /root/.virtualenvs/premkvirtualenv virtualenvwrapper.user_scripts creating /root/.virtualenvs/postmkvirtualenv virtualenvwrapper.user_scripts creating /root/.virtualenvs/prermvirtualenv virtualenvwrapper.user_scripts creating /root/.virtualenvs/postrmvirtualenv virtualenvwrapper.user_scripts creating /root/.virtualenvs/predeactivate virtualenvwrapper.user_scripts creating /root/.virtualenvs/postdeactivate virtualenvwrapper.user_scripts creating /root/.virtualenvs/preactivate virtualenvwrapper.user_scripts creating /root/.virtualenvs/postactivate virtualenvwrapper.user_scripts creating /root/.virtualenvs/get_env_details ➜ ~
|
(3) 测试是否成功
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| ➜ ~ mkvirtualenv test01 -p python3 # -p 参数指定 python 版本 Using base prefix '/usr' No LICENSE.txt / LICENSE found in source New python executable in /root/.virtualenvs/test01/bin/python3.6 Also creating executable in /root/.virtualenvs/test01/bin/python Installing setuptools, pip, wheel... done. virtualenvwrapper.user_scripts creating /root/.virtualenvs/test01/bin/predeactivate virtualenvwrapper.user_scripts creating /root/.virtualenvs/test01/bin/postdeactivate virtualenvwrapper.user_scripts creating /root/.virtualenvs/test01/bin/preactivate virtualenvwrapper.user_scripts creating /root/.virtualenvs/test01/bin/postactivate virtualenvwrapper.user_scripts creating /root/.virtualenvs/test01/bin/get_env_details (test01) ➜ ~ (test01) ➜ ~ deactivate ➜ ~ workon test01 (test01) ➜ ~
|
(4)确定下虚拟环境内,python的路径,为在supervisor配置文件里使用
1 2 3 4 5
| (test01) ➜ ~ where is python is not found /root/.virtualenvs/test01/bin/python /usr/bin/python (test01) ➜ ~
|