0

The scene:

  • wrote my own python package
  • used sphinx to create documentation for said package
  • I'm now trying to upload said documentation to readthedocs

The problem:

When I try to build the documentation, I end up with an error ModuleNotFoundError: No module named 'matplotlib'. I spent about two hours trying to figure out how to fix this, and I've added my .readthedocs.yaml and requirements.txt files, but I just copied what was on the readthedocs website, I can't find anything about how to add additional Python packages to these files (specifically what text I use to do so). I mean, everything says you can, and that you can add via the config or the yaml or through conda, but no example text. I really just need a simple example: "to add matplotlib module, add foo text to requirements.txt" or something like it

I'm sure it's a really simple obvious answer to people who work with this all the time, but this is my first time trying to publish documentation. Can anyone help?

mzjn
  • 48,958
  • 13
  • 128
  • 248
user2954167
  • 155
  • 1
  • 3
  • 14
  • 1
    I don't understand - you can open `requirements.txt` in any text editor and add text manually. And `.readthedocs.yaml` is also normal text file so you can open it in any text editor. – furas Sep 25 '21 at 00:21
  • @furas Yes, I understand that part. What I'm saying is I don't know what text to add. – user2954167 Sep 25 '21 at 00:26
  • did you open `requirements.txt` in text editor? It should explain everything. You need new line with at least text `matplotlib` - and it will install the newest version. If you need some special version then you need `matplotlib==version` or `matplotlib>=version` if you need `version` or newer. – furas Sep 25 '21 at 00:40

1 Answers1

2

Check the version of matplotlib that your package depends on like so:

>>> import matplotlib
>>> matplotlib.__version__
'3.3.4'

The format for requirements.txt is like packagename==version, so you should add the following line:

matplotlib==3.3.4

If using a Linux command-line, you can also do it this way:

$ pip freeze | grep matplotlib
matplotlib==3.3.4

If working in a virtual environment where only the required packages are installed, you don't even need to do this by hand for each package; since pip freeze generates output in the correct format, you can just save the output of pip freeze to generate your whole requirements.txt file (see this Q&A for more details):

$ pip freeze > requirements.txt
kaya3
  • 47,440
  • 4
  • 68
  • 97