How to install Pyserial

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aj7777
    New Member
    • May 2010
    • 5

    How to install Pyserial

    I'm trying to install (& run) Pyserial but I'm failing big time.
    I unpacked the files and put them in a folder I made.
    C:\Python\Pyser ial

    I went to the directory in the command prompt and typed.
    python setup.py install.

    I thought I was good but I get this error.
    Import error: No module named serial.

    I read this thread and installed the windows extensions.

    No effect. I've read people talking about setting the access in PYTHONPATH, but I have no idea how to do that. I also downloaded the "easy installer".

    Unfortunately, I don't know how to install (or run) the easy installer. (I tried running "python setup.py install", but an error message came up.)

    Any suggestions?

    AJ
  • Glenton
    Recognized Expert Contributor
    • Nov 2008
    • 391

    #2
    You'll need to tell us what error messages come up. It's conceivable that python itself isn't in your path. I don't use windows, and it's probably different for different flavours, but from memory, you can go to computer, right-click, properties, system, advanced, environment variables. There's a system variable called path. This is a list of places where windows goes to look when you run a program. The python path needs to be in there. So you can edit the variable, go to the end of what's there already, add a ";" and then add more paths.

    If this doesn't work, please give us more details about the errors, your operating system, and the python installation.

    Comment

    • aj7777
      New Member
      • May 2010
      • 5

      #3
      I checked the path as you said. Sure enough, it listed
      ;C:\python22;

      I changed it to the new version.
      ;C:\python26;

      Then I reinstalled pyserial from the command prompt with
      python setup.py install

      I ran my simple program. The "No module name serial" error is gone.

      Instead, I'm getting a new error. Can I pick your brain once more?

      This is my error message:
      IDLE 2.6.5 ==== No Subprocess ====
      >>>
      Traceback (most recent call last):
      File "C:\Python26\An dy\serial_test. py", line 6, in <module>
      ser.open()
      File "C:\Python26\li b\site-packages\serial \serialwin32.py ", line 56, in open
      raise SerialException ("could not open port %s: %s" % (self.portstr, ctypes.WinError ()))
      SerialException : could not open port COM2: [Error 2] The system cannot find the file specified.
      >>>

      It said it cannot open COM2. This is odd because I'm trying to use COM1 in my test program. I know from Device Manager that COM1 is my computer's serial port. My program is listed below.

      Code:
      import serial
      ser = serial.Serial()
      ser.baudrate = 9600
      ser.port = 1
      ser
      ser.open()
      ser.write("hello") #write a string
      ser.close()
      What am I doing wrong?

      My computer is running Windows XP.

      AJ

      Comment

      • Glenton
        Recognized Expert Contributor
        • Nov 2008
        • 391

        #4
        What do you have plugged into your serial port? If nothing, then try making a loop back (you'll have to look it up, but basically you just stick a wire into two of the sockets), and see if that works. You should then also be able to read the hello of the same port!

        Comment

        • aj7777
          New Member
          • May 2010
          • 5

          #5
          My serial port is connected into the serial port of a laptop computer. I'm running a terminal program (NMITerm) so I can see the output on the screen. I have NMITerm setup with the baud setting listed in the code (9600).

          Nothing appears on the laptop screen when I run the code above.

          Comment

          • Glenton
            Recognized Expert Contributor
            • Nov 2008
            • 391

            #6
            Originally posted by aj7777
            My serial port is connected into the serial port of a laptop computer. I'm running a terminal program (NMITerm) so I can see the output on the screen. I have NMITerm setup with the baud setting listed in the code (9600).

            Nothing appears on the laptop screen when I run the code above.
            That sounds a bit beyond me, I'm afraid. But trying the loopback will at least help you diagnose where the problem lies.

            Comment

            • aj7777
              New Member
              • May 2010
              • 5

              #7
              So the code listing looks OK?

              I'll try the loopback. Thanks.

              Comment

              • aj7777
                New Member
                • May 2010
                • 5

                #8
                wrong port

                I got the program to work. I was trying to open the wrong port.

                Code:
                ser.port =1
                refers to COM2, not COM1.

                When I changed my code to

                Code:
                import serial
                ser = serial.Serial()
                ser.baudrate = 9600
                ser.port = 0 # COM1
                ser.open()
                ser.write("hello") #write a string
                ser.close()
                my laptop monitoring COM1 received the "hello".

                Comment

                • ConorD
                  New Member
                  • Oct 2013
                  • 1

                  #9
                  Originally posted by aj7777
                  I checked the path as you said. Sure enough, it listed
                  ;C:\python22;

                  I changed it to the new version.
                  ;C:\python26;

                  Then I reinstalled pyserial from the command prompt with
                  python setup.py install

                  I ran my simple program. The "No module name serial" error is gone.

                  Instead, I'm getting a new error. Can I pick your brain once more?

                  This is my error message:
                  IDLE 2.6.5 ==== No Subprocess ====
                  >>>
                  Traceback (most recent call last):
                  File "C:\Python26\An dy\serial_test. py", line 6, in <module>
                  ser.open()
                  File "C:\Python26\li b\site-packages\serial \serialwin32.py ", line 56, in open
                  raise SerialException ("could not open port %s: %s" % (self.portstr, ctypes.WinError ()))
                  SerialException : could not open port COM2: [Error 2] The system cannot find the file specified.
                  >>>

                  It said it cannot open COM2. This is odd because I'm trying to use COM1 in my test program. I know from Device Manager that COM1 is my computer's serial port. My program is listed below.

                  Code:
                  import serial
                  ser = serial.Serial()
                  ser.baudrate = 9600
                  ser.port = 1
                  ser
                  ser.open()
                  ser.write("hello") #write a string
                  ser.close()
                  What am I doing wrong?

                  My computer is running Windows XP.

                  AJ
                  ser.port = 1 = open serial port TWO
                  0 - port 1
                  1 - port 2
                  2 - port 3

                  Comment

                  Working...