How to import third party Python module in Flux

Altair Forum User
Altair Forum User
Altair Employee
edited October 2020 in Community Q&A

Hi,

 

I want to use a 3rd party Python module (numpy, which I successfully installed in Python 2.7) in Flux. When I tried ' import numpy' in command prompt in Flux the error comes as

 

Can not execute the following command :
import numpy

Problem to import the module : numpy
Enter sys.path to see if this module is accessible from your jython session
 

I guess my problem is the 3rd party module is not installed in C:\Altair\Flux_12.3\Third_party\python. So how can I install and use 3rd party Python modules in Flux?

 

Kind regards,

 

Chen

Tagged:

Answers

  • asoualmi
    asoualmi
    Altair Employee
    edited November 2020

    Hello,

    You will find attached a word document which explains the differents steps to us Num Py in Flux.

    Best regards.

    Unable to find an attachment - read this blog

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited July 2018

    Thank you so much!

  • asoualmi
    asoualmi
    Altair Employee
    edited July 2018

    You are welcome. For your information this will be available in Flux 2018.1,which will be available soon.

    Best regards.

     

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited July 2018

    You are welcome. For your information this will be available in Flux 2018.1,which will be available soon.

    Best regards.

     

    That's great!

     

    Actually I (and many other Flux users I believe) find out there is little information about using Python to manipulate Flux, which is a very powerful way to make more use of Flux. If the Flux development group can provide more material/tutorials on this subject in the future, it's going to be very helpful for Flux users, especially for those who already have some knowledge of Python. 

     

    Kind regards,

     

    Chen

  • asoualmi
    asoualmi
    Altair Employee
    edited July 2018

    Your remark is taken into account.
    Best regards

  • Romain B
    Romain B Altair Community Member
    edited January 2019

    Hi, 

     

    I definitely agree with qchen regarding the doc :-)

    I have a similar question:

    I'm trying to import one of my scripts (imprtScrpt.py) in another script (mainScrpt.py). The imported script only contains functions.

    The only solution that I've found until now is to call 'executeBatchSpy('imprtScrpt.py')' in mainScrpt. When I simply try 'import imprtScrpt', mainScrpt exits without any message.

     

    Am I doing something wrong?

     

    Thank you very much in advance for your help!

     

    PS: until now, I've been ok with importing by using executeBatchSpy, but my script is starting to get quite big and I'd like to use imports to use profiling tools (such as doxy).

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited February 2019

    I'm trying to import one of my scripts (imprtScrpt.py) in another script (mainScrpt.py). The imported script only contains functions.

    The only solution that I've found until now is to call 'executeBatchSpy('imprtScrpt.py')' in mainScrpt. When I simply try 'import imprtScrpt', mainScrpt exits without any message.

     

    I would like to get an answer to the same question as well.

  • Vincenzo
    Vincenzo Altair Community Member
    edited March 2020

    Hi,

    the link in previous discussion with the file 'how to use Numpy in flux' seem to do not work anymore. Can you upload the document again?

    Thank you.

     

  • asoualmi
    asoualmi
    Altair Employee
    edited March 2020
  • Vincenzo
    Vincenzo Altair Community Member
    edited April 2020

    Hi, it seems the link doesn't work yet.

    Could you fix it?

    Thanks

  • asoualmi
    asoualmi
    Altair Employee
    edited April 2020

    The link work fine just it is available in Flux 2020.

    How to Experiment with NumPy in Flux?

     

    Introduction

    NumPy is a Python module widely used in scientific computing area and could improve the capacity of what Flux users could achieve when they write PyFlux scripts.

    However, NumPy is a native C-Python module whereas PyFlux scripts are executed by Jython, a Java Python interpreter, which is not able to execute C Python modules thus preventing NumPy usage with Flux.

    Nowadays a third-party project named JyNI (Jython Native Interface) provides an experimental solution to execute native C Python with the Jython interpreter, starting with Jython 2.7.1

    Since Flux 2018.1 release, Flux has been upgraded to use Jython 2.7.1 and it becomes possible to use the JyNI library to experiment with native C Python modules like NumPy.

    Disclaimer

    The JyNI library is a third-party library which is still in alpha version and NumPy support with Jython remains experimental. This means that Altair is not responsible for maintaining or fixing bugs related to NumPy integration with JyNI and Jython.

    Besides, usage of NumPy with Flux has not been qualified in the current release and nothing has been made to allow a smooth and seamless integration of NumPy with Flux. On the contrary there are known limitations and issues: See the Troubleshooting section for more details.

    Prerequisite

    Using NumPy with Flux requires the users to download the following third-party libraries:

    Step-by-step

    Follow the steps below to install and configure NumPy for Flux:
    1. Ensure that no other CPython or NumPy module is already installed on the machine
    2. Install CPython 2.7.1
    3. Create a UserDLL directory to store the additional DLLs that will be required to use NumPy with Flux. For example: %INSTALLFLUX%\Third_party\jython-2.7.1\userdll
    4. Create a UserLib directory to store the additional Python module required to use NumPy. For example: %INSTALLFLUX%\Third_party\jython-2.7.1\userlib
    5. Install JyNI
      1. Copy JyNI.jar into: %INSTALLFLUX%\Third_party\jython-2.7.1\javalib
      2. Extract the JyNI.dll folder from the platform-specific archive into your UserDLL directory. Be careful to copy the JyNI.dll folder ifself (not only its content) inside the UserDLL directory
    6. Install NumPy
      1. Unzip the numpy-13.3.3-cp27-xxx.whl archive into your UserLib folder
      2. Look for the NumPy DLL inside: <UserLib>/numpy/core

        and copy it to your UserDLL folder

        The name of the DLL to copy depends on the platform-specific archive you downloaded. For example for windows 64 it is named:

        libopenblas_v0.2.20_mingwpy.dll

    7. Starts Flux Supervisor
    8. Configure the Flux Supervisor options to use your UserDLL and UserLib folders for all Flux modules (2D, 3D, Skew, PEEC)
      1. Open the Options dialog by clicking on the Options button in the bottom left
        experiment1.png
      2. In the dialog’s navigation tree select the Access Paths > Python node
      3. Enter the User Python scripts directory by typing the path to your UserLib folder
      4. Enter the User libraries directory by typing the path to your UserDLL folder
      5. Apply the changes and close the dialog by clicking OK
    9. Start Flux from the Supervisor
    10. In Flux, test you can use NumPy functions
      1. In the PyFlux shell enter the following Python code to define a 3x5 matrix and print it in the console:
        experiment2.png
      2. Execute the code by clicking on the red arrow on the left of the PyFlux shell

        You should see the following output in the Flux console:

        [[ 0 1 2 3 4]

        [ 5 6 7 8 9]

        [10 11 12 13 14]]

    Troubleshooting

    • Flux does not start any more after I configured NumPy for Flux
      • What should I do?

        Look at Flux Supervisor Options and ensure that you have configured the User libraries directory for the module (2D,3D, Skew, PEEC) you are trying to use, even if you do not want to use NumPy for this specific module.

      • <li