python – ImportError:没有名为’yaml’的模块
作者:互联网
我有一个脚本,我正在尝试执行
python3 env/common_config/add_imagepullsecret.py
但是,我收到以下错误:
[root@kevin]# python3 env/common_config/add_imagepullsecret.py
Traceback (most recent call last):
File "env/common_config/add_imagepullsecret.py", line 4, in <module>
import yaml
ImportError: No module named 'yaml'
[root@kevin]# pip3 install pyyaml
Requirement already satisfied: pyyaml in /usr/lib64/python3.4/site-packages
(3.12)
[root@kevin]#
PyYAML已安装在机器中:
[root@bhimsvm31 k8s]# pip3 install pyyaml
Requirement already satisfied: pyyaml in /usr/lib64/python3.4/site-packages
(3.12)
[root@bhimsvm31 k8s]#
如何让这个脚本导入PyYAML?
解决方法:
解决方案1:安装python 3.6和ln python3
export $PYPATH=`which python3`
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz
tar -Jxf Python-3.6.5.tar.xz
cd Python-3.6.5/
./configure && make && make altinstall
rm $PYPATH
ln -s `which python3.6` $PYPATH
python3 -m pip install pyyaml
python3 env/common_config/add_imagepullsecret.py
解决方案2:使用virtualenv
pip3 install virtualenv
virtualenv --python=python3 venv
source venv/bin/activate
pip install pyyaml
python env/common_config/add_imagepullsecret.py
Solution 3: use pipenv
标签:pyyaml,python,python-3-x,pip 来源: https://codeday.me/bug/20190910/1799685.html