本文主要是介绍[TroubleShooting]CentOS8使用pyenv部署多版本python时报 python: command not found,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
pyenv部署python报错的troubleshooting
pyenv: python :command not found
- 在CentOS8中成功部署pyenv后,安装多版本python也成功。
- 但是当在项目文件夹中设定python版本,创建虚拟python时始终不成功
- 始终报错
-bash: python: command not found
[python@C8-196 ~]$ cd projects/web36
[python@C8-196 web36]$ pyenv local
3.6.15
[python@C8-196 web36]$ pyenv versionssystem3.10.0
* 3.6.15 (set by /home/python/projects/web36/.python-version)3.6.15/envs/py36153.8.12py3615
[python@C8-196 web36]$ python -V
-bash: python: command not found
[python@C8-196 web36]$ python3 -V
Python 3.6.8
[python@C8-196 web36]$ python3.6 -V
Python 3.6.8
重新部署
- 初始化虚拟机,重新一步一步部署,问题依然重现
检查pyenv install python是否成功
- 进入安装目录查看,并执行程序,证明程序安装的没问
[python@C8-196 web36]$ ~/.pyenv/versions/3.6.15/bin/python -V
Python 3.6.15
思考问题原因
- 根据以往经验,command not found如果不是程序没装好,那就肯定是环境变量除了问题
- 之前在CentOS 7配置的环境变量方法
vim ~/.bashrcexport PATH="/home/python/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"source ~/.bashrc
解决问题
-
既然在配置环境变量上出了问题,就要去官网查看详细的文档说明
-
官网在帮助中写的清清楚楚明明白白,那就按照官网上面来
[python@C8-196 ~]$ sed -Ei -e '/^([^#]|$)/ {a \
> export PYENV_ROOT="$HOME/.pyenv"
> a \
> export PATH="$PYENV_ROOT/bin:$PATH"
> a \
> ' -e ':a' -e '$!{n;ba};}' ~/.bash_profile
[python@C8-196 ~]$ echo 'eval "$(pyenv init --path)"' >> ~/.bash_profile
[python@C8-196 ~]$
[python@C8-196 ~]$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile
[python@C8-196 ~]$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile
[python@C8-196 ~]$ echo 'eval "$(pyenv init --path)"' >> ~/.profile
[python@C8-196 ~]$
[python@C8-196 ~]$ echo 'eval "$(pyenv init -)"' >> ~/.bashrc
[python@C8-196 ~]$ source ~/.bashrc
- 真是立竿见影,药到病除
[root@C8-196 ~]# su - python
Last login: Thu Dec 9 19:26:13 CST 2021 on pts/0
[python@C8-196 ~]$ cd projects/web36
[python@C8-196 web36]$ pyenv versionssystem3.10.0
* 3.6.15 (set by /home/python/projects/web36/.python-version)3.6.15/envs/py36153.6.15/envs/venv3.8.12py3615venv
[python@C8-196 web36]$ python -V
Python 3.6.15
[python@C8-196 web36]$ pip -V
pip 18.1 from /home/python/.pyenv/versions/3.6.15/lib/python3.6/site-packages/pip (python 3.6)
总结
- 出了问题,尽量去官网招解决方案,网上的不一定靠谱
这篇关于[TroubleShooting]CentOS8使用pyenv部署多版本python时报 python: command not found的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!