No module named 'PIL' after Installing pillow latest version - python

I am installed pillow,following the documentation here,
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow
and import Image like this:
from PIL import Image
Even though I upgraded Pillow to 9.4.0, I am getting the following error in vscode
No module named 'PIL'
I am using Python 3.9.7. I am not sure what I am doing wrong here, is it my python version or is it the vscode. Can someone please enlighten me about this issue.
I can see them installed in my venv folder, but cannot access it in the file I am working on (which is highlighted by yellow)

Add this code to your script.
import sys
print(sys.path)
Ensure that your sys.path contains the path "$PROJECT/venv/lib/python3.9/site-packages"
If it doesn't, your virtual environment is broken. Try this instead:
Use this command to remove the current environment. rm -rf venv
Create it again. python -m venv venv
Install all your dependencies and run pip install --no-cache-dir Pillow
Make sure your environment is functioning properly right now.

I currently have also problems with vscode venv because they dont get which packages are installed ...
if you have installed the package in the venv and selected the venc (source .venv/bin/active) there should be no problem running it. It only seems to be a linter problem.
By using my system python installation interpreter and have installed the packages there I dont get the error

Related

Python module not found after installing anaconda

Hope everyone is doing fine :)
I'm new to python, so I'm having trouble cause I've installed anaconda (for machine learning) and now, my local projects in VS Code with python, don't find modules installed from pip install.
I've searched online and I guess it has something to do with the path... Here's the path when I install the module:
user_stuff.../opt/anaconda3/lib/python3.9/site-packages
I want to install modules into my project on desktop, here's the path:
user_stuff.../Desktop/python-project
I keep getting this error when trying to import:
ModuleNotFoundError: No module named 'qrcode'
How do I change this? It's really frustrating :(
I guess your pip is referring to the pip provided by the system, it should be now referring to the pip provided by anaconda.
$ which pip
$ alias pip="/Users/my-username/anaconda3/bin/pip"
$ pip install qrcode
Do you use jupyter notebook in vs code? I prefer it because there you can easily select the environment you are using. And if you want to pip install anything in a environment you have to first activate it in the console with conda activate env name

install taichi package on python

I tried to run a script with python, it has taichi package downloaded from GitHub.
I have little knowledge of how python packages are installed, now I got error in command prompt like
"ModuleNotFoundError: No module named 'taichi'"
I just installed package downloaded from GitHub: https://pypi.org/project/taichi/#files
Hope someone can teach what should I do to run my script contains taichi package~
To install packages in python you just run the command pip install (name of package) in the command prompt so in your case that would be pip install taichi
How to install virtualenv:
Install pip first
sudo apt-get install python3-pip
Then install virtualenv using pip3
sudo pip3 install virtualenv
Now create a virtual environment
virtualenv venv
Active your virtual environment:
source venv/bin/activate
Now install your package for python
pip3 install taichi
I have figured it our that this Taichi package needs 64 bits python, it also needs LLMV file downloaded. Besides, there should be virtual studio installed in the local computer.
Then this Taichi package can be installed just by using "pip install taichi" in command.
Thanks for everyone's help!
I alse encountered this problem,I confirmed that I have already successfully installed taichi whereas it still showed "no module named taichi" .And here is my solution:tryimport sysandsys.path to check whether the file of the packages is contained in python's search range.
For example,after I inputsys.path in python ,it shows ['e:\\', 'd:\\anaconda2022\\python39.zip', 'd:\\anaconda2022\\DLLs', 'd:\\anaconda2022\\lib', 'd:\\anaconda2022', '', 'd:\\anaconda2022\\lib\\site-packages', 'd:\\anaconda2022\\lib\\site-packages\\win32', 'd:\\anaconda2022\\lib\\site-packages\\win32\\lib', 'd:\\anaconda2022\\lib\\site-packages\\Pythonwin']
I am using anaconda as the python interpreter in vscode ,so the packages of taichi is installed in d:\\anaconda2022\\lib\\site-packages,and I can import it successfully . But previously my sys.path are incorrectly setted to E:\\Python but not D:\\anaconda2022. Python cannot find the packages of taichi from the wrong sys.path.
Check the sys.path in python may help.If it is the one which cause the problem , there are many ways to edit sys.path .I solved it by uninstalling the python for I installed python and anaconda at the same time (- -).

ModuleNotFoundError, but it runs in anaconda (jupyter)

I've installed a module named rauth through terminal with pip3 install rauth command but when I import the module and run the code on Visual Studio Code with python3 interpreter, it gives ModuleNotFoundError: No module named 'rauth' error. But it is indeed installed and I can use it in Anaconda. The package file is stored here.
/Users/puffedricecracker/anaconda3/lib/python3.7/site-packages/rauth
And it seems like all my pip installed packages are stored in that path, but those are imported outside Anaconda with no problem. Tried several other commands as google search suggested.
• pip install instead of pip3 install
• python -m pip install
• python3 -m pip install
Let me know if there is any other information needed to be specified.
this is due to the module is installed into site-packages in Anaconda but not Visual Studio. Can you check if the module exists in Visual Studio folder? Another way to test it is to open Python IDLE and run the import, it should also return an error.
I don't know if this could be an universal solution but there was a way to set where to install a package using pip.
In python shell, find where your python modules usually go. It seemed like most of pip installed packages were installed in the second path so I chose that.
>>> import re
>>> print(re.__file__)
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/re.py
>>> import sqlalchemy
>>> print(sqlalchemy.__file__)
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sqlalchemy/__init__.py
Uninstall the package using pip uninstall packagename
Reinstall with a path name.
pip install packagename -t /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
(In fact, just copy pasting package files (in my case, they were rauth, rauth-0.7.3.dist-info) from anaconda package path in the post worked.)

Python does not find installed modules

Python3.5 does not locate installed modules when invoked in virtual env.
Create virtual env: python3.5 -m venv autogit/venv && cd autogit
source venv/bin/activate
which python == ...autogit/venv/bin/python
Weird, would expect python3.5
Add my python source code to /autogit and pip freeze>requirements.txt
pip install -r requirements.txt
ls venv/lib/python3.5/site-packages shows request-0-0-0-py3.5.egg-info and some other stuff
Since dependencies are installed under python3.5 and which python revealed python rather than python3.5, lets invoke the python3.5binary explicitly.... venv/bin/python3.5 autogit.py
Get ImportError: No module named 'request
??? Where could python be looking for packages if not in my virtual env?
UPDATE The questions above remain unanswered; here are things I noticed since then and the workaround I used:
pip install produced a file request-0-0-0-py3.5.egg-info. It did NOT produce an actual request directory with the source code or binaries for this module. Also why is it version 0 0 0 that is fishy
After some googling I noticed the module I wanted seemed to be named requests not request which is what was in my source. I changed it requests, pip install, and everything works. It was hard to see that there was a mistake because pip installing request did not fail
Have you got other Python versions installed? That might be the problem.
Try using pip3 instead of pip

No module named win32com

I've just installed Python for the first time and I'm trying to reference the win32com module however, whenever I try to import it I get the message "no module name win32com".
Any ideas?
the below plus add pywin32 in PyCharm setting work for me
python -m pip install pywin32
As it is not built into Python, you will need to install it.
pip install pywin
Since win32com is a Windows-specific package, this answer will be geared towards Windows users.
Option 1: Install locally with pipenv (recommended)
You can use a package manager like pipenv to manage your dependencies.
Ensure you have pipenv installed (pip install pipenv).
In your project directory, run pipenv install pypiwin32 to install the package.
Now you can run your code using commands like the following pipenv run main.py
Example main.py code:
import win32com
print(win32com)
Option 2: Install locally with venv (recommended)
If pipenv isn't your thing, you can use the built-in virtual environments.
From your project directory, run python -m venv venv to setup you virtual environment.
Run venv\Scripts\activate.bat from your project directory whenever you want to use this virtual environment (you will see (venv) added to your shell prompt to know it's activated).
Run pip install pypiwin32 from your active virtual environment to install the package.
You can run your code like python main.py so long as the virtual environment is active.
Option 3: Install globally (typically not recommended)
This is not typically recommended, but included anyway.
Using pip install pypiwin32 you can install the package globally.
Then you can run your code with just python main.py.
This will work as well
python -m pip install pywin32
You should try using pip this way:
pip install pypiwin32
It is pypiwin32 which should work.
When working with python projects its always a good idea to create a so called virtual environment, this way your modules will be more organized and reduces the import errors.
for example lets assume that you have a script.py which imports multiple modules including pypiwin32.
here are the steps to solve your problem:
1. depending on you operating system you need to download and install virtualenv package, in debian its as simple as sudo apt install virtualenv .
2. after installing 'virtualenv' package go to your project/script folder and create a virtualenv folder with virtualenv venv it creates a folder named venv in that directory.
3. activate your virtualenv source /path/to/venv/bin/activate if your already in the directory where venv exists just issue source venv/bin/activate
4. after activating your venv install you project dependencies pip install pypiwin32 or pip install pywin
5. run your script, it wont throw that error again :)

Categories