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?