Problems with pyserial

78 views
Skip to first unread message

pete

unread,
Jul 31, 2007, 1:06:46 PM7/31/07
to Movable Python
I tried to use pyserial with movable python 2.3 on the same desktop
and get the following error message:

[err] Traceback (most recent call last):
[err] File "main.py", line 900, in ?
[err] File "autotest1.py", line 1, in ?
[err] File "E:\movpy-2.0.0-demo-py2.3.5\movpy\MyScripts
\pb_comms.py", line 28, in ?
[err] File "E:\movpy-2.0.0-demo-py2.3.5\movpy\lib\Lib\site-packages
\serial\__init__.py", line 13, in ?
[err] File "E:\movpy-2.0.0-demo-py2.3.5\movpy\lib\Lib\site-packages
\serial\serialwin32.py", line 9, in ?

[err] ImportError: DLL load failed: The specified procedure could not
be found.

I have Python 2.3 installed on my desktop under WinXP and use pyserial
successfully for serial communicatons there.

I suspect an installation problem perhaps due to the difference in
locations for extensions or something to do with windows. I found the
info under "customizing" on the voidspace site, but unfortunately, I
am unable figure out what to do.

I did try to install it again and see the files directly under ..\movpy
\lib\serial but the above seems to indicate its looking for ..\movpy
\lib\Lib\site-packages

For what its worth, my use case is to move a working program from my
desktop to a laptop doing data collection in the lab. Presently, I am
using the demo pack, but my intent was to purchase it if I can show
that it works.

Can someone please help ? Thanks and regards.

Michael Foord

unread,
Jul 31, 2007, 1:34:46 PM7/31/07
to mo...@googlegroups.com
Hmmm... How about trying to create a 'Lib/site-packages' folder in the
lib directory (as it looks like that is where it is looking), add it to
sys.path at the start of your app. and try that.

It may work :-)

On the other hand - it is possible that those error messages are coming
from '.pyc' files which hard code a path inside them (it could be a
relative path). Try removing those and seeing if the error message changes.

Is there a test program I can run without a serial device attached? That
way I can experiment this end.

Michael
http://www.voidspace.org.uk/python/articles.shtml

pete

unread,
Jul 31, 2007, 2:25:08 PM7/31/07
to Movable Python
Wow, Micheal, thanks for the quick reply !

I found that Lib\site-packages was in the directory AND already in the
sys.path as well.

So I moved on to trying to delete the .pyc files
The error changed to show it looking in \lib\serial (see below)

Below is a very small test program (test_pyserial.py) that doesn't
need a serial device attached:

# pyserial test program
# Open port 0 at "9600,8,N,1", no timeout
import serial
ser = serial.Serial(0) #open first serial port
print "\nPort opened: ",ser.portstr #check which port was really
used
ser.close() #close port
print "Should be closed now"

What I get now is:

[err] Traceback (most recent call last):
[err] File "main.py", line 900, in ?

[err] File "test_pyserial.py", line 4, in ?
[err] File "E:\movpy-2.0.0-demo-py2.3.5\movpy\lib\serial


\__init__.py", line 13, in ?

[err] File "E:\movpy-2.0.0-demo-py2.3.5\movpy\lib\serial


\serialwin32.py", line 9, in ?
[err] ImportError: DLL load failed: The specified procedure could not
be found.

If its helpful, the pyserial website is here: http://pyserial.sourceforge.net/

By the way, I can use the interpreter ">>>", but the IDE doesn't seem
to work...

Thanks in advance.


On Jul 31, 1:34 pm, Michael Foord <fuzzy...@voidspace.org.uk> wrote:
> Hmmm... How about trying to create a 'Lib/site-packages' folder in the
> lib directory (as it looks like that is where it is looking), add it to
> sys.path at the start of your app. and try that.
>
> It may work :-)
>
> On the other hand - it is possible that those error messages are coming
> from '.pyc' files which hard code a path inside them (it could be a
> relative path). Try removing those and seeing if the error message changes.
>
> Is there a test program I can run without a serial device attached? That
> way I can experiment this end.
>

> Michaelhttp://www.voidspace.org.uk/python/articles.shtml

> > Can someone please help ? Thanks and regards.- Hide quoted text -
>
> - Show quoted text -

Michael Foord

unread,
Jul 31, 2007, 7:58:58 PM7/31/07
to mo...@googlegroups.com
Pete - thanks for this. Your test program gives me something to go on
and see if we can get it working.

I'm out now until Friday, but I promise to look at the problem than and
see what I can come up with.

I vaguely wonder if pyserial puts DLLs (or '.pyd's) in funny places and
maybe you aren't copying them across. Or maybe the serial directory
needs to be added to the path as well.

These are all things I can look at on Friday though.

Michael

JimC

unread,
Aug 1, 2007, 10:58:26 AM8/1/07
to Movable Python

On Jul 31, 1:25 pm, pete <peste...@nordson.com> wrote:
> [err] Traceback (most recent call last):
> [err] File "main.py", line 900, in ?
> [err] File "test_pyserial.py", line 4, in ?
> [err] File "E:\movpy-2.0.0-demo-py2.3.5\movpy\lib\serial
> \__init__.py", line 13, in ?
> [err] File "E:\movpy-2.0.0-demo-py2.3.5\movpy\lib\serial
> \serialwin32.py", line 9, in ?
> [err] ImportError: DLL load failed: The specified procedure could not
> be found.

What's on line 9 of serialwin32.py?

BTW, I think removing compiled (.pyc, .pyo) files is a good idea
whenever you copy over a module to Movable Python from another
distribution.

-Jim C.

JimC

unread,
Aug 1, 2007, 1:10:55 PM8/1/07
to Movable Python

>
> What's on line 9 of serialwin32.py?
>

I see, it's importing a .pyd file from the win32 extensions. This
sounds very familiar, this thread might be helpful:

<http://groups.google.com/group/movpy/browse_thread/thread/
4186e56692014bed/2e379e9c86bd9e38?lnk=gst&q=import
+win32api&rnum=1&hl=en#2e379e9c86bd9e38>

JimC

unread,
Aug 1, 2007, 1:11:05 PM8/1/07
to Movable Python

>
> What's on line 9 of serialwin32.py?
>

I see, it's importing a .pyd file from the win32 extensions. This

JimC

unread,
Aug 1, 2007, 1:11:22 PM8/1/07
to Movable Python

>
> What's on line 9 of serialwin32.py?
>

I see, it's importing a .pyd file from the win32 extensions. This

JimC

unread,
Aug 1, 2007, 1:11:54 PM8/1/07
to Movable Python

>
> What's on line 9 of serialwin32.py?
>

I see, it's importing a .pyd file from the win32 extensions. This

JimC

unread,
Aug 1, 2007, 1:14:17 PM8/1/07
to Movable Python

Blast, sorry for the multiple posts and broken URL. Probably easier to
search the group for "import win32api".

-Jim

pete

unread,
Aug 1, 2007, 3:48:41 PM8/1/07
to Movable Python
I was trying to find the answer to this question:

> What's on line 9 of serialwin32.py?
but it took longer than expected. I'm inexperienced with this, but
seems to be related to win32all...

On my desktop, in WINDOWS\SYSTEM32 I find:
python23.dll version 2.3.2150.1013
pythoncom23.dll version 2.3.2.163 <----------- build 163?

On my USB stick I find
movpy\python23.dll
movpy\lib\pythoncom23.dll version 2.3.210.0 <------ from
http://pywin32.sourceforge.net

JimC: I searched the group as you suggested. I couldn't follow all
the discussion, but I added these 3 lines to the start of my program

import pywintypes
import pythoncom
import win32api

and it works now. Thanks JimC ! But I don't understand why... or if
this is the best way. It wasn't required on my desktop.

I appreciate any help or explanation (knowledge!) anyone might
provide.

Regards,
Pete

Michael Foord

unread,
Aug 2, 2007, 5:25:05 AM8/2/07
to mo...@googlegroups.com
pete wrote:
> I was trying to find the answer to this question:
>
>> What's on line 9 of serialwin32.py?
>>
> but it took longer than expected. I'm inexperienced with this, but
> seems to be related to win32all...
>
> On my desktop, in WINDOWS\SYSTEM32 I find:
> python23.dll version 2.3.2150.1013
> pythoncom23.dll version 2.3.2.163 <----------- build 163?
>
> On my USB stick I find
> movpy\python23.dll
> movpy\lib\pythoncom23.dll version 2.3.210.0 <------ from
> http://pywin32.sourceforge.net
>
> JimC: I searched the group as you suggested. I couldn't follow all
> the discussion, but I added these 3 lines to the start of my program
>
> import pywintypes
> import pythoncom
> import win32api
>
> and it works now. Thanks JimC ! But I don't understand why... or if
> this is the best way. It wasn't required on my desktop.
>
> I appreciate any help or explanation (knowledge!) anyone might
> provide.
>


As you might guess build 210 is much more recent than build 163. Having
to do the imports in that specific order is just a peculiarity of the
pywin32 extensions - the dlls must be loaded in the correct order for
some reason when running with Movable Python or any program created with
py2exe.

I'm glad it has been sorted though. (And thanks for the responses Jim.)

Michael
http://www.voidspace.org.uk/python/articles.shtml

pete

unread,
Aug 2, 2007, 10:13:18 AM8/2/07
to Movable Python
I very much appreciate the support thus far. Not to "beat a dead
horse", but I see that my language was imprecise. I'd like to clarify
so I can understand what's required in order to avoid *future*
problems (and avoid taking anyone's time) when moving programs. I now
understand that the *order* of imports is important. What I don't
understand is that on my desktop, *none* of the three imports were
needed. Is it just that they're needed and used anyway (unbeknownst
to me) and by specifying them I control the order? Or is it that the
3 extra imports are required *and* the order matters, too?

Can you provide guideliness for when to do this? Is it only related
to py2exe or something else? Thanks !

Pete

>
> > Regards,
> > Pete
>
> > On Aug 1, 1:14 pm, JimC <jacli...@mailbolt.com> wrote:
>
> >> Blast, sorry for the multiple posts and broken URL. Probably easier to
> >> search the group for "import win32api".
>

> >> -Jim- Hide quoted text -
>
> - Show quoted text -- Hide quoted text -

JimC

unread,
Aug 2, 2007, 10:53:47 AM8/2/07
to Movable Python

On Aug 2, 9:13 am, pete <peste...@nordson.com> wrote:
>
> > > import pywintypes
> > > import pythoncom
> > > import win32api
>

> > As you might guess build 210 is much more recent than build 163. Having

> problems (and avoid taking anyone's time) when moving programs. I now


> understand that the *order* of imports is important. What I don't
> understand is that on my desktop, *none* of the three imports were
> needed. Is it just that they're needed and used anyway (unbeknownst
> to me) and by specifying them I control the order? Or is it that the

That's right. And furthermore, at some point they try to find one more
more dlls (e.g. python23com.dll). For reasons that I don't understand,
if you explicitly do the import in your Python code it finds the
correct dll, whereas if you allow the import to happen indirectly in
a .pyd module it finds the one in your system directory. Which is a
different version.

Michael might have some notion about why this happens and how it
relates to whether or not sys.frozen is defined, I just stumbled
across it.

The imports may not all three be necessary, you might try leaving out
win32api.

-Jim

Michael Foord

unread,
Aug 2, 2007, 6:49:32 PM8/2/07
to mo...@googlegroups.com
pete wrote:
> [snip..]

> I very much appreciate the support thus far. Not to "beat a dead
> horse", but I see that my language was imprecise. I'd like to clarify
> so I can understand what's required in order to avoid *future*
> problems (and avoid taking anyone's time) when moving programs. I now
> understand that the *order* of imports is important. What I don't
> understand is that on my desktop, *none* of the three imports were
> needed. Is it just that they're needed and used anyway (unbeknownst
> to me) and by specifying them I control the order? Or is it that the
> 3 extra imports are required *and* the order matters, too?
>

This is a specific problem with the pywin32 extensions. It took quite a
long time to track down - but the solution (odd as it is) seems to work.
As I mentioned, it is not a problem specific to Movable Python, but can
affect other programs created with py2exe as well.

In *general* this is the only problem of its kind that I'm aware of.

There are a few other minor differences between the Movable Python and
the CPython environment, a few of which are noted here:

http://www.voidspace.org.uk/python/movpy/ISSUES.html

All the best,


Michael
http://www.ironpython.info/

Reply all
Reply to author
Forward
0 new messages