Python install serial linux

No module named serial

and I got a question when I run my Python code. I installed Python 2.7 on Windows 7, bit 64. I got an error «No module named serial» when I compiled my code:

import serial ser = serial.Serial("COM5", 9600) ser.write("Hello world") x = ser.readline() print(x) 

I tried many ways to crack this problem, such as installed Canopy to setup virtual environment, make sure ‘pip’ is there, no Python v 3.x installed. But still cannot get it out. Any advice would be appreciated.

11 Answers 11

Serial is not included with Python. It is a package that you’ll need to install separately.

Since you have pip installed you can install serial from the command line with:

Or, you can use a Windows installer from here. It looks like you’re using Python 3 so click the installer for Python 3.

Then you should be able to import serial as you tried before.

You must pip install pyserial first.

The above commands will index it with system interpreter.

You must have the pyserial library installed. You do not need the serial library.Therefore, if the serial library is pre-installed, uninstall it. Install the pyserial libray. There are many methods of installing:-

  1. pip install pyserial
  2. Download zip from pyserial and save extracted library in Lib>>site-packages folder of Python.
  3. Download wheel and install wheel using command: pip install

After installing Pyserial, Navigate to the location where pyserial is installed. You will see a «setup.py» file. Open Power Shell or CMD in the same directory and run command » python setup.py install «. Now you can use all functionalities of pyserial library without any error.

@indymx Can you please confirm whether the pip (you used for installing pyserial) is for python x version (which you are using to compile your code)

In my case the command below did the job

cd /opt sudo tar -xvf ~/Downloads/pyserial-3.2.1.tar.gz -C . cd /opt/pyserial-3.2.1 sudo python setup.py install 
sudo apt install python-serial python3-serial 

Solved it, using it for esp32

Читайте также:  Bin исполняемый файл linux

I had this same problem multiple times but finally found solution.

I had multiple Python versions installed. Like in Raspberry Pi there was Python3.5 installed and I installed also 3.9.2 without uninstalling 3.5. Then I installed pyserial with pip and tried my program. No module. But the reason was that the linux symbolic link in python3 pointed to python3.9.2 version but pip3 pointed to python3.5. So pyserial was installed in python3.5 and understandably was not found when run python3.9.2. Then I changed symbolic link in pip3 to right version and voila, everything works fine!

  1. Firstly uninstall pyserial using the command pip uninstall pyserial
  2. Then go to https://www.lfd.uci.edu/~gohlke/pythonlibs/
  3. download the suitable pyserial version and then go to the directory where the file is downloaded and open cmd there
  4. then type pip install «filename»(without quotes)

Happened to me. Something was broken. All the solutions presented didn’t work.

sudo pip install serial Requirement already satisfied: serial in /usr/local/lib/python3.8/dist-packages (0.0.97)

sudo pip3 install serial Requirement already satisfied: serial in /usr/local/lib/python3.8/dist-packages (0.0.97)

Same for pyserial, it was already installed.

Solution: I replaced the symbolic link /usr/bin/python to use python3 instead of python2.

Источник

pySerial¶

This module encapsulates the access for the serial port. It provides backends for Python running on Windows, OSX, Linux, BSD (possibly any POSIX compliant system) and IronPython. The module named “serial” automatically selects the appropriate backend.

It is released under a free software license, see LICENSE for more details.

Copyright (C) 2001-2020 Chris Liechti

Features¶

  • Same class based interface on all supported platforms.
  • Access to the port settings through Python properties.
  • Support for different byte sizes, stop bits, parity and flow control with RTS/CTS and/or Xon/Xoff.
  • Working with or without receive timeout.
  • File like API with “read” and “write” (“readline” etc. also supported).
  • The files in this package are 100% pure Python.
  • The port is set up for binary transmission. No NULL byte stripping, CR-LF translation etc. (which are many times enabled for POSIX.) This makes this module universally useful.
  • Compatible with io library
  • RFC 2217 client (experimental), server provided in the examples.
Читайте также:  What linux distribution to use

Requirements¶

  • Python 2.7 or Python 3.4 and newer
  • If running on Windows: Windows 7 or newer
  • If running on Jython: “Java Communications” (JavaComm) or compatible extension for Java

For older installations (older Python versions or older operating systems), see older versions below.

Installation¶

This installs a package that can be used from Python ( import serial ).

To install for all users on the system, administrator rights (root) may be required.

From PyPI¶

pySerial can be installed from PyPI:

python -m pip install pyserial 

Using the python / python3 executable of the desired version (2.7/3.x).

Developers also may be interested to get the source archive, because it contains examples, tests and the this documentation.

From Conda¶

pySerial can be installed from Conda:

conda install pyserial or conda install -c conda-forge pyserial 

Currently the default conda channel will provide version 3.4 whereas the conda-forge channel provides the current 3.x version.

From source (zip/tar.gz or checkout)¶

Download the archive from http://pypi.python.org/pypi/pyserial or https://github.com/pyserial/pyserial/releases. Unpack the archive, enter the pyserial-x.y directory and run:

Using the python / python3 executable of the desired version (2.7/3.x).

Packages¶

There are also packaged versions for some Linux distributions:

  • Debian/Ubuntu: “python-serial”, “python3-serial”
  • Fedora / RHEL / CentOS / EPEL: “pyserial”
  • Arch Linux: “python-pyserial”
  • Gentoo: “dev-python/pyserial”

Note that some distributions may package an older version of pySerial. These packages are created and maintained by developers working on these distributions.

References¶

Older Versions¶

Older versions are still available on the current download page or the old download page. The last version of pySerial’s 2.x series was 2.7, compatible with Python 2.3 and newer and partially with early Python 3.x versions.

pySerial 1.21 is compatible with Python 2.0 on Windows, Linux and several un*x like systems, MacOSX and Jython.

On Windows, releases older than 2.5 will depend on pywin32 (previously known as win32all). WinXP is supported up to 3.0.1.

© Copyright 2001-2020, Chris Liechti Revision 31fa4807 .

Versions latest stable Downloads pdf html epub On Read the Docs Project Home Builds Free document hosting provided by Read the Docs.

Читайте также:  Steam goes to linux

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Python serial port access library

License

pyserial/pyserial

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

docs: \n was not in inline mode, causing the backslash to be escaped

Git stats

Files

Failed to load latest commit information.

README.rst

This module encapsulates the access for the serial port. It provides backends for Python running on Windows, OSX, Linux, BSD (possibly any POSIX compliant system) and IronPython. The module named «serial» automatically selects the appropriate backend.

BSD license, (C) 2001-2020 Chris Liechti

For API documentation, usage and examples see files in the «documentation» directory. The «.rst» files can be read in any text editor or being converted to HTML or PDF using Sphinx. An HTML version is online at https://pythonhosted.org/pyserial/

Examples and unit tests are in the directory examples.

pip install pyserial should work for most users.

Detailed information can be found in documentation/pyserial.rst.

The usual setup.py for Python libraries is used for the source distribution. Windows installers are also available (see download link above).

To install this package with conda run:

conda install -c conda-forge pyserial

conda builds are available for linux, mac and windows.

Источник

Оцените статью
Adblock
detector