Python Forum
Open a setup python file?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Open a setup python file?
#1
I recently downloaded the VSL compiler developed by Matthieu Amiguet (http://www.matthieuamiguet.ch/pages/compilateurs) to learn how to compile with Python PLY. In the README it says to type python setup install. I readapted the code to work in python 3. Here is what I got as an error:
[Image: Unkmo.png]
Here is setup.py:
import sys, os, shutil

def install():
    print ('Installing...')
    if not os.path.exists(vsldir): os.mkdir(vsldir)
    pyfiles = [f for f in os.listdir('VDK/src/') if not os.path.isdir(f) and f.endswith('.py')]
    for p in pyfiles:
        shutil.copy('VDK/src/'+p,vsldir)
    shutil.copy('VDK/bin/vslc',INSTALLDIR)
    shutil.copy('VRE/vsl',INSTALLDIR)
    shutil.copy('VRE/vsl',INSTALLDIR)
    shutil.copy('vmake/vmake',INSTALLDIR)
    os.chmod(INSTALLDIR+'vslc',111)
    os.chmod(INSTALLDIR+'vsl',111)
    os.chmod(INSTALLDIR+'vmake',111)
    print ('Installed!')

def uninstall():
    print ('Desinstalling...')
    if os.path.exists(vsldir): os.system('rm -R '+vsldir)
    if os.path.exists(INSTALLDIR+'vslc'): os.system('rm '+INSTALLDIR+'vslc')
    if os.path.exists(INSTALLDIR+'vsl'): os.system('rm '+INSTALLDIR+'vsl')
    if os.path.exists(INSTALLDIR+'vsl'): os.system('rm '+INSTALLDIR+'vmake')
    print ('Desinstalled!')

def printHelp():
    print ('''usage : python setup.py COMMANDE
            - install : installation of the compiler and runtime environement
            - uninstall : uninstall the compiler et the runtime environement
                (this two last command need root password)''')

if __name__ == '__main__':
    pythonpath = [path for path in sys.path if path.find('python')!=-1 and path.find('site-packages')!=-1]
    print ('========================================'.center(80))
    print ('=====         VSL Compiler         ====='.center(80))
    print ('===== David Jacod , Anthony Mougin ====='.center(80))
    print ('========================================'.center(80))
    if len(pythonpath)==0:
        print (' * No python path found. Installation failed')
        sys.exit(-1)

    if os.name=='posix': INSTALLDIR = '/usr/local/bin/'
    elif os.name=='nt': INSTALLDIR = 'c:/VSLCompiler/'

    pythonpath=pythonpath[0]
    vsldir = pythonpath+'/vslcomp/'
    if len(sys.argv)<=2:
        if sys.argv[1]=='install': install()
        elif sys.argv[1]=='uninstall': uninstall()
        else: printHelp()
    else:
        printHelp()
Larz60+ write Jan-22-2021, 02:33 AM:
Please use error tags for error posts.
Refer to BBCode
Reply
#2
It installs without problems on Linux if one changes 'if len(sys.argv)<=2:' to 'if len(sys.argv)==2:'
    pythonpath=pythonpath[0]
    vsldir = pythonpath+'/vslcomp/'
    if len(sys.argv)==2:
        if sys.argv[1]=='install': install()
        elif sys.argv[1]=='uninstall': uninstall()
        else: printHelp()
    else:
        printHelp()
but when I try to install it on windows 10 I get the same error as you do. If I change the 'pythonpath' to where python is installed (in my case 'C:\\Python\\Python39\\', note the double slashes) it is accepted but fails on the next path. It seems to me that you will have to manually change every path in the script to make it install on windows and that is just the beginning. You will probably have to change a lot of things in the compiler code as well, e.g. all "print" commands. Possibly more than that.
When I try it on Linux it complains about "print" commands lacking parentheses. You are in for a lot of work to make it run with python 3. Maybe better to try it with python 2.7.
Reply
#3
Quote:
pythonpath = [path for path in sys.path if path.find('python')!=-1 and path.find('site-packages')!=-1]

It's looking for specifically "python" (all lowercase). But default Windows installations install to "Python" (capital P). Try changing that line to look like this:
pythonpath = [path for path in sys.path if path.lower().find('python')!=-1 and path.lower().find('site-packages')!=-1]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Can we store value in file if we open file in read mode? prasanthbab1234 3 2,568 Sep-26-2020, 12:10 PM
Last Post: ibreeden
  open file from listbox to Text elstolbo 0 2,374 Jan-21-2020, 09:37 PM
Last Post: elstolbo
  Python 3.6.4 setup fails embeeusername 2 4,840 Mar-16-2018, 02:29 PM
Last Post: sparkz_alot
  Setup a label by binding listbox importing a subclass method using python 3 and tkint Dannds 0 2,789 Mar-21-2017, 09:38 PM
Last Post: Dannds

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020