Import problems python [PILLOW] [duplicate] - python

This question already has answers here:
Package (Python PIL/Pillow) installed but I can't import it
(3 answers)
Closed 7 years ago.
I want to import pillow module but have some problems. I did pip install PillowModule.whl , downloaded from this site
And through PyCharm module install
but when I try to import it I get error ImportError: No module named 'Pillow'
Any advice is helpful.

Pillow is a fork of PIL an older python imaging library
to import Pillow, you do the following:
from PIL import Image
edit: this stackoverflow problem Package (Python PIL/Pillow) installed but I can't import it
is worth a read.

Related

Automatically install Python module when code is ran [duplicate]

This question already has answers here:
Installing python module within code
(12 answers)
How to install and import Python modules at runtime
(5 answers)
have python script check for missing modules and install if missing
(3 answers)
Closed 25 days ago.
I am currently finishing a school project making a game of Blackjack. I was using Replit to code and everything was fine. I recently tried to run it at home on Visual Studio Code but it said a module named "matplotlyb.pyplot" wasn't installed. I seem to understand now that you have to install it manually. When my project is done, it will be sent to an external examiner who will review it. Is there anyway to automatically download the module when the code is ran so the examiner won't have to?
Here's what I'm looking for:
import matplotlib.pyplot as plt
#something that installs it if not already installed
Best practice would be to include a requirements.txt file along with your project. The file should contain all the required packages in the format
packagename==version
You could also use the below to generate the requriements.txt
pip freeze > requirements.txt
pip freeze gives you the list of all installed Python modules along with the versions
To run your install all the dependencies, you could just use:
pip install -r requirements.txt
Hope this helps!
Simply wrap things in a try.. except and don't forget to use sys.executable to ensure that you will call the same pip associated with the current runtime.
import subprocess
import sys
# lazy import + install
try:
import matplotlib.pyplot as plt
except ModuleNotFoundError:
subprocess.check_call([sys.executable, "-m", "pip", "install", "matplotlib"])

Packages importing in Python - Spyder [duplicate]

This question already has answers here:
ImportError: No module named requests
(33 answers)
Closed 4 months ago.
I'm using Spyder with Python 3.9 and Python 3.7 respectively on Mac and Windows and I got the same issue.
I'm trying to import some packages like:
import pythonnet as clr
or
import yfinance as yf
but I get this message:
File "/var/folders/xs/1_m665393ql86dptnsrft5j80000gn/T/ipykernel_2232/2746914347.py", line 1, in <cell line: 1>
import pythonnet as clr
ModuleNotFoundError: No module named 'pythonnet'
I'm sure that I already installed these packages from the prompt. I'm facing the following issue with many packages so I suppose is it related to the working directory. This is the directory where -pip installs the package by default:
/Users/user_folder/opt/miniconda3/lib/python3.9/site-packages
I'd to understand if the issue is related to the directory and how to efficiently setup it.
Thank you in advance.
It may be that when you are running the script you are trying to run a different version of python.
When you run the pip install try python3 -m pip install instead.
If this doesn't work and you are using vscode you can simply click in the bottom right where it states the python interpreter and change what you are using.
If all of that fails to work, then sorry but that's all I can suggest with my current knowledge.

Can not import requests in python, even then I installed it [duplicate]

This question already has answers here:
Installed module using pip, not found
(5 answers)
Dealing with multiple Python versions and PIP?
(28 answers)
Closed 2 years ago.
I installed "request" but I can not import it in my Python. I dont know why?
CMD:
pip install requests
Python:
import requests
Error:
ModuleNotFoundError: No module named 'requests'

'opencv-python' installed but still shows 'ModuleNotFoundError: No module named cv2 ' [duplicate]

This question already has answers here:
Cannot find module cv2 when using OpenCV
(24 answers)
Closed 3 years ago.
I have run the command
pip3 list
It shows that I have already installed these versions of OpenCV
opencv-contrib-python 4.1.2.30
opencv-python 4.2.0.32
But whenever I import cv2 it shows the error
ModuleNotFoundError: No module named 'cv2'
If you had a previous version installed. Uninstall it first and try installing it. See the instructions here:
https://pypi.org/project/opencv-python/

python3 cannot load qrcode module [duplicate]

This question already has answers here:
How to use pip with Python 3.x alongside Python 2.x
(11 answers)
Closed 6 years ago.
I have installed qrcode package as pip install pyqrcode
Then when I open a python2.x shell and import it there, no errors are given. But when I open a python3 shell and try to import it there it says
ImportError: No module named 'qrcode'
I import it as import qrcode
When I installed the package with pip it says Downloading PyQRCode-1.2.tar.gz, meaning that it is installing the last version. But in pypi
it says that it also support python3.
What's the correct way to import it?
You need to download a separate package for python 3. pip3 install pyqrcode
Then you can access it. Of course you will need to install pip3 first if you don't have it.

Categories