1

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
  • 69,918
  • 32
  • 186
  • 246
iamj
  • 21
  • 1
  • 1
  • 4

2 Answers2

7

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

ntrupin
  • 83
  • 1
  • 6
  • 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. – Anthon Jul 14 '18 at 05:50
  • 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 – ntrupin Jul 14 '18 at 12:51
  • In my case (Windows 10 desktop) I had to run "python -m pip install PyYaml". – A.P. Sep 17 '20 at 21:59
  • On MacOS with python version 3.9.7 and pip version 21.2.4, I had to run `pip3 install PyYAML`. – Ryan Kyle Sep 16 '21 at 17:16
0

I have not made an .egg for some time (you really should be consider using wheels for distributing packages), but IIRC an .egg should have a requires.txt file with an entry that specifies dependency on pyyaml.

You normally get that when setup() in your setup.py has an argument install_requires:

setup(
...
install_requires=['pyyaml<4']
...
)

(PyYAML 4.1 was retracted because there were problems with that version, but it might be in your local cache of PyPI as it was in my case, hence the <4, which restricts installation to the latest 3.x release)

Anthon
  • 69,918
  • 32
  • 186
  • 246
  • 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. – iamj Jul 15 '18 at 02:24
  • 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.) – Anthon Jul 15 '18 at 05:17