cannot import name '_imaging' from 'PIL' error - python

I am using Pillow-6.1.0 for my python project and I am trying to import the ImageGrab() function inside it however I keep getting this following error:
cannot import name '_imaging' from 'PIL'
I am currently using Python 3.7 and editing the code on Visual Studios (Unsure if the IDE may play part in the error as I do not have much experience on it)
I am also running Windows so some of the solutions I have seen which require Linux does not work for me.
What I have tried:
Uninstalling and reinstalling Pillow
Deleting everything with "PIL" in the Python37-32/Lib/site-packages folder and uninstalling Pillow and reinstalling
Moving the Pillow module directly into my project folder
Moving ImageGrab.py directly into my project folder
Updated my Pillow module
All my reinstallations of Pillow is via the pip command
Other possibly relevant info:
ImageGrab() is not the only module that I cant import, I also cant import the Image module
I can import the PIL module successfully but I cannot access the modules within it via the command "from PIL import some_PIL_module" in my IDE
I only get the "cannot import name '_imaging' from 'PIL'" error when I am running my code through the Visual Studios IDE, if I type the command "from PIL import ImageGrab" directly into the python terminal it runs successfully with no errors
This is the line that gives me the error in my code
from PIL import ImageGrab;
I expected it to import with no problems but instead, I get the following error:
cannot import name '_imaging' from 'PIL'

Related

ModuleNotFoundError: No module named 'System'

I'm working on an EXE file crypter in python 3.11.1 and I cannot seem to get the System.Reflection import working. I've tried pythonnet and clr, but it just doesn't recognize 'System.'
I've tried to make sure pythonnet and clr are not conflicting, but that hasn't worked either. I tried clearing the cache and reinstalling python entirely. I also made sure there weren't any multiple instances of pip and python. This is the code snippet:
def crypt(filepath):
import base64
import clr
from System.Reflection import Assembly

ImportError, no module named

I get ImportError: no module named Flopy when I try to run the following script from an Anaconda prompt in the folder that the script it stored in, but when I run the script through Spyder it imports Flopy just fine and the rest of the code (not shown) which uses Flopy also works.
# import the required libraries
try:
import flopy
except:
fpth = os.path.abspath(os.path.join('..', '..'))
sys.path.append(fpth)
import flopy
The Spyder ran version never runs the code under than 'except' section since it managed to import Flopy at first try. I tried checking the path created by os.path.abspath(os.path.join('..', '..')) and even copied the Flopy directory to that location and running the script from the Anaconda prompt started in that folder...which did make some difference, but the import failed with error: ImportError: cannot import name getfullargspec.
Any ideas why imports work one way but not the other?
Fixed it with help from #Jainal Patel! I just had to tidy up all my environment paths. There was an installed version of Python in C:\Python3, but Spyder was using the one in C:ProgramData\Anaconda.
Now when I open the command prompt, or an Anaconda prompt, or use Spyder, it uses the same Python environment and recognizes all my installed packages.
!pip install flopy
try:
import flopy
except:
fpth = os.path.abspath(os.path.join('..', '..'))
sys.path.append(fpth)
import flopy
you need to install it first either using pip or conda

Error using PIL in a virtualenv in IBM Cloud Functions: ModuleNotFoundError: No module named 'PIL'

I'm attempting to define an IBM Cloud Function in Python using PIL.
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
img = Image.new('RGB', (width, height))
d = ImageDraw.Draw(img)
...
I use Pycharm to do my development. In Pycharm, under site-packages in my Python runtime, I see PIL and Pillow-4.3.0:dist-info. When I run my code locally from within Pycharm it works fine.
I built a virtualenv with the same Python runtime and my code in order to include dependencies not part of the Cloud Functions Python runtime. Examining the virtualenv, I can see the same libraries:
\virtualenv
\bin
\include
\lib
\python3.6
\site-packages
...
\PIL
\Pillow-4.3.0:dist-info
...
However, when I execute my code as a Cloud Function with this virtualenv runtime, I see an error: ModuleNotFoundError: No module named 'PIL'.
I'm thinking the error is with how I've constructed my virtualenv, but I'm at a loss as it looks like the same libraries are there.
OK, I figured out the immediate problem. It was a simple error in my deploy script. While my virtualenv content looked fine locally, I had a deployment error that resulted in something other than what I'd intended getting deployed. Now, next error: ImportError: cannot import name '_imaging'

pdfminer - import error

I’m new to Python and programming in general.
I am trying to install pdfMiner. I have Windows 7 with Python 2.7 installed.
I followed the instructions when installing (downloaded the PDFMiner source, unpacked it, and ran setup.py to install and it was installed in C:\pdfminer) – no errors.
It created:
build, build\lib,build\lib\pdfminer, then copied files to build\lib\pdfminer. It created build\scripts-2.7 and copied tools\pdf2txt.py, dymppdf.py to scripts, then wrote install-egg-info
and had no errors with install.
When I try running the test document from the command line:
C:\pdfminer\pdfminer-20140328> pdf2txt.py samples/simple1.pdf
I get:
File “C:\Python27\Scripts\pdf2txt.py”, line3, in <module> from pdfminer.pdfdocument import PDFDocument
ImportError: No module named pdfminer.pdfdocument
I saw this post:
pdfminer - ImportError: No module named pdfminer.pdfdocument
and tried following it (#1..put sys.path.append… into pdf2txt.py) and get the same error.
The system variables do include the path (pdfminer\pdfminer-20140328).
I’ve looked for other solutions but haven’t had much luck – the file is there but I can’t seem to get the program to look in the right area for it…I think.
Do I have the wrong path or is it installed in the wrong directory?

cx_freeze no module named 'pkg_resources'

I'm using Python 3.3.5 with cx-freeze 4.3.3 on windows 8.1.
I'm trying to cx_freeze a program that uses pkg_resources.
I initially had it in my setup file under packages, but when I tried to freeze it the processes stopped with an error Import Error: No module named 'pkg_resources'.
I then moved it in the setup file from packages to includes. The cx_freeze process completed this time but when I tried to start the application I got another error message.
If I go to my IDE and try to import pkg_resources it works fine.
>>> import pkg_resources
>>> pkg_resources
<module 'pkg_resources' from 'C:\\Python33\\lib\\site-packages\\setuptools-18.0.1-py3.3.egg\\pkg_resources\\__init__.py'>
There's a similar question asked here, and the solution is to re-install setuptools. So I downloaded setuptools 18.0.1 and installed it via cmd, but it did not solve my problem and I'm still getting the same errors with cx_freeze.
Any help getting this to work would be greatly appreciated.
Edit: My solution (hack) has been to write the dependency out of yagmail. Yagmail's original _innit__.py...
from pkg_resources import get_distribution
__project__ = 'yagmail'
__version__ = get_distribution(__project__).version
I first put a print statement in there to get the version, and then hard coded it.
__project__ = 'yagmail'
__version__ = '0.4.84'
Though this has solved my problem it isn't really the answer, so will leave this open should someone have a solution that keeps pkg_resources.

Categories

Resources