ImportError: No module named 'yaml'

后端 未结 6 946
既然无缘
既然无缘 2020-12-30 22:11

I have one script in which I am trying to execute

python3 env/common_config/add_imagepullsecret.py

But, I am getting the following error:<

6条回答
  •  庸人自扰
    2020-12-30 23:00

    The problem here arises from the fact that you have downloaded, compiled and installed a (newer) version of python3, on a machine that has an older python3 installed by the package manager. The latter has and associated pip3 the former does not. You can verify this by doing /usr/local/bin/python3 --version and /usr/bin/python3 --version

    Because of that, what happens when you do pip3 install pyyaml is to add the PyYAML package to the old Python3. When you do:

    /usr/bin/python3 env/common_config/add_imagepullsecret.py
    

    things should work, unless you rely on some feature of the newer python3.

    A more structural solution is to install pip for the newer python3 and use that to install PyYAML.

    A more structural solution, is to never install such additional python3 in your path, but e.g. in /opt/python/3.7.0, use virtualenv -p /opt/python/3.7.0/bin/python /opt/util/yourutil, install every package with /opt/util/yourutil/bin/pip3 install package_name and then do:

    /opt/util/yourutil/bin/python env/common_config/add_imagepullsecret.py
    

    to run your program. With a few supporting scripts/functions/aliases/links, this can be done very efficiently without polluting the systempython3` "install space" nor your PATH.

提交回复
热议问题