Author Topic: Python import of pySerial  (Read 8870 times)

pfcass

  • Community Member
  • Posts: 6
  • Hero Points: 0
Python import of pySerial
« on: December 16, 2009, 02:37:32 pm »
I am evaluating slickEdit 2009 for use in a Python project.  I have installed the pySerial module and have tried their basic test at the python command line in a cygwin bash shell window:

$ python
ActivePython 2.6.4.8 (ActiveState Software Inc.) based on
Python 2.6.4 (r264:75706, Nov  3 2009, 13:23:17) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import serial
>>> ser = serial.Serial()
>>> ser
Serial<id=0xb3ddd0, open=False>(port=None, baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=None, xonxoff=0, rtscts=0, dsrdtr=0)
>>>

This creates a serial port called 'ser'.

When I try the same 3 lines in slickEdit, the 'import' succeeds, but the second line, 'ser = serial.Serial()' fails with this message:

C:\dev\cdev\Projects\pyRio>"C:\Python26\python.exe" -S -u "C:\Program Files\SlickEditV14.0.2\resource\tools\pydbgp-1.1.0/bin/pydbgp.py" -d 127.0.0.1:1835 -k slickedit "C:\dev\cdev\Projects\pyRio\serial.py"
Traceback (most recent call last):
  File "C:\dev\cdev\Projects\pyRio\serial.py", line 1, in <module>
    import serial
  File "C:\dev\cdev\Projects\pyRio\serial.py", line 2, in <module>
    ser = serial.Serial()
AttributeError: 'module' object has no attribute 'Serial'

I can user sys.path to see that the path to the 'site-packages' is correct (and it must be if the 'import' line succeeds).

Can someone explain why this works at the python command line but fails in slickedit


Matthew

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 990
  • Hero Points: 44
Re: Python import of pySerial
« Reply #1 on: December 16, 2009, 02:58:32 pm »
Are you on Vista or Win7? I've seen PATH-related problems when invoking some Cygwin tools (like gcc) from non-Cygwin shells. Cygwin has set up some Unix-style symlinks, which work in Cygwin's bash, but don't work in other shells. (I don't know if they're creating those symlinks differently, or if they just stopped working in Vista/Win7).
Are your packages installed under the Cygwin directories, or are they under the ActiveState's site-packages directory? Can you invoke this script correctly from a plain-vanilla CMD.exe shell?

pfcass

  • Community Member
  • Posts: 6
  • Hero Points: 0
Re: Python import of pySerial
« Reply #2 on: December 16, 2009, 03:30:02 pm »
The installation was created by downloading and running

pyserial-2.5-rc1.win32.exe

on a Windows XP-Profession system.

I have tried running python and the three lines to test the serial module using cmd.exe (a dos window), and I get the same successful result as I get when I run python under the cygwin bash shell.

So far, it's only when running python from SlickEdit that it fails.

Rodney

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 710
  • Hero Points: 45
Re: Python import of pySerial
« Reply #3 on: December 16, 2009, 04:34:10 pm »
I think the problem is that you named your test module 'serial.py' and ended up importing it instead.

--rodney

garion911

  • Senior Community Member
  • Posts: 184
  • Hero Points: 13
Re: Python import of pySerial
« Reply #4 on: December 16, 2009, 04:40:40 pm »
I dont run windows, but I do develop python..

I agree with Rodney, you're trying to import yourself.. Your filename is serial.py, and python first looks in the local dir for files or modules that match the name you're trying to import.

Try changing your filename.


pfcass

  • Community Member
  • Posts: 6
  • Hero Points: 0
Re: Python import of pySerial
« Reply #5 on: December 16, 2009, 04:58:01 pm »
Rodney (and garion911) -

You hit the nail on the head.  I changed the file name and it works fine -- just another self-inflicted wound.

Many thanks.

P.