How can I import in Python simple coding error - python

I have started any coding for example: from PIL import Image, I encountered such an error:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
from PIL import Image
ModuleNotFoundError: No module named 'PIL'
I will be pleased that guide me.

In shell, run:
pip install Pillow
PIL is deprecated - Pillow is its replacement

This means that the package is not installed. To install it, you will need pip, a package installer for python.
Here is the Pillow package official website, which you can use to understand how to install the package: https://pillow.readthedocs.io/en/stable/installation.html. All the commands on the site are typed into Terminal on MacOS and Linux and the cmd on Windows.

Related

Pillow working in python 3.10.x but not in 3.11

I am using the pillow library for images in python. With python 3.10.x I dont get an error when I import Image from PIL
from PIL import Image
However if I run the same code in python 3.11.x, I get an error
Traceback (most recent call last):
File "C:\Users\einfa\Downloads\Displaying-Images-With-Turtle_ORIGINAL\main\main.py", line 8, in <module>
from libs.PIL import Image
File "C:\Users\einfa\Downloads\Displaying-Images-With-Turtle_ORIGINAL\main\libs\PIL\Image.py", line 100, in <module>
from . import _imaging as core
ImportError: cannot import name '_imaging' from 'libs.PIL' (C:\Users\einfa\Downloads\Displaying-Images-With-Turtle_ORIGINAL\main\libs\PIL\__init__.py)
Does somebody know a solution so I can run my program with PIL in both versions?
I tried installing different pillow versiosn at first which did't work. After that I installed python 3.11.x and python 3.10.x and noticed this difference. I installed pillow via pip with the command pip3 install pillow

Why cant I import/use installed libraries in Python

I recently downloaded Python 3.10 because I used 3.9. At first, everything worked fine. Sadly, I can't use installed libraries nor use newly downloaded ones, since I deleted Python 3.9. What can I do about this problem?
VSCode gives me this Error message:
Traceback (most recent call last):
File "e:\XXXX\XXXX.py", line 5, in <module>
from playsound import playsound
ModuleNotFoundError: No module named 'playsound'
You can check installed packages using this command:
pip freeze
or
pip list
Uninstall and install using command pip install <package-name>

No module name 'face_recognition' windows

I am using a windows computer. When I run the command(which is below) it does not work and says something about dlib. I looked at this stack overflow post but no answers worked:
Stackoverflow post
My install:
>>> pip install face-recognition
My code:
import face_recognition
image = face_recognition.load_image_file("your_file.jpg")
face_landmarks_list = face_recognition.face_landmarks(image)
error:
Traceback (most recent call last):
File "main.py", line 1, in <module>
import face_recognition
ModuleNotFoundError: No module named 'face_recognition'
Face_recognition package is not officially supported on Windows but it might be work,
Here is the two way, You can install face_recognition package,
For Windows 10, You can follow these steps,
https://github.com/ageitgey/face_recognition/issues/175#issue-257710508
They are also providing ready-made virtual environment for this, So you can install it on your Windows system from here by using virualbox.
https://medium.com/#ageitgey/try-deep-learning-in-python-now-with-a-fully-pre-configured-vm-1d97d4c3e9b
I know Windows is not supporting face_recognition package but I guess this will little bit help you.
It seems the package doesn't seem installed. You may be running in a different environment.

Pyglet import not found when using pip

Ok so I'm trying to install pyglet using pip3 and I've used the command pip3 install pyglet and it works it's in my /usr/local/lib/python3.7/site-packages (1.4.9) and I am using python 3.7. I have successfully imported things using pip before, I've tried uninstalling and reinstalling... I'm not sure what the problem is the error message is
Traceback (most recent call last):
File "/Users/myname/Documents/plz.py", line 1, in <module>
import pyglet
ModuleNotFoundError: No module named 'pyglet'

I'm having troubles getting pybrain working through anaconda

Here is my problem:
After I managed to install anaconda (having python 3.4), I apparently managed to install pybrain too. But when i use 'import pybrain' from anaconda or from the terminal too I get this error:
>>> import pybrain
Traceback (most recent call last):
File "<ipython-input-2-0fb7233d2a8c>", line 1, in <module>
import pybrain
File "//anaconda/lib/python3.4/site-packages/PyBrain-0.3-py3.4.egg/pybrain/__init__.py", line 1, in <module>
from structure.__init__ import *
ImportError: No module named 'structure'
Simply running sudo pip3 install git+https://github.com/pybrain/pybrain.git worked for me after having the same issue.
The version up on PyPi isn't Python 3 compatible.
Installing the latest commit directly using pip3 should take care of your old package (from PyPi) as well.

Categories

Resources