Problem 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 serialin both versions. Both called Import Error.

Then I downloaded the win32 installer from this page . I ran it and installed for 2.4.4. (He said he found it in the registry.) I did not have the opportunity to upgrade to version 3.1.1.

Then I got the following error in 2.4.4:

>>> import serial

Traceback (most recent call last):
  File "<pyshell#0>", 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

I look up ctypesand see that he was a bullet with 2.5.5. Good.

Download ctypesand run python setup.py install. (2.4.4.)

I get the following:

C:\path\to\ctypes-1.0.2>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.

. . , Python 3.1.1. PATH, C:\Python31\ C:\Python24.

cmd python setup.py install pyserial:

C:\path\to\pyserial-2.5>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>

. import serial IDLE Python 3.1.1, ImportError. .

? - ?

. setup.py install 3.1.1:

c:\path\to\pyserial-2.5>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 -> build\scripts-3.1
running install_lib
creating c:\python31\Lib\site-packages\serial
copying build\lib\serial\loopback_connection.py -> c:\python31\Lib\site-packages
\serial
copying build\lib\serial\rfc2217.py -> c:\python31\Lib\site-packages\serial
copying build\lib\serial\serialcli.py -> c:\python31\Lib\site-packages\serial
copying build\lib\serial\serialjava.py -> c:\python31\Lib\site-packages\serial
copying build\lib\serial\serialposix.py -> c:\python31\Lib\site-packages\serial
copying build\lib\serial\serialutil.py -> c:\python31\Lib\site-packages\serial
copying build\lib\serial\serialwin32.py -> c:\python31\Lib\site-packages\serial
copying build\lib\serial\sermsdos.py -> c:\python31\Lib\site-packages\serial
copying build\lib\serial\socket_connection.py -> c:\python31\Lib\site-packages\s
erial
copying build\lib\serial\win32.py -> c:\python31\Lib\site-packages\serial
copying build\lib\serial\__init__.py -> 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 -> 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>

... , pyserial. , 2.5 . .

2. , . __init__.py :

if os.name == 'nt': #sys.platform == 'win32':
    from serialwin32 import *
elif os.name == 'posix':
    from serialposix import *
elif os.name == 'java':
    from serialjava import *

if os.name == 'nt': #sys.platform == 'win32':
    from .serialwin32 import *
elif os.name == 'posix':
    from .serialposix import *
elif os.name == 'java':
    from .serialjava import *

serialwin32.py:

>>> import serial
Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    import serial
  File "C:\Python31\lib\site-packages\serial\__init__.py", line 19, in <module>
    from .serialwin32 import *
  File "C:\Python31\lib\site-packages\serial\serialwin32.py", line 12, in <module>
    import win32
ImportError: No module named win32

.modulename, .

? , - Python 3. (, ?)

+2
2

-, python 2.4 Windows? , (, ctypes), , pyserial.

, , PYTHONPATH, python . Python 3 , , , Python 2.x.

, pyserial:

http://pypi.python.org/pypi/pyserial. , pyserial-x.y :

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


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

, python3.

+2

, , -. ,

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

, import serial, :

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

, . serial, .

0
source

Source: https://habr.com/ru/post/1795920/


All Articles