index out of range

Asked by sunwei

when i want to Import Yade in other Python applications, i do the command as https://www.yade-dem.org/doc/user.html#python-specialties-and-tricks:
$ cd /path/where/you/want/yadeimport
$ ln -s /path/to/yade/executable/yade-trunk yadeimport.py
then
import sys
sys.path.append('/path/where/you/want/yadeimport')
from yadeimport import *
but at this step, the error is "indexerror: index out of range"
the relevant lines are
"except ImportError: # argparse not present, print error message
    raise RuntimeError("\n\nPlease install 'python-argparse' package.\n")
prog = os.path.basename(sys.argv[0])
par=argparse.ArgumentParser(usage='%s [options] [ simulation.xml[.bz2] | script.py [script options]]'%prog,
  prog=prog,description="Yade: open-source platform for dynamic compuations. It\"
i think it may be induced by the sys.argv[0], but i don't know how to amend it.

Question information

Language:
English Edit question
Status:
Answered
For:
Yade Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:

This question was reopened

Revision history for this message
Jan Stránský (honzik) said :
#1

Hello,

"except ImportError: # argparse not present, print error message
> raise RuntimeError("\n\nPlease install 'python-argparse' package.\n")

exactly as the error says, package python-argparse is missing. On ubuntu run
sudo apt-get install python-argparse

cheers
Jan

Revision history for this message
sunwei (ttsunwei) said :
#2

in fact, i had already installed it. so it doesn't work. it still has the" index out of range" problem.

Revision history for this message
Jan Stránský (honzik) said :
#3

Please put here complete error, system you use and Yade version.
Thanks
Jan

2017-02-25 8:43 GMT+01:00 sunwei <email address hidden>:

> Question #482400 on Yade changed:
> https://answers.launchpad.net/yade/+question/482400
>
> sunwei posted a new comment:
> in fact, i had already installed it. so it doesn't work. it still has
> the" index out of range" problem.
>
> --
> You received this question notification because your team yade-users is
> an answer contact for Yade.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-users
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~yade-users
> More help : https://help.launchpad.net/ListHelp
>

Revision history for this message
sunwei (ttsunwei) said :
#4

the complete error is as follows:

Yade [1]: import sys

Yade [2]: sys.path.append('/home/thusunwei/myyade/trunk/py/FEMxDEM')

Yade [3]: from yadeimport import *
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
/home/thusunwei/myyade/build/bins/yade-2017-02-07.git-11c276f in <module>()
----> 1 from yadeimport import *

/home/thusunwei/myyade/trunk/py/FEMxDEM/yadeimport.py in <module>()
     36 except ImportError: # argparse not present, print error message
     37 raise RuntimeError("\n\nPlease install 'python-argparse' package.\n")
---> 38 prog = os.path.basename(sys.argv[0])
     39 par=argparse.ArgumentParser(usage='%s [options] [ simulation.xml[.bz2] | script.py [script options]]'%prog,
     40 prog=prog,description="Yade: open-source platform for dynamic compuations. It\

IndexError: list index out of range

i use the ubuntu version 14.04 and Yade version is 2017-02-07.git-11c276f

Revision history for this message
Jan Stránský (honzik) said :
#5

Thanks for info,
empty sys.argv is not standard. A workaround should be

argv = sys.argv
sys.argv = ['whatever']
from yadeimport import *
sys.argv = argv

Anyway, why you import Yade into Yade session? :-) (based on #4)

cheers
Jan

Revision history for this message
sunwei (ttsunwei) said :
#6

thank you jan. That solves my problem.
The reason why i import Yade into Yade session is to take Yade as an object to couple with FEM(Like OOFEM).

Revision history for this message
sunwei (ttsunwei) said :
#7

now I input

Yade [1]: import sys

Yade [2]: sys.path.append('/home/thusunwei/myyade/trunk/py/FEMxDEM')

Yade [3]: from yadeimport import *

but errors happen as
"bash: syntax error near unexpected token '''/home/thusunwei/myyade/trunk/py/FEMxDEM'"

can't read /var/mail/yadeimport

I think it is strange because it is OK a period of time ago.

Revision history for this message
Jan Stránský (honzik) said :
#8

> "bash: syntax error

the "bash" looks very suspicious.. could you please send all commands (including console command starting yade or possibly even some console commands before) you use?
Also please provide complete error
thanks
Jan

Revision history for this message
sunwei (ttsunwei) said :
#9

the console commands is as follows:
thusunwei@thusunwei:~$ cd /home/thusunwei/myyade/trunk/py/FEMxDEM
thusunwei@thusunwei:~/myyade/trunk/py/FEMxDEM$ ln -s /home/thusunwei/myyade/build/bins/yade-2017-02-07.git-11c276f yadeimport.py
thusunwei@thusunwei:~/myyade/trunk/py/FEMxDEM$ import sys
thusunwei@thusunwei:~/myyade/trunk/py/FEMxDEM$ sys.path.append('/home/thusunwei/myyade/trunk/py/FEMxDEM')
bash: syntax error near unexpected token `'/home/thusunwei/myyade/trunk/py/FEMxDEM''
thusunwei@thusunwei:~/myyade/trunk/py/FEMxDEM$

they are like the commands in https://www.yade-dem.org/doc/user.html#python-specialties-and-tricks.
But I don't know what is the wrong.

Revision history for this message
Jan Stránský (honzik) said :
#10

Thanks, now it is much more clear :-)

> thusunwei@thusunwei:~/myyade/trunk/py/FEMxDEM$ import sys

here is the problem, you are still in a linux shell, you have to start python/ipython first. Then you can write "import sys" and other lines. Or you can put all the commands into .py file and call "python someFile.py"

cheers
Jan

Can you help with this problem?

Provide an answer of your own, or ask sunwei for more information if necessary.

To post a message you must log in.