title: Trouble with PySerial and multiple Python installations
body: <p>I have Python 2.4.4 and 3.1.3 on my Windows 7 machine. I would like to use PySerial.</p>
  
  <p>I heard that it was built in, so I tried <code>import serial</code> in both versions. Both caused an <code>Import Error</code>. </p>
  
  <p>Then I downloaded the win32 installer from <a href="http://pypi.python.org/pypi/pyserial" rel="nofollow">this page</a>. I ran it, and it installed for 2.4.4. (It said it found it from the registry.) I had no option to change to the 3.1.1 version.</p>
  
  <p>I then got the following error in 2.4.4:</p>
  
  <pre><code>&gt;&gt;&gt; import serial
  
  Traceback (most recent call last):
    File "&lt;pyshell#0&gt;", line 1, in -toplevel-
      import serial
    File "C:\Python24\Lib\site-packages\serial\__init__.py", line 19, in -toplevel-
      from serialwin32 import *
    File "C:\Python24\Lib\site-packages\serial\serialwin32.py", line 11, in -toplevel-
      import ctypes
  ImportError: No module named ctypes
  </code></pre>
  
  <p>I look up <code>ctypes</code>, and see that it has been bulit in since 2.5.5. Ok.</p>
  
  <p>I download <code>ctypes</code>, and run <code>python setup.py install</code>. (2.4.4.)</p>
  
  <p>I get the following:</p>
  
  <pre><code>C:\path\to\ctypes-1.0.2&gt;python setup.py install
  running install
  running build
  running build_py
  running build_ext
  error: Python was built with Visual Studio 2003;
  extensions must be built with a compiler than can generate compatible binaries.
  Visual Studio 2003 was not found on this system. If you have Cygwin installed,
  you can try compiling with MingW32, by passing "-c mingw32" to setup.py.
  </code></pre>
  
  <p>Sweet. Ok. That seems like too much effort, so I'd like to try with Python 3.1.1. I edit my PATH environment variable to include <code>C:\Python31\</code> instead of <code>C:\Python24</code>.</p>
  
  <p>I restart cmd and run <code>python setup.py install</code> on pyserial:</p>
  
  <pre><code>C:\path\to\pyserial-2.5&gt;python setup.py install
  running install
  running build
  running build_py
  running build_scripts
  running install_lib
  running install_scripts
  
  C:\path\to\pyserial-2.5&gt;
  </code></pre>
  
  <p>Interesting. I then try to <code>import serial</code> from IDLE in Python 3.1.1, but I get the standard <code>ImportError</code>. Hmm.</p>
  
  <p>What is going on here? Am I doing something wrong?</p>
  
  <p><strong>Update</strong>: I tried to run <code>setup.py install</code> using 3.1.1:</p>
  
  <pre><code>c:\path\to\pyserial-2.5&gt;c:\python31\python.exe setup.py install
  running install
  running build
  running build_py
  running build_scripts
  creating build\scripts-3.1
  copying and adjusting examples\miniterm.py -&gt; build\scripts-3.1
  running install_lib
  creating c:\python31\Lib\site-packages\serial
  copying build\lib\serial\loopback_connection.py -&gt; c:\python31\Lib\site-packages
  \serial
  copying build\lib\serial\rfc2217.py -&gt; c:\python31\Lib\site-packages\serial
  copying build\lib\serial\serialcli.py -&gt; c:\python31\Lib\site-packages\serial
  copying build\lib\serial\serialjava.py -&gt; c:\python31\Lib\site-packages\serial
  copying build\lib\serial\serialposix.py -&gt; c:\python31\Lib\site-packages\serial
  copying build\lib\serial\serialutil.py -&gt; c:\python31\Lib\site-packages\serial
  copying build\lib\serial\serialwin32.py -&gt; c:\python31\Lib\site-packages\serial
  copying build\lib\serial\sermsdos.py -&gt; c:\python31\Lib\site-packages\serial
  copying build\lib\serial\socket_connection.py -&gt; c:\python31\Lib\site-packages\s
  erial
  copying build\lib\serial\win32.py -&gt; c:\python31\Lib\site-packages\serial
  copying build\lib\serial\__init__.py -&gt; c:\python31\Lib\site-packages\serial
  byte-compiling c:\python31\Lib\site-packages\serial\loopback_connection.py to lo
  opback_connection.pyc
    File "c:\python31\Lib\site-packages\serial\loopback_connection.py", line 101
      except ValueError, e:
                       ^
  SyntaxError: invalid syntax
  
  byte-compiling c:\python31\Lib\site-packages\serial\rfc2217.py to rfc2217.pyc
    File "c:\python31\Lib\site-packages\serial\rfc2217.py", line 370
      except Exception, msg:
                      ^
  SyntaxError: invalid syntax
  
  byte-compiling c:\python31\Lib\site-packages\serial\serialcli.py to serialcli.py
  c
    File "c:\python31\Lib\site-packages\serial\serialcli.py", line 39
      except Exception, msg:
                      ^
  SyntaxError: invalid syntax
  
  byte-compiling c:\python31\Lib\site-packages\serial\serialjava.py to serialjava.
  pyc
    File "c:\python31\Lib\site-packages\serial\serialjava.py", line 67
      except Exception, msg:
                      ^
  SyntaxError: invalid syntax
  
  byte-compiling c:\python31\Lib\site-packages\serial\serialposix.py to serialposi
  x.pyc
    File "c:\python31\Lib\site-packages\serial\serialposix.py", line 64
      50:      0000001,
                     ^
  SyntaxError: invalid token
  
  byte-compiling c:\python31\Lib\site-packages\serial\serialutil.py to serialutil.
  pyc
    File "c:\python31\Lib\site-packages\serial\serialutil.py", line 510
      except TypeError, err:
                      ^
  SyntaxError: invalid syntax
  
  byte-compiling c:\python31\Lib\site-packages\serial\serialwin32.py to serialwin3
  2.pyc
  byte-compiling c:\python31\Lib\site-packages\serial\sermsdos.py to sermsdos.pyc
  byte-compiling c:\python31\Lib\site-packages\serial\socket_connection.py to sock
  et_connection.pyc
    File "c:\python31\Lib\site-packages\serial\socket_connection.py", line 49
      except Exception, msg:
                      ^
  SyntaxError: invalid syntax
  
  byte-compiling c:\python31\Lib\site-packages\serial\win32.py to win32.pyc
    File "c:\python31\Lib\site-packages\serial\win32.py", line 164
      MAXDWORD = 4294967295L # Variable c_uint
                           ^
  SyntaxError: invalid syntax
  
  byte-compiling c:\python31\Lib\site-packages\serial\__init__.py to __init__.pyc
  running install_scripts
  creating c:\python31\Scripts
  copying build\scripts-3.1\miniterm.py -&gt; c:\python31\Scripts
  running install_egg_info
  Writing c:\python31\Lib\site-packages\pyserial_py3k-2.5-py3.1.egg-info
  
  
  c:\path\to\pyserial-2.5&gt;
  </code></pre>
  
  <p>Hmm... looks like I'm using an incorrect version of pyserial. <a href="http://pypi.python.org/pypi/pyserial" rel="nofollow">This download page</a> makes it look like 2.5 is the most current. Odd.</p>
  
  <p><strong>Update 2</strong>: I went through and fixed all the syntax errors, but started getting import errors. In <code>__init__.py</code>, I changed:</p>
  
  <pre><code>if os.name == 'nt': #sys.platform == 'win32':
      from serialwin32 import *
  elif os.name == 'posix':
      from serialposix import *
  elif os.name == 'java':
      from serialjava import *
  </code></pre>
  
  <p>to:</p>
  
  <pre><code>if os.name == 'nt': #sys.platform == 'win32':
      from .serialwin32 import *
  elif os.name == 'posix':
      from .serialposix import *
  elif os.name == 'java':
      from .serialjava import *
  </code></pre>
  
  <p>Now I'm getting an error in <code>serialwin32.py</code>:</p>
  
  <pre><code>&gt;&gt;&gt; import serial
  Traceback (most recent call last):
    File "&lt;pyshell#4&gt;", line 1, in &lt;module&gt;
      import serial
    File "C:\Python31\lib\site-packages\serial\__init__.py", line 19, in &lt;module&gt;
      from .serialwin32 import *
    File "C:\Python31\lib\site-packages\serial\serialwin32.py", line 12, in &lt;module&gt;
      import win32
  ImportError: No module named win32
  </code></pre>
  
  <p>I tried doing the <code>.modulename</code> syntax, but that wouldn't compile.</p>
  
  <p>What else can I do here? I'm having a hard time believing that anyone intended this code to run on Python 3. (Perhaps I got the wrong version?)</p>