…little BITS of our lives.


Well it is time for another easy tutorial on how to install something with python on Windows and that something is pyserial. I am assuming if you are reading this, you already know what pyserial is, but are just having trouble getting it installed with python.

Let me just talk about what problem most people face while performing the install. They get an error like “no python installation found in the registry” and then the installer quits.

To resolve this error, first you need to check whether your windows machine can find the python executable, by which I mean the following:

1. Open up the command prompt and type python.

If you get an error like “python is not recognized as an internal command…bla bla bla…” it means that your     system can not find where your python executable is. We need to solve this issue first and for that we need to set our ‘environment variables‘.

2. So go to Start menu. Right click on computer and select properties. Then go to advanced system properties and select environment variables. Look for the variable ‘Path’, select it and click edit. Python 3.2 is installed in the location ‘C:\Python32‘, so just add this to the path variable.

3. Now close all windows and RESTART your computer. If you don’t restart it, then the changes won’t take place.

4. Now after restarting, to check all if all went well, open the command prompt and then type ‘python‘. What you should get is following:

This prompt tells us that the system can find python executable now. Yay!!! Now we can focus on installing pyserial.

So the next step involves downloading the  file  pyserial-2.6.tar.gz from the pyserial website, extract it and then copy the extracted folder to C:\Python32\Lib\site-packages. Once you are done with that, move to the folder which contains the file ‘setup.py’, using command prompt and enter:

python setup.py install

That’s it!

Have fun with pyserial, and if u have any problems pls post. I will be happy to help! 😀

Advertisements

Comments on: "Installing pyserial on Windows 7 with Python3.2" (68)

  1. Thanks!
    It has been a few years since using Python, rather than Java and C++
    Trying my old Python apps that required Pyserial was a real problem on Win7.
    Followed your instructions and now works OK.

  2. Hi,

    Thanks for your post on installing pyserial.I have a problem installing it.I followed your instructions.But when I gave the command on cmd window.I am getting following error

    File “”, line 1
    cd c:\Python32\Lib\site-packages\pyserial-2.6

    Can you tell me where have i gone wrong?

    Thx
    Sreeni

    • Hi Sreeni,
      Sry for the late reply. 🙂

      The error message you posted doesn’t make things very clear.
      If you provide me with the steps you took till u get that error, may be I can reproduce it and help.

      From what I can make out, your error may be because:

      1. You don’t have or not working in python3.
      2. Or you didn’t move the downloaded file to the location ‘C:/Python32/Libs/site-packages’

      In the latter case, copy the downloaded file to the given location. Then extract it, either from the terminal or using winrar, whatever u prefer :).

      After that, u can proceed.

      Let me know if this helped, or whatever error u get.

      You can upload the error message in the terminal window, to any image uploading site, and provide me the link here too :).

      Have fun!

  3. Thank you very much installed pyserial 2.6 in python 3.3 and cmd prompt recognizes it ;D

  4. Perfect! Thanks for the easy to follow tut

  5. Christian V said:

    Hi,

    Thanks for your tutorial. I downloaded the package, decompressed it, moved it to Python33 (I have Python 3.3) and was able to download it with python setup.py install. However, I’m trying to use a program (not written by me) to connect my computer to a barcode reader. In the code the command “import serial” is used, and after downloading the serial modules like you explained I run the code and it gives the error “ImportError: No module named serial”.

    Any ideas on why is this happening? I’m very new to python and have been trying to work around it to make this code work. Thanks in advance.

    • Hi Christian,
      As the error message states, your python is probably yet not aware of the pyserial installation.

      What happens when you use the following statement on the python prompt instead of a program?
      “import serial”

      If the same error message comes, I recommend a fresh install and restart.

      Also do you have any other version of python along side python 3.3?

      If error still occurs, pls post a pastebin or imagebin log of what you are doing. It will be easier to understand the problem for me then.

      Cheers,
      Abhijit

      • Thank you for your reply.
        I am not in my other computer at the moment but I do indeed have both python 2.3 and 3.3. Could this be the problem? I’m not sure on how to uninstall it beside deleting the Python23 folder in C: or using Windows uninstall program in the control panel. I will post a imagebin when I can. Thanks

  6. Super 😀

  7. Hi i have problems in stalling pyserial. Whenever i tried typing python setup.py install it keeps telling me this “python: cant open file ‘setup.py’ : [Errno 2] no such file or directory.

    PS i have installed pyton 3.2

    • Hi Jaron!
      It might not seem an obvious mistake, but when u run the command( type: python setup.py install ), are you doing it from the same directory where your “setup.py” file resides.

      If not, you have to move to the folder containing “setup.py”, using ‘cd’ command.
      For example: cd C:\Python32\Libs\site-packages\pyserial-2.6 can work, depending on how you copied the extracted folder.

      Hope this helps,
      abhijit 🙂

      • how would i know if i am doing it right in the same directory?
        Pardon on being lost at this move but what do you mean by moving to the folder containing “setup.py” using the “cd” command.

  8. Hi Jaron,

    Let’s say I have a folder named “games” on my desktop which contains a program called “angry_birds.exe” (yup! I like this game 🙂 ). Anyway, if i want to run “angry_birds.exe”, what I should do is go inside the “games” folder and double click on the icon for the angry birds game.

    Similarly, what we are trying to do here is to run a program called ‘setup.py’, but this time from the command prompt. So rather than double -clicking stuff, we move to that folder using the “cd” command.
    Once we are in that folder where “setup.py” file is, all that is needed is to run it using the following:

    python setup.py install

    So, to summarise:

    1. After downloading the pyserial file, extract it and move it to C:/Python32/Lib/site-packages. ( You can use copy and paste folder )

    2. Now open the windows command prompt, and using the following command move to the folder just copied.

    cd C:/Python32/Lib/site-packages/pyserial-2.6

    A quick ‘dir’ command will show the list of all files inside that folder. ‘setup.py’ should be one of them.

    3. Run: python setup.py install and job done!

    I hope this clears things out a little better. If you are still having problems, let me know and I will try to help.

    Cheers,
    Abhijit

    • Hi! I’m trying to install pyserial on Windows 7 64bit with Python 2.7.

      Do I copy the entire unzipped folder of pyserial-2.6.tar to the site-packages file? When I extract the pyserial-2.6.tar folder, I cannot find setup.py. I cannot find setup.py anywhere in any folders inside Python27 folder or the extracted folder. Where do I get the setup.py file?

      • Hi!
        Yes, the whole extracted folder gets copied into ‘site-packages’.

        setup.py should be inside this extracted folder, strange it’s not there for ur copy. Can you post the contents of ‘pyserial-2.6’, i.e. the extracted folder?

        Don’t waste time looking for it in the python27 directory, it comes with the pyserial download, as it’s meant to install pyserial with ur python. 🙂

        Thanks,
        Abhijit

  9. I can use this in Windows 8 too?

    • Hi Bruno!
      I personally haven’t tried that, but it should work just fine. ( windows is too expensive for me to buy another one of them 🙂 🙂 )

      Give it a try and if you run into any problems, let me know.

  10. Hi, thanks for the tutorial, very helpful. I am on windows 7 and python33. I (neoNewbie) was stuck on this part for three hours “Once you are done with that, move to the folder which contains the file ‘setup.py’” (a) I didn’t know how to “move” to the folder (b) there is no file directly named ‘setup.py’ but there is a file called ‘setup’ which is a python file. For (a) I searched online and found this useful:”Shift + right click on the folder containing your module (I’m working in Windows 7)”, when the menu shows up, select “Open command window here”. Clicked that and I got this in the command console ” C:\Python33\Lib\site-packages\pyserial-2.6>” in my computer. At prompt type this “python setup.py install”, press enter and voila! This is for %Newbies, disregard if you are not, but I do appreciate all the discussions up here.

    • Hi Davish! the ‘.py’ in ‘setup.py’, is the file extension for the ‘setup’ file. Depending on how you have set your folder options, it either displays, or as in case of your OS, it doesn’t. 🙂

      But, I think the default setting is to hide the extensions for the file name. Thanks for pointing that out, could help some.

      Point (a) in ur post is a welcome addition to my little knowledge of windows 🙂 ty

  11. I don’t understand what i have to do after unzip. I put that at Python’s folder and install by prompt but nothing work. It’s appears: Traceback(most recent call last):
    File “C:\python33\setup.py”, line 44, in (module)
    open <os.patch.join('serial', '_init_.py')).read()).group(1)
    FileNotFoundError [Errno 2] No such file or directory: 'serial \\_init_.py'

    You know what can be this??

    • Hi Bruno,

      I do not have win 8 atm, so I can’t try it out, however I can definitely point out the reason behind this error you are getting. Hopefully that will enable you to solve the problem.

      The way this works is following:

      When you unzip the pyserial-2.6.tar.gz, it creates a directory ‘pyserial-2.6’ which contains a bunch of files and other directories, one of which is a directory named ‘serial’. Inside this directory, there is a file called ‘__init__.py’, which your system can not find.

      This among other things, can mean that an error occured during extraction, or you didn’t copy the entire pyserial folder inside of C:\Python33\Lib\site-packages.

      It also looks like that you typed the error log rather than copy/pasting it ( which is not recommended 🙂 ), as from the error log it appears that you tried to run the ‘setup.py’ script, from outside the pyserial folder. In that case, the error above will obviously occur, since it can’t find the required files to properly install.

      Here’s what I recommend:

      1. After unzipping and copying the pyserial folder to ‘C:\Python33\Lib\site-packages’, double click to go inside that folder. Then, make sure that you see the ‘serial’ folder and ‘setup.py’ there among other things.
      2. Shift + right click and choose ‘Open command window here’ and then use python setup.py install

      If this helped, let me know 🙂

  12. i am getting
    C:\Python33>python setup.py install
    running install
    running build
    running build_py
    creating build
    error: could not create ‘build’: 5

    what’s error 5?

    • Hi Sam,
      Can you post the steps you took, so that I can reproduce this error.
      I tried this on a windows machine with python33 and the installation worked just fine.

      • noblemen998@yahoo.com said:

        I followed exact steps on the web page

        Have a nice day!

      • noblemen998@yahoo.com said:

        Not sure if anti virus has something to do with it

        Have a nice day!

      • Despite my limited understanding of Windows and it’s strange ways, I am fairly sure the antivirus has got nothing to do with it.

        Though one reason for the ‘build’ to fail, might be some files missing from the pyserial folder which are required for compiling it.
        I think you should give it another go, since it works fine for most people, and make sure you copy the entire pyserial folder into Python33/Lib/site-packages.

        If you solve it in any other way, please let us know.
        Thank you!

      • noblemen998@yahoo.com said:

        Thanks , got it working, zip file got corrupted

        Have a nice day!

  13. open command prompt.. and navigate in to…C:\Python33\Lib\site-packages\pyserial-2.6
    Disable Antivirus..
    type python setup.py install…

    Worked for me
    Thanks

  14. wow we are certainly whipping a dead horse here. I am having trouble with the install aswell. under windows 7 with 2.7 and 3.3 installed. I can install for 2.7 no problems. but I cannot get it to install for 3.3 it errors complaining about syntax. without specifying python 3.3, it will install fine from the python33 directory into the python27 folder.

    C:\Python33\libs\pyserial-2.6>py -3 setup.py install
    running install
    running build
    running build_py
    running build_scripts
    running install_lib
    byte-compiling C:\Python33\Lib\site-packages\serial\rfc2217.py to rfc2217.cpython-33.py
    c
    File “C:\Python33\Lib\site-packages\serial\rfc2217.py”, line 372
    except Exception, msg:
    ^
    SyntaxError: invalid syntax

    This is followed by about a dozen more syntax errors.
    Any ideas?

    • Hi,
      Sorry for the late reply.

      Please check the following things:
      1. Python3.3 is added to your environment variables. ( You can choose this while installing or do it later)

      2. pyserial is a 3rd party package, so the ideal location for installing it is in the ‘site-packages’ folder. You can find this inside,

      C:\Python33\Lib\. From what I see, you are installing it inside the ‘libs’ directory. May be that’s what throws these errors.

      So, I recommend to try installing it in the ‘site-packages’ directory. I tried to install it again, today, and it worked just fine for me.

      Let me know if the installation worked or not. Also, it would be helpful to see a few more of those error messages that you were getting to work out what is going wrong.

      Best regards,
      Abhijit

      • found out what to do. despite the instructions, I had to run the 2to3 script on the whole pyserial distribution. only then would it build and install without errors.

  15. I continuously get a syntax error at the point where I type ‘python setup.py install’
    It reads:
    SyntaxError: invalid syntax
    >>>python setup.py install
    File “”, line 1
    python setup.py install
    ^
    I really have no idea why that shows up. Any ideas or suggestions?

  16. EXCELLENT!! Thanks 🙂

  17. Dude, I had an earlier project running Linux and Python and Pyserial and it all just worked from the git-go. Now I’ve been trying to get Pyserial to work on Windows after a really long time trying to get it going on Ubuntu 13.04 which never worked and probably never will. (It gets lost somewhere in the upgrade from Python 2.X to 3.X and in the fact that Ubuntu is written in and needs both Pythons. Cute, huh?) So now over in Windows I have a “supposed” Windows installer that doesn’t work and the only option is to go down a long list of steps including opening a file using a tool (7zip) that promises to put a lot of shitware in my computer that’s going to take hours to remove. So I just have to say–is it really fucklng worth it? If the people who wrote Pyserial have given up on their module and no longer update it, shouldn’t we just say that Python doesn’t support serial ports anymore and move on. I think it’s time to go find another software for stuff like that.

    Terry G

  18. Thank you for this tutorial. After following the instructions carefully INCLUDING installing in ‘site-packages’ folder and running the setup from there, I can now start to use pyserial.

  19. After an apparently successful installation, I have not been successful even opening a USB port.

    I have seen simple code in stackoverflow using pyserial in USB ports with Python 3.3 but I can’t get this to work on my new installation of pyserial 2.7 [in Windows 7, 64 bit, with 3 USB ports]. Installation of pyserial went smoothly, I can import without error and methods are recognized in the Pyscripter IDE which boosts confidence in a good installation, however:

    The code stripped down to its error producing essentials is:

    import serial
    def main():
    ser = serial.Serial(port=’COM2′)
    ser.close()

    if __name__ == ‘__main__’:
    main

    From this I receive a dialog box with the error “SerialException: could not open port ‘COM2′: FileNotFoundError(2,’The system cannot find the file specified.’,None,2)”

    The Traceback states:

    *** Remote Interpreter Reinitialized ***
    >>>
    Traceback (most recent call last):
    File “”, line 420, in run_nodebug
    File “C:\Python33\Lib\site-packages\scanport2.py”, line 19, in
    main()
    File “C:\Python33\Lib\site-packages\scanport2.py”, line 15, in main
    ser = serial.Serial(port=’COM2′)
    File “C:\Python33\Lib\site-packages\serial\serialwin32.py”, line 38, in __init__
    SerialBase.__init__(self, *args, **kwargs)
    File “C:\Python33\Lib\site-packages\serial\serialutil.py”, line 282, in __init__
    self.open()
    File “C:\Python33\Lib\site-packages\serial\serialwin32.py”, line 66, in open
    raise SerialException(“could not open port %r: %r” % (self.portstr, ctypes.WinError()))

    serial.serialutil.SerialException: could not open port ‘COM2’: FileNotFoundError(2, ‘The system cannot find the file specified.’, None, 2)

    And the code segment in the imported module which raises the SerialException is:

    # the “\\.\COMx” format is required for devices other than COM1-COM8
    # not all versions of windows seem to support this properly
    # so that the first few ports are used with the DOS device name
    port = self.portstr
    try:
    if port.upper().startswith(‘COM’) and int(port[3:]) > 8:
    port = ‘\\\\.\\’ + port
    except ValueError:
    # for like COMnotanumber
    pass
    self.hComPort = win32.CreateFile(port,
    win32.GENERIC_READ | win32.GENERIC_WRITE,
    0, # exclusive access
    None, # no security
    win32.OPEN_EXISTING,
    win32.FILE_ATTRIBUTE_NORMAL | win32.FILE_FLAG_OVERLAPPED,
    0)
    if self.hComPort == win32.INVALID_HANDLE_VALUE:
    self.hComPort = None # ’cause __del__ is called anyway
    raise SerialException(“could not open port %r: %r” % (self.portstr, ctypes.WinError()))

    I do have an active device connected to COM2 as identified in the Windows device manager. I also have tried scanning all the ports, but the code stops on the first use of serial.Serial

    This appears that something may be going on with win32?

    I am a newbie for interfacing Python with hardware. Any suggestions?

    Thank you and happy new year!

  20. Copied from CMD:

    ” error: package directory ‘serial’ does not exist ”

    What is going on?

    Can anyone help me?

    • Hi!

      Can you post at what stage of the installation did you get this error?
      At a first look it seems you didn’t copy the extracted pyserial folder into site-packages directory.
      The directory named serial will be inside this folder.

  21. benjamin said:

    Hi
    I’m tying to install pyserial on window 7. I have the following error while installing:
    C:\21.Phyton\pyserial-2.7.tar\dist\pyserial-2.7\pyserial-2.7>python
    tall
    Detected Python 3, using 2to3
    C:\Python34\lib\distutils\dist.py:260: UserWarning: Unknown distrib
    ‘use_2to3’
    warnings.warn(msg)
    running install
    running build
    running build_py
    running build_scripts
    running install_lib
    running install_scripts
    running install_egg_info
    Removing C:\Python34\Lib\site-packages\pyserial-2.7-py3.4.egg-info
    Writing C:\Python34\Lib\site-packages\pyserial-2.7-py3.4.egg-info

    C:\21.Phyton\pyserial-2.7.tar\dist\pyserial-2.7\pyserial-2.7>

    if I start python and do the import I get the following errors:

    Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:24:06) [MSC v.1600 32 bit (In
    tel)] on win32
    Type “help”, “copyright”, “credits” or “license” for more information.
    >>> import serial
    Traceback (most recent call last):
    File “”, line 1, in
    File “”, line 2214, in _find_and_load
    File “”, line 2203, in _find_and_load_unlocked
    File “”, line 1191, in _load_unlocked
    File “”, line 1161, in _load_backward_compatible
    File “C:\Python34\lib\site-packages\pyserial-2.7-py3.4-win32.egg\serial\__init
    __.py”, line 19, in
    File “”, line 2214, in _find_and_load
    File “”, line 2203, in _find_and_load_unlocked
    File “”, line 1191, in _load_unlocked
    File “”, line 1161, in _load_backward_compatible
    File “C:\Python34\lib\site-packages\pyserial-2.7-py3.4-win32.egg\serial\serial
    win32.py”, line 12, in
    File “”, line 2214, in _find_and_load
    File “”, line 2199, in _find_and_load_unlocked
    File “”, line 2141, in _find_spec
    File “”, line 1917, in find_spec
    File “”, line 1893, in _get_spec
    File “”, line 1874, in _legacy_get_spec
    File “”, line 863, in spec_from_loader
    File “”, line 904, in spec_from_file_location
    File “C:\Python34\lib\site-packages\pyserial-2.7-py3.4-win32.egg\serial\win32.
    py”, line 196
    MAXDWORD = 4294967295L # Variable c_uint
    ^
    SyntaxError: invalid syntax
    >>>

    Can anyone help?

  22. I have python 3.3.3 on windows 7 I type python in command and get `python` is not recognized as an internal or external command operable program or batch file. Can u help ples thanks

    • Hi Luke,
      Sorry for the late reply!

      I hope the issue you were having, is resolved by now.

      But, just in case,,,

      You get this message because python is not present in your system’s path. To be able to run python from anywhere on your computer, add the location of the python executable into your system path. You can find it by right clicking on computer in the start menu, and going to enviroment variables.

      Let me know if it helped.

    • Is the python install in your path and/or are you invoking python from the directory it is install in?

  23. Hello, Thank you for the nice tutorial, I’m in the process of getting the components together so that I can try to replicate your application and I have a simple question for you, Can I use python 2.6 0r 2.7 or does it have to be 3.2?
    Looking forward to hearing from you soon!

    Cheers

    • Hi,
      Yes, you can use python2.6 or 2.7. You will need to provide the proper path variable in step 2.

      Pyserial can be installed with ‘pip’ as well for python2.6+ ( i think ).

      Best,
      Abhijit

  24. Hi All,

    I am new to Python.
    And I am trying to use read and write modbus using Pymodbus Python package.
    I am using Python 3.2

    Can anyone guide me how to install Pymodbus in my Python 3.2
    Thanks in advance.

  25. Okay, so when I clicked on “Start menu” it only came up with two options: Programs and desktop.ini. I right clicked both of them and did not see anything about “Path”??

    Any ideas on this? (Sorry, I’m new at this ouo)

  26. Rakshak R.Hegde said:

    If PiPy is installed, you can also install pyserial by typing the following in command line:
    pip install pyserial
    For more info go to: http://pyserial.sourceforge.net/pyserial.html#from-pypi

  27. thanks for the tut! was a saviour!

  28. cagdasakalin said:

    I’ve followed the installation procedure you suggested but, at the end, I got the message in command prompt, showing an syntax error.

    What I enter in command prompt is

    >>> python setup.py install

    Then the message in the command prompt is the following;
    ——————————————-

    File “”, line1
    python setup.py install

    SyntaxError: invalid syntax

    ——————————————-

    By the way I installed the version of “python-3.2.amd64” for Win 7 64-bit operating system, and also copied the files within “pyserial-2.6.tar.gz” to the location C:\Python32\Lib\site-packages. I am sure from that I followed the whole story but it failed at the end.

    Could you please give your suggestion for repairing the point that I am stuck with?

  29. cagdasakalin said:

    ——————————————-

    File “”, line1
    python setup.py install

    SyntaxError: invalid syntax

    ——————————————-

    In above part of my message the word inside ” ” is not appeared, this is why I am writing this message. What I have inside ” ” is .

  30. cagdasakalin said:

    I do not understand why what I am writing is not appearing here but the the thing inside the quotation mark is between the angle brackets stdin .

  31. Hello, i have followed your intructions (I’m using windows 8, and i installed Pyserial 3.5) but i have a problem. After i have pasted the pyserial folder to python/python 35-32/Lib/site-packages, and type python setup.py install on the prompt commander, i get the error saying syntaxerror: invalid syntax. How can i fix this?

    Thanks.

  32. hola amigo, ya segui todos pasos y al parecer si se instalo el py.serial, pero tengo una duda, lo que quiero es que se enlace arduino y segui un tutorial e hice exactamente todo lo que me pidio pero cuando le doy Run a python me aparece este msj:

    Traceback (most recent call last):
    File “C:\Users\Javier R’Marro\Desktop\pyhton alarma\import time.py”, line 12, in
    ser = serial.Serial(‘COM3’, 9600)
    File “C:\Python27\lib\site-packages\serial\serialwin32.py”, line 38, in __init__
    SerialBase.__init__(self, *args, **kwargs)
    File “C:\Python27\lib\site-packages\serial\serialutil.py”, line 282, in __init__
    self.open()
    File “C:\Python27\lib\site-packages\serial\serialwin32.py”, line 66, in open
    raise SerialException(“could not open port %r: %r” % (self.portstr, ctypes.WinError()))
    SerialException: could not open port ‘COM3’: WindowsError(2, ‘El sistema no puede encontrar el archivo especificado.’)

  33. Thanks! Pretty straight forward!

  34. Thank you very much for the wonderful
    tutorial

  35. Hi, i’ve followed the whole setup instructions but got stuck at the last bit with pyserial. When i open up the setup.py file, the command box open only for a second and then dissapears, so i cant type in the last install command. Any chance u know how to fix that?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: