OS/X VENTURA 3.7 , PYTHON3 ,
import img2pdf
from PIL import Image
import os
CODE…
ModuleNotFoundError: No module named ‘mylib’
OS/X VENTURA 3.7 , PYTHON3 ,
import img2pdf
from PIL import Image
import os
CODE…
ModuleNotFoundError: No module named ‘mylib’
You haven’t provided enough details.
Post the smallest code that produces the problem and its traceback (error messages) in full.
In order to preserve formatting, please select any code or traceback that you post and then click the </>
button.
#code plus error
import img2pdf
from PIL import Image
import os
pngfilename = “test1.png”
pngfname = fname[:-4]
print(“processing:”, pngfname)
pdffilename = pngfname + (“.pdf”)
image = Image.open(fname)
pdf_bytes = img2pdf.convert(image.filename)
file = open(pngfname, “wb”)
file.write(pdf_bytes)
print(“saving:”, pdffname)
image.close()
file.close()raceback (most recent call last):
File “/Users/johnpendreich/app.py”, line 1, in
import img2pdf
File “/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/img2pdf.py”, line 25, in
from PIL import Image, TiffImagePlugin, GifImagePlugin, ImageCms
File “/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/PIL/Image.py”, line 33, in
import logging
File “/Users/johnpendreich/logging.py”, line 3, in
import mylib
ModuleNotFoundError: No module named ‘mylib’
johnpendreich@Johns-iMac ~ %
You have a file named “logging.py” located in the directory “/Users/johnpendreich/”. This file shadows Python’s logging module, i.e. when PIL tries to import Python’s logging module, it instead imports your logging.py. Your logging.py imports something called “mylib”, which Python cannot find, which is what the error message tells you.
You need to rename your logging.py file to something else.
In general, you should never give a Python script a name which already exists in Python’s standard library. Here is a list.
pip install virtualenv
. It’s about 4MB.python\myproject
. Go into myproject
.virtualenv .venv
. Your environment is now named .venv..venv\scripts\activate
.myprog.py
program. Just add a few imports and maybe a few lines for testing the imported modules were installed correctly.python myprog.py
.To go to another project.
.venv\scripts\deactivate
.python\myproject2
..venv\scripts\activate
.python myprog2.py
.Did the error message really say that “mylib” is missing? Because you didn’t import it. Or it may be part of another module that you didn’t install correctly because you didn’t use an environment.
Help us help you. Read this link first and learn how to format code so we can help you better. Do not use a screen shot of your code as some of us will copy and paste the code to get it to work for you, so you can learn from this. About the Python Help category You will get more help this way.