Importing Yade in other Python applications

Asked by Rong Zhao on 2019-11-15

Hi, I have a problem with importing Yade in other Python applications. The Yade documentation provides the easiest way to import the Yade in other Python applications. I try the provided method to create a symbolic link as explained below.

=================================================================================
$ cd /home/zhaorong/Desktop/
$ ln -s /home/zhaorong/myYade/build/bins/yade-2019.01a /home/zhaorong/Desktop/yadeimport.py
=================================================================================

Then, I tried in Python2 and it succeeded.
======================================================
zhaorong@ubuntu64:~/Desktop$ python2
Python 2.7.16 (default, Oct 7 2019, 17:36:04)
[GCC 8.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.append('/home/zhaorong/Desktop/')
>>> from yadeimport import *
=======================================================

But when I used the same method in python3, it failed.
=======================================================
zhaorong@ubuntu64:~/Desktop$ python3
Python 3.7.3 (default, Oct 7 2019, 12:56:13)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.append('/home/zhaorong/Desktop/')
>>> from yadeimport import *

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/zhaorong/Desktop/yadeimport.py", line 71
    print 'Yade version: %s%s'%(version,debugbuild)
                             ^
SyntaxError: invalid syntax
=======================================================

I want to know whether the Yade is imported to Python2 applications only, not Python3 applications.

Thanks.

Question information

Language:
English Edit question
Status:
Answered
For:
Yade Edit question
Assignee:
No assignee Edit question
Last query:
2019-11-15
Last reply:
2019-11-15

Hi,

Did you compile yade using python3 version?

According to this line :

  print 'Yade version: %s%s'%(version,debugbuild)

it seems not.

William

On 15/11/2019 11:03, Rong Zhao wrote:
> New question #685892 on Yade:
> https://answers.launchpad.net/yade/+question/685892
>
> Hi, I have a problem with importing Yade in other Python applications. The Yade documentation provides the easiest way to import the Yade in other Python applications. I try the provided method to create a symbolic link as explained below.
>
> =================================================================================
> $ cd /home/zhaorong/Desktop/
> $ ln -s /home/zhaorong/myYade/build/bins/yade-2019.01a /home/zhaorong/Desktop/yadeimport.py
> =================================================================================
>
> Then, I tried in Python2 and it succeeded.
> ======================================================
> zhaorong@ubuntu64:~/Desktop$ python2
> Python 2.7.16 (default, Oct 7 2019, 17:36:04)
> [GCC 8.3.0] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import sys
>>>> sys.path.append('/home/zhaorong/Desktop/')
>>>> from yadeimport import *
> =======================================================
>
> But when I used the same method in python3, it failed.
> =======================================================
> zhaorong@ubuntu64:~/Desktop$ python3
> Python 3.7.3 (default, Oct 7 2019, 12:56:13)
> [GCC 8.3.0] on linux
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import sys
>>>> sys.path.append('/home/zhaorong/Desktop/')
>>>> from yadeimport import *
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "/home/zhaorong/Desktop/yadeimport.py", line 71
> print 'Yade version: %s%s'%(version,debugbuild)
> ^
> SyntaxError: invalid syntax
> =======================================================
>
> I want to know whether the Yade is imported to Python2 applications only, not Python3 applications.
>
> Thanks.
>
>

Robert Caulk (rcaulk) said : #2

William is partially right, but it looks like you compiled yade version 2019.01a (judging by your filepath name), which does not include python3. You should compile the latest master branch on trunk [1] to get python3 functionality (or any commit past April-ish of 2019, when Fran├žois finished the python3 migration).

[1]https://gitlab.com/yade-dev/trunk/tree/master

Can you help with this problem?

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

To post a message you must log in.