I really don't get why Python is so difficult to get up and running properly.
Anyway, I've just fresh installed Python 3.7 and PyCharm. I want to get the Python Imaging Library working within my project, but when I try to install it using PyCharm I get the following error:
pip install PIL
Non-zero exit code (1)
Try to run this command from the system terminal. Make sure that you use the correct version of 'pip' installed for your Python interpreter located at 'C:\Users\Jake\AppData\Local\Programs\Python\Python37-32\python.exe'.
Command output:
Collecting PIL
Could not find a version that satisfies the requirement PIL (from versions: )
No matching distribution found for PIL
You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
I've attempted to run python -m pip install --upgrade pip from a CMD prompt, but I then get this error:
Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
I just tried to install NumPy using the exact same method for PIL and Numpy installed without any issues whatsoever. This leads me to think that maybe PIL isn't supported for Python 3.7?
Can someone explain to me what the issue is here and help me with importing modules into my PyCharm project?
PIL is not maintained anymore. You can use Pillow instead, a more active fork of PIL.
pip install Pillow
Related
I've installed Pillow using the Pip command, and it says it's installed in the system. When I run my Python3 program that imports Pillow, it returns a module not found error.
Here is the error:
sudo pip3 install Pillow
This returns:
Requirement already satisfied: Pillow in /usr/lib/python3/dist-packages (8.1.2)
Then after I run my Python program which uses Pillow, I get this:
ModuleNotFoundError: No module named 'pillow'
Thanks!
Maybe you are using another version of python when you run your script..
Try to run your script from the terminal and write before it (python3)
You are probably trying to run it with a different python version or in a virtual environment, you can provide controls by going into the settings of your code editor.
I am currently on Linux x86-64 machine. I am trying to install opencv in my virtual environment using pip however the error I keep receiving is
ERROR: Could not find a version that satisfies the requirement numpy==1.19.3 (from versions: 1.19.2+computecanada, 1.21.0+computecanada, 1.21.2+computecanada)
ERROR: No matching distribution found for numpy==1.19.3
I am running python 3.9.6 (64bit) and my current numpy version is 1.21.3. the command I've been using is pip install opencv-python. i've also tried uninstalling other instances of openCV and have tried the other options all with the same error. Does openCV not support numpy 1.21.3? Would anyone be able to point me in the right direction?
On computecanada you don't need to install OpenCV.
You can use it by following these commands:
module spider opencv
module load opencv/version
Actually, this error happens if numpy version does not match OpenCV required version.
for my case:
I used python 3.6. so I solved this error by following:
pip install numpy==1.19.0
pip install opencv-python==3.4.11.45
after installing numpy I search which OpenCV version support this numpy version, I found 3.4.11.45 so I install it by 2 number command and it is working.
I installed cv2 with pip3 install opencv-contrib-python on terminal and it worked, but on the python IDLE whenever I try to import cv2 or run a vscode file with cv2 imported it says
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cv2/__init__.py", line 3, in <module>
from .cv2 import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cv2/cv2.cpython-38-darwin.so, 2): Symbol not found: _inflateValidate
Referenced from: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cv2/.dylibs/libpng16.16.dylib (which was built for Mac OS X 10.13)
Expected in: /usr/lib/libz.1.dylib
in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cv2/.dylibs/libpng16.16.dylib
in the terminal.
Any idea how to fix this?
I had the same question and I found it's because I use a high version of opencv (4.X.X), and my system version is low (mac os 10.12.5). So I installed a lower version of opencv (3.4.5.20), and then the question is solved.
You can use the following command to list the versions of opencv:
pip install opencv-python==
ERROR: Could not find a version that satisfies the requirement opencv-python== (from versions: 3.4.2.16, 3.4.2.17, 3.4.3.18, 3.4.4.19, 3.4.5.20, 3.4.6.27, 3.4.7.28, 3.4.8.29, 3.4.9.31, 4.0.0.21, 4.0.1.24, 4.1.0.25, 4.1.1.26, 4.1.2.30, 4.2.0.32)
ERROR: No matching distribution found for opencv-python==
Then you can try a lower version (3.4.5.20, for example), and install it using:
pip install opencv-python==3.4.5.20
Then you can retry import cv2 to see whether the question is solved.
I was puzzling around for a few hours and the thing that worked for me was to downgrade opencv (cv2) version via pip in conda enviroment (I am big fan of virtualenv but does not work smoothly with apple silicon M1 for now).
Follow these steps in activated virtual enviroment. To set virtual enviroment follow "Install conda" section from https://sayak.dev/install-opencv-m1/
pip3 uninstall opencv-python (equivalent is python3 -m pip uninstall opencv-python)
pip3 install opencv-python==randomwords (equivalent is python3 -m pip install opencv-python==randomwords)
Result should be error message which contains pip available versions for opencv (pick one)
pip3 install opencv-python==4.4.0.40 (my version of choice)
Verify with python3 -c "import cv2"
If there is not traceback you are good to go!
Notes:
Tested with python version 3.8.6
Operating system: MacOS Big Sur 11.3.1
OpenCV is also referred to as cv2 in Python.
The installation of OpenCV varies betweenoperating systems, so below Iam providing instructions for Windows, Mac, and Linux:
Installing OpenCV on Windows
1.Open the command line and type:
pip install opencv-python
2.Then open a Python session and try:
import cv2
3.If you get no errors, then OpenCV has been successfully installed and you can skip the next steps.
4.If there is an error (usually saying that DLL load failed) then please download a precompiled wheel (.whl) file from this link and install it with pip. Make sure you downloadthe correct file for your Windows version and your Python version. For example, forPython 3.6 onWindows 64-bit you would do this:
pip install opencv_python3.2.0cp36cp36mwin_amd64.whl
5.Then try to import cv2 in Python again. If there's still an error, then please type the following again in the command line:
pip install opencv-python
6.Now you should successfully importcv2 in Python.
Installing OpenCV on Mac
Currently some functionalities of OpenCV are not supported for Python 3 on Mac OS, so it's best to install OpenCV for Python 2and use Python 2 to run the programsthat containscv2 code. Its' worth mentioning that Python 2 is installed by default on Mac, so no need to install Python 2. Here are the steps to correctly install OpenCV:
Install brew:
Open your terminal and paste the following:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2. OpenCV depends on GTK+, so please install that dependencyfirst with brew (always from the terminal):
brew install gtk+
Install OpenCV with brew:
brew install opencv
Open Python 2 by typing:
python
Import cv2 in Python:
import cv2
If you get no errors, that means OpenCV has been successfully installed.
Installing OpenCV on Linux
1.Please open your terminal and execute the following commands one by one:
sudo apt-get install libqt4-dev
cmake -D WITH_QT=ON ..
make
sudo make install
2.If that doesn't work, please execute this:
sudo apt-get install libopencv-*
3.Then install OpenCV with pip:
pip install opencv-python
Import cv2 in Python.If there are no errors, OpenCVhas been successfully installed.
Actually, this issue has been raised for MacOS Catalina. I know the ask to solve this is painful but as of now the only clean way is to remove/uninstall anaconda completely and then do a fresh reinstall with installation directory set as /Users//anaconda3. Currently if you would notice this is in /opt which is not appropriate for MacOS Catalina. I may also recommend to use the command line installer.
More info: https://www.anaconda.com/blog/how-to-restore-anaconda-after-macos-catalina-update
Issue report: https://github.com/ContinuumIO/anaconda-issues/issues/10998.
I did find this question asked by few more people, but none of those exactly met my situation, so asking here myself.
I've (rather had) two versions of Python (2.7 and 3.4.3) on my Mac running the latest MacOS High Sierra. As I understand, the v2.7 comes as default installation with the MacOS. And I installed the 3.4.3 (from .dmg file downloaded from the python site). Thus now, the python command defaults to the 2.7, while python3 points to the 3.4.3 in the terminal.
While trying to learn, I tried a python script that uses
import PIL and from PIL import Image
But when running, this gave the error ImportError: No module named PIL.
Upon research on google, I figured out to install PIL and Pillow using
sudo pip install Pillow
It installed correctly, but I'm still getting the same error.
To remove the confusion, I decided to remove the python 3.4.3 from the system. But even after it's removed, I still get the same error.
Even pip list displays Pillow 5.1.0 alright.
So right now, I've only Python 2.7, and the error persists, while Pillow is also in there.
which python gives /opt/local/bin/python as the path.
Does any of the above ring a bell? Any ideas, what else could be missing here?
Phew, finally found the issue. Thanks #Yash for the pointers.
Incidentally I did a which -a python and surprisingly got this output:
/opt/local/bin/python
/usr/bin/python
Damn, I don't remember when I installed a second 2.7 version on the /opt/local/bin folder (probably via macports). Alright, removed the confusion, deleted this python, so now I'm left only with the system installed python at /usr/bin.
And now the imports all run perfectly fine as expected. :-)
Try this,
sudo pip install image
I hope it works! One more thing, do check if you're running python3 filename.py instead of python filename.py, if you want to install it for Python 3, run the command,
sudo pip3 install Pillow
Basic Installation:
pip install Pillow
Windows Installation:
pip install Pillow
Reference: https://pillow.readthedocs.io/en/stable/installation.html
Try this. It worked for me
pip install --upgrade --force-reinstall pillow
If you get something like access denied error run the below command
pip install --upgrade --force-reinstall pillow --user
I am trying to install opencv in python on my windows machine but I am unable to do so. I have python 2.7.11::Anaconda 2.4.1 <32-bit>
Here is what I have tried till now -
pip install cv2 on command line gives the error :
could not find a
version that satisfies the requirement cv2
I downloaded the package from sourceforge site, followed the steps
and pasted cv2.pyd in C:\Python27\Lib\site-packages but still it is
not working. I get the following error message
ImportError: No
module named cv2
(I already have numpy installed and it works just fine).
pip install opencv-python
you can type this instead of
pip install cv2
it also works with anaconda pro
I was able to solve the error.
If you are using python version 3 , sometimes you have to use pip3.
pip3 install opencv-python
Make sure you are using python 3 , it won't work for python 2.
Try
pip install opencv-python==4.3.0.36
So I was using PyCharm, and what worked for me was to install it directly from file->settings, Project:your-project-name->Python Interpreter list