How do I pick the right python in Linux env? - 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: How do I pick the right python in Linux env? (/thread-27843.html) |
How do I pick the right python in Linux env? - MDRI - Jun-24-2020 How do I pick the right python in Linux env? ============================================ Thanks for reviewing my threads. I have a pyhton code developed in Windows Eclipse PyDev IDE. As I place this code in Linux environment, I am finding some challenges. I added #!/usr/bin/env python to code in linux box xmlcode.py. I find many python version like Python 2.3, 2.6, 3.2 etc I made this code file to have execute privilege. ./xmlcode.py ==> throw file not found. python xmlcode.py ==> not producing output I find /usr/lib64/python2.6/site-packages/lxml in linux server but import xml.etree.ElementTree as ET from lxml import etree not picking up in my code run How do I pick the correct python version env for my code? How do I bring xml.etree.ElementTree , lxml to above correct python version env? What are the linux env (variable) set up required for my code to work? Thanks for your guidance. RE: How do I pick the right python in Linux env? - ndc85430 - Jun-24-2020 If the file isn't found, are you running it from the correct directory? When you run python xmlcode.py , what exactly happens? We need to see your terminal output and the code as well. It's impossible to help you with so little information.
RE: How do I pick the right python in Linux env? - Gribouillis - Jun-24-2020 There are many ways to do this
RE: How do I pick the right python in Linux env? - MDRI - Jun-25-2020 Thanks for weighing in. Here is the code #!/usr/bin/python def Process_XML(infile, inxpath, xpathdln): """ Process XML Xpath """ import xml.etree.ElementTree as ET from lxml import etree tree = etree.parse(infile) root = tree.getroot() print(root) for dln in tree.xpath(xpathdln): # Iterate over attributes of datafield print(dln.tag + ' = ' + dln.text) for df in tree.xpath(inxpath): # Iterate over attributes of datafield print(df.tag + ' = ' + df.text) for attrib_name in df.attrib: print( '@' + attrib_name + '=' + df.attrib[attrib_name]) # subfield is a child of datafield, and iterate subfields = df.getchildren() for subfield in subfields: print (subfield.tag + ' = ' + subfield.text) return; infile1 = '<CountryData.xml> # Given below inxpath1 = '//Country' xpathdln = '/data' Process_XML(infile1, inxpath1, xpathdln)The above code is tested in windows Python 3.8.1, but Linux has Python 2 INPUT Data ============== <?xml version="1.0" encoding="UTF-8"?> <data> <country name="Liechtenstein"> <rank>1</rank> <year>2008</year> <gdppc>141100</gdppc> <neighbor name="Austria" direction="E"/> <neighbor name="Switzerland" direction="W"/> </country> <country name="Singapore"> <rank>4</rank> <year>2011</year> <gdppc>59900</gdppc> <neighbor name="Malaysia" direction="N"/> </country> <country name="Panama"> <rank>68</rank> <year>2012</year> <gdppc>13600</gdppc> <neighbor name="Costa Rica" direction="W"/> <neighbor name="Colombia" direction="E"/> </country> </data> The python code ==> xmltest.py It is sitting in the home directory with u+x permission If I use ./xmltest.py throw file not found Running this in window make output, but Linux is not making output. I ran with python -v xmltest.py. I did not see any errors there as well. Thanks for your guidance. RE: How do I pick the right python in Linux env? - ndc85430 - Jun-25-2020 As I asked, please post the output you're seeing in the terminal. We can't see your screen. RE: How do I pick the right python in Linux env? - MDRI - Jun-27-2020 Here is what I see in the linux terminal /export/home/XXXXXX/Scripts$ls -l xmltest.py -rwxr--r--. 1 XXXXXX dsx-users 1698 Jun 26 12:54 xmltest.py /export/home/bn1pb/Scripts$./xmltest.py -ksh: ./xmltest.py: not found [No such file or directory]Thanks for your guidance. RE: How do I pick the right python in Linux env? - Gribouillis - Jun-27-2020 What about $ python xmltest.pyIs there an error message? RE: How do I pick the right python in Linux env? - snippsat - Jun-27-2020 (Jun-25-2020, 01:59 AM)MDRI Wrote: The above code is tested in windows Python 3.8.1, but Linux has Python 2Not anymore in new releases eg Ubuntu/Mint 20.. is Python 2 not included by default. Quote:Python3 by defaultPython 3 has been in Linux distors bye default for many year,but if you do ./xmltest.py (don't test only with this) or python xmltest.py it will call Python 2 in most distros. Most use python3 xmltest.py .Look at Linux Python 3 environment and pyenv Simple Python Version Management. And go back and look your older Thread,there is no need to use one for loop for each tag element as you do now. # Example all the child element nodes of the country element parse = root.xpath('//country/*') >>> for tag in parse: ... if tag.text is not None: ... print(tag.text) 1 2008 141100 4 2011 59900 68 2012 13600 RE: How do I pick the right python in Linux env? - MDRI - Jun-27-2020 Thanks for weighing in. $ python xmltest.py ===> working alright. Our linux OS has Python 2.6.6 . I find *.py with execute permission can run as ./*.py Is it true? Thanks for guidance. RE: How do I pick the right python in Linux env? - snippsat - Jun-27-2020 (Jun-27-2020, 04:42 PM)MDRI Wrote: $ python xmltest.py ===> working alright.You should not at all use Python 2.6,python 2 is dead all support/maintenance stopped after 2020. If you type python3 -V and pip3 -V in Terminal what to get?As a adivce should at least use Python 3.6 preferably python 3.7 or newer. |