0

This is a very leveled problem. I was using pdoc to create some documentation for my library, which uses PIL for image processing. Everything worked fine, except the module that used PIL, where it threw the following

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pdoc/doc.py", line 400, in submodules
    module = extract.load_module(mod.name)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/contextlib.py", line 75, in inner
    return func(*args, **kwds)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pdoc/extract.py", line 221, in load_module
    raise RuntimeError(f"Error importing {module}") from e
RuntimeError: Error importing timmaldFunctions.setup

  warnings.warn(
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pdoc/doc.py:402: RuntimeWarning: Couldn't import timmaldFunctions.imageStuff:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pdoc/extract.py", line 219, in load_module
    return importlib.import_module(module)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ModuleNotFoundError: No module named 'PIL'

It threw that exact exception many many times, despite the fact that I ran it once. just to check, I used pip3.9 show PIL, and it said WARNING: Package(s) not found: PIL. However, I have used PIL.Image in PyCharm many times, always with python 3.9, just like I am using for this library. I looked in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages and found PIL in there. I then made sure that that site packages path was in sys.path, and it was. I tried using Pillow(a fork of PIL), and made sure I had a version that was compatible with python3.9(I have 8.1). However, even after I installed packages through both automatic install in PyCharm and pip3.9 install Pillow, as well as pip3.9 install pillow. pip3.9 show Pillow and pip3.9 show pillow said that it existed and had the correct version. However,PyCharm still acted like it wasn't installed, and threw ModuleNotFoundError: No module named 'Pillow'. I also learned that PIL and pillow can't be in the same environment, so I tried pip3.9 uninstall PIL, but pip thought that the package never existed in the first place. The way I see it, I have 2 options: Get pdoc and pip to recognize PIL, or Get Python to recognize Pillow. Which do I do, or is there another option? Thanks in advance, and let me know if you need more info!

UPDATE:

I created a venv using the command from the answer given, and then I found the file called activate for the venv(no extension), and entered the following into terminal: source path-to-activate, at which point the name of the venv appeared in parentheses behind the start of each new terminal line. I then went into PyCharm's interpreter settings and made a new environment on PyCharm, choosing "existing environment" and then put in the path to the venv folder/bin/python3.9 (this is an alias that points to the real python3.9). It named the setting after the project it was in. I switched to that in the interpreter options. I then ran pip3.9 install pillow from terminal(which was still using the venv), with both pip and pip3.9 and also replacing those with the paths to them in the new venv. Each time I got the Requirement already satisfied message, assuring that pillow was installed. I also checked site-packages, and PIL was there, as well as the Pillow-dist-info. PyCharm didn't error, so it was working. However, when I ran pdoc path-to-library-folder(still in the venv), it threw the exact same error. Did I do any part of that wrong?

Nathan Wolf
  • 336
  • 3
  • 12
  • 1
    Is PyCharm using the same interpreter as pip3.9 in the run configuration? – Peter Wood Apr 07 '21 at 15:01
  • 2
    When you install Pillow it appears as `PIL`, .e.g. `import PIL`. – Peter Wood Apr 07 '21 at 15:03
  • @PeterWood Your second comment is helpful, it might then work if I try the pdoc again. For your first comment, pip3.9 is a terminal alias or something like that(it came with python3.9 as far as I can tell) which represents installing a package for Python3.9, because my system default python version is 2.7, so that has to be specified. PyCharm is using Python 3.9. That should be the same thing, but I'm not sure which interpreter is actually running pip3.9. Is there a way to check that? – Nathan Wolf Apr 07 '21 at 15:11
  • If you're not using PyCharm to install the best way to evoke pip is to use python -m pip. You just have to know which python you're using. To do that, activate the venv python first. – Peter Wood Apr 07 '21 at 16:00

2 Answers2

1

Which do I do, or is there another option?

In general, with open-source projects, I check their repositories and see which has the more recent commit/activity. In your case, PIL has its last commit 10 years ago, 9 forks, 9 stars, and 0 watchers, whilst pillow has its last commit 6 hours ago, 1.6k forks, 8.4k stars and 216 watchers. While this isn't a perfect metric, it is a rule of thumb.

How to proceed? From scratch:

  1. Create a new venv using python3 -m venv nathans_new_venv and activate it, by sourcing its activate line.
  2. Now, pip3.9 install pillow or nathans_new_venv/bin/pip install pillow

Point pycharm at nathans_new_venv and you should be golden.

hd1
  • 33,938
  • 5
  • 80
  • 91
  • Thanks so much! I think your answer has at the very least gotten me very close. I posted an update in my question. Can you please check that out and make sure I didn't do anything wrong? – Nathan Wolf Apr 07 '21 at 18:00
  • You may need to further install pdoc in nathans_new_venv – hd1 Apr 07 '21 at 20:21
  • I think it was there, I can always try different variations of the command and make sure it's up to date – Nathan Wolf Apr 07 '21 at 20:29
  • It wasn't there, so I installed it, when it was there, the exact same thing happened. – Nathan Wolf Apr 07 '21 at 21:34
  • It's not a matter of trying different variations of the command... activate the venv or use the full path, it will **always** hit the right binaries – hd1 Apr 07 '21 at 22:50
  • at this point it's probably easier to copy the html of another module then plug in the values of the image one – Nathan Wolf Apr 07 '21 at 23:27
0

This worked for my PyCharm problems:

python3.9 -m pip install pillow --upgrade
rundekugel
  • 1,118
  • 1
  • 10
  • 23