jasonbb
(jason)
August 26, 2023, 9:25am
1
Hello,
I have PIP installed “fer” and “opencv-python”
but I can’t import them.
My commands to install are:
pip install opencv-python
pip install fer
These worked.
My python code is:
import cv2
from fer import FER
Both imports do not work. They both fail with a similar error:
%Run testFer.py
Traceback (most recent call last):
File “N:\python\testFer.py”, line 1, in
import cv2
ModuleNotFoundError: No module named ‘cv2’
Please help.
petersuter
(Peter Suter)
August 26, 2023, 9:42am
2
Probably you have multiple Python’s installed.
Try:
where pip
and where python
to see where they are.
import sys
and print(sys.executable)
to see which one your IDE is using.
python -m pip
instead of pip
to use the pip that belongs to the active python.
jasonbb
(jason)
August 26, 2023, 9:54am
3
I only installed Python yesterday - so i’m a noob but I got the latest version. This is what i just tried:
N:\python>where pip
C:\Users\61403\AppData\Local\Microsoft\WindowsApps\pip.exe
N:\python>where python
C:\Users\61403\AppData\Local\Microsoft\WindowsApps\python.exe
N:\python>import sys + print(sys.interpreter)
‘import’ is not recognized as an internal or external command,
operable program or batch file.
N:\python>python
Python 3.11.4 (tags/v3.11.4:d2340ef, Jun 7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
">>> import sys + print(sys.interpreter)
File “”, line 1
import sys + print(sys.interpreter)
SyntaxError: invalid syntax
">>>
it doesn’t how the ^ but it points to the “+”
thanks
petersuter
(Peter Suter)
August 26, 2023, 10:36am
4
Sorry, these should go on separate lines in the python where you get the original problem with the ModuleNotFoundError:
import sys
print(sys.executable)
import cv2
Also try pip show opencv-python
to confirm it was installed.
jasonbb
(jason)
August 26, 2023, 10:50am
5
I tried that too and this is my response:
">>> import sys
">>> print(sys.interpreter)
Traceback (most recent call last):
File “stdin>”, line 1, in module>
AttributeError: module ‘sys’ has no attribute ‘interpreter’
">>> import cv2
">>> pip show opencv-python
File “stdin>”, line 1
pip show opencv-python
^^^^
SyntaxError: invalid syntax (^^^ points to “show”)
">>> cv2
<module ‘cv2’ from ‘C:\Users\61403\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\cv2\init .py’>
">>>
petersuter
(Peter Suter)
August 26, 2023, 11:04am
6
My bad, I meant print(sys.executable)
.
pip show opencv-python
should go on the command line, not inside python.
It looks like cv2 can be imported now. So you either fixed it or did this in a different python than before.
jasonbb
(jason)
August 26, 2023, 11:12am
7
ok,
I can import both “cv2” and “fer” at the python prompt.
But I can’t import them in my Thonny script.
jasonbb
(jason)
August 26, 2023, 11:25am
8
ok, i changed the Python Executable to my proper location and it complies now.