How to check if the python module pyserial is installed?

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
Fran_3
Level 2
Level 2
Posts: 92
Joined: Tue Jul 28, 2020 5:13 pm

How to check if the python module pyserial is installed?

Post by Fran_3 »

Entering this at the terminal command line...

Code: Select all

dpkg -l | grep python3
seems to list all the installed python3 modules...
BUT pyserial is not listed...
even though I know it is installed
via...

Code: Select all

pip3 instal pyserial
which reports that it is already installed

The Question:
Why doesn't the first command show pyserial is installed?
Just trying to get educated so thanks for any help.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
ajgringo619

Re: How to check if the python module pyserial is installed?

Post by ajgringo619 »

For listing all installed python modules:

Code: Select all

pip3 list
For listing user-specific python modules:

Code: Select all

pip3 list --user
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: How to check if the python module pyserial is installed?

Post by rene »

pip installs Python packages from PyPI, the Python Package Index, which is to say not from the Mint/Ubuntu software repositories. dpkg and apt and friends do latter and only concern themselves with latter.

As long as we're talking about an also from the repositories or standard installed Python interpreter on Mint/Ubuntu it's generally considered better to also install packages from those same repositories. Of course, only if said package is available prepackaged for Mint/Ubuntu from them but many/most are. In this case apt search pyserial will supposedly show it available (can't check right now). Keeping interpreter and packages "synchronized" like that wrt. origins and possible configuration could theoretically be important. And even though often not practically so much it at least makes conceptual sense.

pip you'd use to grab something not available from the repositories, or more usually a newer version than available from them, or maybe to install into a so-called venv (virtual environment). Or as the main package retrieval tool for an entirely self-installed version of Python, generally also as a result of needing a newer version of that than available directly from the repositories. And of course on e.g. Windows where no such thing as "distribution repositories" exist in the first place.

In any case. Using pip will generally work but if you're using a repository Python interpreter you may wish to "pair" it with packages also from those same repositories.
Fran_3
Level 2
Level 2
Posts: 92
Joined: Tue Jul 28, 2020 5:13 pm

Re: How to check if the python module pyserial is installed?

Post by Fran_3 »

Thank you ajgringo619 and Rene.

Rene, in response to your post noting that...
pip installs Python packages from PyPI, the Python Package Index,
which is to say not from the Mint/Ubuntu software repositorie
Question 1:
a. How would I install pyserial from the Mint/Ubuntu software repository?
b. Is Software Manager the tool to use?
c. How about installing packages, python or otherwise, from the Mint/Ubuntu software repository using Terminal and the command line?
(A couple of examples would be helpful.)
d. Now that I've used pip to install pyserial and...

Code: Select all

pip3 list
shows it... while...

Code: Select all

apt search pyserial
does not show it
To keep things in order should I use...

Code: Select all

pip3 uninstall pyserial
to remove it... and...
Then reinstall it from the Mint/Ubuntu Software Repository using the Software Manager GUI?

And finally to your comment...
dpkg and apt and friends do latter and only concern themselves with latter.
Question 2:
Do you mean apt and dpkg will install packages from the Mint/Ubuntu software repository?
Or what?
(A couple of examples would be helpful.)

Thanks again to both of you for your help.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: How to check if the python module pyserial is installed?

Post by rene »

As to Q1, trouble is that I'm currently often not in fact on Mint and can then not quickly verify things. Yes, apt search pyserial indeed does not hit upon the pySerial module which on Ubuntu 18.04/Mint 19 has apparently been helpfully named python3-serial for the repository Python 3 interpreter, python-serial for the Python 2 one. I believe this will not be different for Ubuntu 20.04/Mint 20, but try searching with

Code: Select all

apt search "python.*-serial$"
(the search term is a so-called regular expression). Or note those package names from the main pySerial package documentation over at https://pyserial.readthedocs.io/en/latest/pyserial.html, "Packages".

I generally consider Software Manager a bit too slow and clunky to in fact use, but sure, it's just one way of installing repository software on Mint. Some like and advise synaptic but I personally tend to just use the command line:

Code: Select all

sudo apt-get install python3-serial
and/or same for python-serial if you'd also like it integrated into the system's Python 2 install. Very same for any other repository software. If you will be experimenting, uninstall is

Code: Select all

sudo apt-get purge --auto-remove python3-serial
Note that the --auto-remove switch cleans up any by the install automatically installed dependent packages that are no longer required when the main package is uninstalled (plus in fact other such packages you may currently have lingering around already). For pySerial there are no dependent packages so not here relevant, but generally it is. Personally I would, yes, uninstall the pip-retrieved version in the manner you say and grab it from the repositories as per above. Which is still not to say that is in fact generally practically important.

As to Q2, yes, apt interfaces with the repositories as configured in the file /etc/apt/sources.list and the directory /etc/apt/sources.list.d/, which by default means the Mint and Ubuntu software repositories and only those, and installs software from there, be it "normal software" or e.g. a Python module such as here. Whatever is available from said repositories, i.e., whatever Mint or Ubuntu has already packaged for you.

dpkg is/interfaces with the package system on your own, local system and need for basic use not often be used directly.There's in fact for basic use little other you need than the above apt-get install and apt-get purge invocations. Together then with possibly apt search to find what you're looking for in the first place. Or, yes, sure, browsing through Software Manager which ends up being very much the same (save Flatpak support as integrated in Software Manager but not apt but that's an entirely new rabbit hole again...)
User avatar
spamegg
Level 14
Level 14
Posts: 5096
Joined: Mon Oct 28, 2019 2:34 am
Contact:

Re: How to check if the python module pyserial is installed?

Post by spamegg »

Fran_3, always use pip for all Python related things. Python modules are provided by PyPI, not Ubuntu. If it happens to be the case that some Python module is in a Ubuntu repository, it's likely out of date.

Even better, use an IDE like PyCharm that allows you to easily setup and use virtual environments that installs Python and all the needed packages for each project, without affecting your system Python.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: How to check if the python module pyserial is installed?

Post by rene »

Quite and quite explicitly disagreed with the above. The exact point of grabbing a certain module from the repositories rather than PyPI is because it pairs with the also from the repositories installed Python interpreter. As said originally as well, sometimes indeed you explicitly want a newer version --- but that is in the case of a repository interpreter the exception and only available if said shiny new module version from PyPI is not in fact in some subtle or nonsubtle manner incompatible with the older repository interpreter.

As also said, when installing your own Python interpreter version and/or when on e.g. Windows, sure --- but then you get to manage those kinds of potential version incompatibilities manually. Mint/Ubuntu has done it for you in the case of their packaged versions.
Locked

Return to “Beginner Questions”