Basically from the title and the image below, I have installed pyserial
and it works in the Python terminal but not in a script.
I have done pip3 install pyserial
, and have also tried pip install pyserial
and python3 -m pip install pyserial
, which return that I already have the package installed.
When I use python3
, enter the Python terminal, and enter import serial
there are no errors. When I have a script using import pyserial
and run it using python3 ./serial_test.py
, it gives the error.
Why does one throw an error and the other not? And how may I fix this?
Here is a screenshot of my terminal:
My python script, no matter if the script uses the serial
library, throws the error:
Edit 1: One thing I forgot to mention was that when I do pip3 --version
it shows:
pip 22.0.3 from /usr/local/lib/python3.8/dist-packages/pip (python 3.8)
instead of:
/usr/lib/python3...
as listed here, although this still would not explain the difference in the in-terminal code.
Maybe a solution would be to install it using pip
for /usr/lib/python3
, however I am unsure how to do that.
Edit 2: As I look further into this, I will update my findings. When I do whereis python3
, I get:
python3: /usr/bin/python3 /usr/bin/python3.8 /usr/bin/python3.8-config /usr/lib/python3 /usr/lib/python3.8 /usr/lib/python3.9 /etc/python3 /etc/python3.8 /usr/local/lib/python3.8 /usr/include/python3.8 /usr/share/python3 /usr/share/man/man1/python3.1.gz
I am unsure how programs work on the command line, so I am not sure why there are multiple places for python3
, but maybe it will explain the issue.
Edit 3: which python3
shows:
/usr/bin/python3
and which pip3
shows:
/usr/local/bin/pip3