1

So I am trying to setup the code on my Raspberry Pi 3 Model B so make it so it can read and write from a Serial Port. I installed Python 2 and 3 versions of PySerial with:

sudo apt-get install python3-serial
sudo apt-get install python-serial

So I should have the most up to date versions of PySerial installed correctly? Well when I was running my code I was just trying to output the port settings with:

print(port.get_settings())

Which when I run the module gives me the error:

AttributeError: 'Serial' object has no attribute 'get_settings()'

So I went and changed the code to the old name for the method:

print(port.getSettingsDict)

And this worked. So obviously I don't have the newest version of PySerial on my Pi. So I went to do the install again and was told I already have the newest version on my Pi. However, I can obviously tell I don't because of the errors I am getting.

So how would I go about fixing this? Am I just not making the correct terminal calls to install PySerial?

2

As you have found the version available in the APT repositories are not always the most up to date.

You can use pip to install a newer version with the following command:

pip install pyserial

Note: You may need to run the above command with the following options:

sudo pip install --upgrade pyserial

or download the archive:

wget https://pypi.python.org/packages/8d/88/cf848688ae011085a6da5a470740dafa3a4b105f84a5f79c3b720c19279c/pyserial-3.3.tar.gz#md5=6afe4c2e47bcec6eb7051b8c1ce19d52

Unpack the archive:

tar -xzf pyserial-3.3.tar.gz

enter the pyserial-3.3 directory:

cd pyserial-3.3

and run:

python setup.py install

for Python 2.x

or:

python3 setup.py install

For Python 3.x.

Note: You may need to remove the older packages you installed using apt first. You can remove them with the following commands:

sudo apt-get remove python-serial
sudo apt-get remove python3-serial
  • Where is the pyserial-x.y directory? – Skitzafreak Jun 22 '17 at 13:30
  • @Skitzafreak It will be in the directory where you downloaded and extracted the source file see above edits. The pip method is easier. – Steve Robillard Jun 22 '17 at 13:35
  • SoI ran the upgrade through pip, and after running print(serial.VERSION) I am still being shown that my PySerial version is 2.6 – Skitzafreak Jun 22 '17 at 13:59
  • I get 3.3 did you use sudo amd the upgrade flag? Are you doing this in Python 2 or 3 – Steve Robillard Jun 22 '17 at 14:01
  • 1
    Hello and welcome, @Skitzafreak. Please take the tour and visit the helpcenter to see how things work here. Note that upvoting and/or accepting a helpful answer is the Raspberry Pi way of saying thank you. – Ghanima Jun 23 '17 at 21:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.