ModuleNotFoundError: No module named 'yaml'

10,507

You have not provided quite enough information for an exact answer, but, for missing python modules, simply run

py -m pip install PyYaml 

or, in some cases

python pip install PyYaml

You may have imported it in your project (on PyCharm) but you have to make sure it is installed and imported outside of the IDE, and on your system, where the python interpreter runs it

Share:
10,507
iamj
Author by

iamj

Updated on December 05, 2022

Comments

  • iamj
    iamj over 1 year

    I have used a YAML file and have imported PyYAML into my project.

    The code works fine in PyCharm, however on creation of an egg and running the egg gives an error as module not found on command prompt.

  • Anthon
    Anthon almost 6 years
    On which platform can you start Python by just using py? The "some cases" you refer to can only occur on a platform where the pip command has no extension (like .bat), your python is in your path and you are in the bin directory of your installation (so pip) can be found. In that case you should be able to do just pip install pyyaml, unless pip is incorrectly installed.
  • ntrupin
    ntrupin almost 6 years
    I have python on my Windows 10 laptop, and, after much worry that it was configured poorly, I found out that all of my commands had to start with py -something, with -m being the extension for installing modules
  • iamj
    iamj almost 6 years
    Thanks @Anthon, I shall try this out. However, as ntrupin mentioned, i was able to resolve it once i tried installing pyyaml in my machine. I was of the assumption that since the Setup.py had PyYaml as a dependency, it would automatically install it.
  • Anthon
    Anthon almost 6 years
    It should install automatically if you include the above in your setup.py. If you have to do so by hand for each virtualenv you create you are bound to forget it. (And I hope you are not clobbering the system wide python with your programs and packages.)
  • A.P.
    A.P. over 3 years
    In my case (Windows 10 desktop) I had to run "python -m pip install PyYaml".
  • Ryan Kyle
    Ryan Kyle over 2 years
    On MacOS with python version 3.9.7 and pip version 21.2.4, I had to run pip3 install PyYAML.