import an external library

Asked by Raphaël Maurin

Hi all,

I am trying to import an external library nsmp1d_yade.so in my script (see below) and I don't succeed to do it.
When I am using my script with python, doing :
python Simple.py
everything is working and the script is using the content of the library.
However, when I am running the same script with yade :
yade-daily Simple.py

I get an error :
Welcome to Yade 3+3698+47~precise1
TCP python prompt on localhost:9000, auth cookie `ucdsea'
XMLRPC info provider on http://localhost:21000
Running script Simple.py
Traceback (most recent call last):
  File "/usr/bin/yade-daily", line 168, in runScript
    execfile(script,globals())
  File "Simple.py", line 2, in <module>
    from nsmp1d_yade import *
ImportError: No module named nsmp1d_yade

I don't understand why it is working with python and not with Yade.
Do you have any idea of how I can solve this problem?

Thank you

Raphael

Here is my script Simple.py :

from nsmp1d_yade import *

from pylab import *
from matplotlib import pyplot
import matplotlib.gridspec as gridspec
import numpy as np

## Define the situation
rho_f = 1000
rho_s = 2500
slope = 1e-4
visco_f = 1e-3
dp=6e-3
ndimz=301
h=1.
dsig=np.zeros(ndimz)
dsig[0:ndimz-1]=h/(double(ndimz-1))
sig=linspace(0e0,1e0,ndimz)

ufnp = np.zeros(ndimz)
ufn = np.zeros(ndimz)
alphaf = np.zeros(ndimz)
us = np.zeros(ndimz)
alphas = np.zeros(ndimz)
alphaf=1e0-alphas
tfin=2000.
dt=1e-1

ufnp=nsmp1d_yade(h,sig,dsig,dp,ufn,alphaf,us,alphas,tfin,dt)

##
## plots
##

zmin=0
zmax=h

umin=min(ufnp)
umax=max(ufnp)

figure(1)

plot(ufnp,sig*h,'ob',label='u_f')
title('U_f')
#axis([1200, 1900, zmin, zmax])
xlabel('U_f (m/s)')
ylabel('z (m)')
axis([umin, umax, zmin, zmax])

show()

Question information

Language:
English Edit question
Status:
Answered
For:
Yade Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Anton Gladky (gladky-anton) said :
#1

PYTHONPATH=. yade-daily Simple.py

should fix your problem, if nsmp1d_yade.so is in the current folder.

Anton

2013/8/23 Raphaël Maurin <email address hidden>:
> New question #234513 on Yade:
> https://answers.launchpad.net/yade/+question/234513
>
> Hi all,
>
> I am trying to import an external library nsmp1d_yade.so in my script (see below) and I don't succeed to do it.
> When I am using my script with python, doing :
> python Simple.py
> everything is working and the script is using the content of the library.
> However, when I am running the same script with yade :
> yade-daily Simple.py
>
> I get an error :
> Welcome to Yade 3+3698+47~precise1
> TCP python prompt on localhost:9000, auth cookie `ucdsea'
> XMLRPC info provider on http://localhost:21000
> Running script Simple.py
> Traceback (most recent call last):
> File "/usr/bin/yade-daily", line 168, in runScript
> execfile(script,globals())
> File "Simple.py", line 2, in <module>
> from nsmp1d_yade import *
> ImportError: No module named nsmp1d_yade
>
>
> I don't understand why it is working with python and not with Yade.
> Do you have any idea of how I can solve this problem?
>
> Thank you
>
> Raphael
>
>
>
> Here is my script Simple.py :
>
> from nsmp1d_yade import *
>
> from pylab import *
> from matplotlib import pyplot
> import matplotlib.gridspec as gridspec
> import numpy as np
>
> ## Define the situation
> rho_f = 1000
> rho_s = 2500
> slope = 1e-4
> visco_f = 1e-3
> dp=6e-3
> ndimz=301
> h=1.
> dsig=np.zeros(ndimz)
> dsig[0:ndimz-1]=h/(double(ndimz-1))
> sig=linspace(0e0,1e0,ndimz)
>
> ufnp = np.zeros(ndimz)
> ufn = np.zeros(ndimz)
> alphaf = np.zeros(ndimz)
> us = np.zeros(ndimz)
> alphas = np.zeros(ndimz)
> alphaf=1e0-alphas
> tfin=2000.
> dt=1e-1
>
> ufnp=nsmp1d_yade(h,sig,dsig,dp,ufn,alphaf,us,alphas,tfin,dt)
>
> ##
> ## plots
> ##
>
> zmin=0
> zmax=h
>
> umin=min(ufnp)
> umax=max(ufnp)
>
> figure(1)
>
> plot(ufnp,sig*h,'ob',label='u_f')
> title('U_f')
> #axis([1200, 1900, zmin, zmax])
> xlabel('U_f (m/s)')
> ylabel('z (m)')
> axis([umin, umax, zmin, zmax])
>
> show()
>
> --
> You received this question notification because you are a member of
> yade-users, which 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
Jan Stránský (honzik) said :
#2

or inside the script (in the beginning)

import sys
sys.path.append('.')

the solution is the same as Anton's one
Jan

2013/8/23 Anton Gladky <email address hidden>

> Question #234513 on Yade changed:
> https://answers.launchpad.net/yade/+question/234513
>
> Status: Open => Answered
>
> Anton Gladky proposed the following answer:
> PYTHONPATH=. yade-daily Simple.py
>
> should fix your problem, if nsmp1d_yade.so is in the current folder.
>
> Anton
>
>
> 2013/8/23 Raphaël Maurin <email address hidden>:
> > New question #234513 on Yade:
> > https://answers.launchpad.net/yade/+question/234513
> >
> > Hi all,
> >
> > I am trying to import an external library nsmp1d_yade.so in my script
> (see below) and I don't succeed to do it.
> > When I am using my script with python, doing :
> > python Simple.py
> > everything is working and the script is using the content of the library.
> > However, when I am running the same script with yade :
> > yade-daily Simple.py
> >
> > I get an error :
> > Welcome to Yade 3+3698+47~precise1
> > TCP python prompt on localhost:9000, auth cookie `ucdsea'
> > XMLRPC info provider on http://localhost:21000
> > Running script Simple.py
> > Traceback (most recent call last):
> > File "/usr/bin/yade-daily", line 168, in runScript
> > execfile(script,globals())
> > File "Simple.py", line 2, in <module>
> > from nsmp1d_yade import *
> > ImportError: No module named nsmp1d_yade
> >
> >
> > I don't understand why it is working with python and not with Yade.
> > Do you have any idea of how I can solve this problem?
> >
> > Thank you
> >
> > Raphael
> >
> >
> >
> > Here is my script Simple.py :
> >
> > from nsmp1d_yade import *
> >
> > from pylab import *
> > from matplotlib import pyplot
> > import matplotlib.gridspec as gridspec
> > import numpy as np
> >
> > ## Define the situation
> > rho_f = 1000
> > rho_s = 2500
> > slope = 1e-4
> > visco_f = 1e-3
> > dp=6e-3
> > ndimz=301
> > h=1.
> > dsig=np.zeros(ndimz)
> > dsig[0:ndimz-1]=h/(double(ndimz-1))
> > sig=linspace(0e0,1e0,ndimz)
> >
> > ufnp = np.zeros(ndimz)
> > ufn = np.zeros(ndimz)
> > alphaf = np.zeros(ndimz)
> > us = np.zeros(ndimz)
> > alphas = np.zeros(ndimz)
> > alphaf=1e0-alphas
> > tfin=2000.
> > dt=1e-1
> >
> > ufnp=nsmp1d_yade(h,sig,dsig,dp,ufn,alphaf,us,alphas,tfin,dt)
> >
> > ##
> > ## plots
> > ##
> >
> > zmin=0
> > zmax=h
> >
> > umin=min(ufnp)
> > umax=max(ufnp)
> >
> > figure(1)
> >
> > plot(ufnp,sig*h,'ob',label='u_f')
> > title('U_f')
> > #axis([1200, 1900, zmin, zmax])
> > xlabel('U_f (m/s)')
> > ylabel('z (m)')
> > axis([umin, umax, zmin, zmax])
> >
> > show()
> >
> > --
> > You received this question notification because you are a member of
> > yade-users, which 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
>
> --
> You received this question notification because you are a member of
> yade-users, which 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
Raphaël Maurin (raphael-maurin) said :
#3

Thanks for the answer, I tried both solutions one by one, but both lead to another error :
Welcome to Yade 3+3698+47~precise1
TCP python prompt on localhost:9000, auth cookie `dascks'
XMLRPC info provider on http://localhost:21000
Running script Simple.py
Erreur de segmentation (core dumped)

translation : segmentation fault

and I don't know how to fix that.
Any idea ?

Thanks
Raphael

(The script is still working in python)

Revision history for this message
Anton Gladky (gladky-anton) said :
#4

It should be debugged. Can be related to a LP:1183402 [1].

[1] https://bugs.launchpad.net/yade/+bug/1183402

Anton

2013/8/23 Raphaël Maurin <email address hidden>:
> Question #234513 on Yade changed:
> https://answers.launchpad.net/yade/+question/234513
>
> Status: Answered => Open
>
> Raphaël Maurin is still having a problem:
> Thanks for the answer, I tried both solutions one by one, but both lead to another error :
> Welcome to Yade 3+3698+47~precise1
> TCP python prompt on localhost:9000, auth cookie `dascks'
> XMLRPC info provider on http://localhost:21000
> Running script Simple.py
> Erreur de segmentation (core dumped)
>
> translation : segmentation fault
>
> and I don't know how to fix that.
> Any idea ?
>
> Thanks
> Raphael
>
> (The script is still working in python)
>
> --
> You received this question notification because you are a member of
> yade-users, which 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
Bruno Chareyre (bruno-chareyre) said :
#5

Since google likes this page when it comes to importing libraries, it may hide another important thread regarding imports.
If yade crash when importing something, please see also:
https://bugs.launchpad.net/yade/+bug/1183402

Can you help with this problem?

Provide an answer of your own, or ask Raphaël Maurin for more information if necessary.

To post a message you must log in.