![]() |
Python Errors - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Python Errors (/thread-3397.html) |
Python Errors - kendias - May-19-2017 my question here I am using a python program from a link but am getting errors on simple lines of code (below). Get errors on the first, second lines i.e. import serial # ImportError: "No module named serial" from pynmea import nmea #ImportError: "No module named pynmea" So, my question is - how to import these 2 programs i.e. from a library? I am using these in Enthought Canopy Environment. my code here: import serial from pynmea import nmea import string import webbrowser #####Global Variables###################################### ser = 0 #####FUNCTIONS############################################# def scan(): #scan for available ports. return a list of tuples (num, name) available = [] for i in range(256): try: s = serial.Serial(i) available.append( (i, s.name)) s.close() # explicit close 'cause of delayed GC in java except serial.SerialException: pass return available RE: Python Errors - sparkz_alot - May-19-2017 Always post the entire error report (between the "error" tags). What version of Python are you running? Which OS are you using? You need to install the module before you can use it. Depending on the Python version you might try pip install pynmea
RE: Python Errors - kendias - May-19-2017 (May-19-2017, 09:27 PM)sparkz_alot Wrote: Always post the entire error report (between the "error" tags). Thanks. Windows10 Python 2.7.9 How to import "serial"? Error: C:\Users\Dell\Downloads\lat_lon.py in <module>() 2 import webbrowser 3 import string ----> 4 import serial 5 6 def to_degrees(lats, longs): ImportError: No module named serial RE: Python Errors - nilamo - May-19-2017 Have you... tried installing it? Possibly with pip install pyserial ?
RE: Python Errors - snippsat - May-19-2017 kendias Wrote:from pynmea import nmea #ImportError: "No module named pynmea"You had a long post here ,about installing pynmea 2-days ago. You have now posted code with no indentation. kendias Wrote:I am using these in Enthought Canopy Environment.Have you changed to Enthought since last post? RE: Python Errors - kendias - May-20-2017 Thanks. Tried to install serial from pyserial as you said; installed OK. Tried with python from cmd line and no errors. Tried to run it in Enthought Canopy and got error. I cannot run in the python cmd line as it is a program that runs continuously and hence not suitable for running from python cmd line - or maybe I am confused as to how to run the progam. ImportErrorTraceback (most recent call last) C:\Users\Dell\py_1.py in <module>() 1 # -*- coding: utf-8 -*- ----> 2 import serial 3 from pynmea import nmea 4 import string 5 import webbrowser ImportError: No module named serial RE: Python Errors - snippsat - May-20-2017 When you changes you most learn how to install packages with Enthought Canopy. Installing packages into Canopy User Python from the OS command line PySerial is a part of Enthought as Python 2.7 Packages. RE: Python Errors - kendias - May-21-2017 Thanks - serial is OK now. Trying this program but the 2 print outputs are not displayed. # -*- coding: utf-8 -*- import webbrowser import string import serial from pynmea2 import nmea def to_degrees(lats, longs): # Convert string forms from ddmm.mmmm to dd°mm'ss.ss“ msg = pynmea2.parse("$GPGGA,184353.07,1929.045,S,02410.506,E,1,04,2.6,100.00,M,-33.9,M,,0000*6D") lat_deg = lats[0:2] print lat_deg lat_mins = lats[2:4] print (lat_mins) lat_secs = round(float(lats[5:])*60/10000, 2) lat_str = lat_deg + u'°'+ lat_mins + string.printable[68] + str(lat_secs) + string.printable[63] lon_deg = longs[0:3] lon_mins = longs[3:5] lon_secs = round(float(longs[6:])*60/10000, 2) lon_str = lon_deg + u'°'+ lon_mins + string.printable[68] + str(lon_secs) + string.printable[63] return [lat_str, lon_str] print(lat_str) print msg RE: Python Errors - kendias - May-22-2017 Sorry, not sure how to do it. Will repost when sure - please ignore previous post. RE: Python Errors - kendias - May-22-2017 Trying to define a serial port to get data. def init_serial(): print "Found Ports:" for n,s in scan(): print "%s" % s print " " COMNUM = 5 #set you COM port # here global ser #must be declared in each fxn used ser = serial.Serial() ser.baudrate = 4800 ser.port = COMNUM -1#starts at 0, so subtract 1def init_serial(): print "Found Ports:" for n,s in scan(): print "%s" % s print " " I get the foll. error: %run "C:/Users/Dell/Downloads/lat_lon1.py" C:\Users\Dell\Downloads\lat_lon1.py:26: SyntaxWarning: name 'ser' is assigned to before global declaration global ser #must be declared in each fxn used ValueErrorTraceback (most recent call last) C:\Users\Dell\Downloads\lat_lon1.py in <module>() 27 ser = serial.Serial() 28 ser.baudrate = 4800 ---> 29 ser.port = COMNUM -1#starts at 0, so subtract 1 30 31 ser.timeout = 1 #you must specify a timeout (in seconds) so that the serial port doesn't hang C:\Users\Dell\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\serial\serialutil.pyc in port(self, port) 262 """ 263 if port is not None and not isinstance(port, basestring): --> 264 raise ValueError('"port" must be None or a string, not {}'.format(type(port))) 265 was_open = self.is_open 266 if was_open: ValueError: "port" must be None or a string, not <type 'int'> |