Skip to content Skip to sidebar Skip to footer

Trouble With Pyserial And Multiple Python Installations

I have Python 2.4.4 and 3.1.3 on my Windows 7 machine. I would like to use PySerial. I heard that it was built in, so I tried import serial in both versions. Both caused an Import

Solution 1:

First of all, why are you using python 2.4 on Windows? It is pretty old and things are improved (for e.g. ctypes) and you might need those for pyserial.

Now, coming to your installation question, please don't dabble with PYTHONPATH in order to make the module working for one python version vs. another. Python 3 is backwards incompatible, so you won't get it automatically working for what you install for Python 2.x.

There is a simple set of instructions given in the pyserial website:

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

# This will be suitable for python2.5
python setup.py install


# This is suitable for python3.1
python3 setup.py install

Note that I am using the interpreter python3 in the second case.

Solution 2:

I had a problem similar to yours when I followed the install instructions from the website. Just like it said, I navigated into the unpacked download folder and ran

# This is suitable for python3.1
python3 setup.py install

However, when I ran import serial, I got a similar syntax error:

>>> import serial
Traceback (most recent call last):
  File"<stdin>", line 1, in <module>
  File"serial/__init__.py", line 21, in <module>
    from serial.serialposiximport *
  File"serial/serialposix.py", line 58
    except IOError, e:
                  ^
SyntaxError: invalid syntax

It turns out that you just need to leave the install directory. The download folder has a folder named serial that overrides the newly installed serial module.

Post a Comment for "Trouble With Pyserial And Multiple Python Installations"