How to import third party Python module in Flux
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
Answers
-
Hello,
You will find attached a word document which explains the differents steps to us Num Py in Flux.
Best regards.
0 -
Thank you so much!
0 -
You are welcome. For your information this will be available in Flux 2018.1,which will be available soon.
Best regards.
0 -
Altair Forum User said:
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
0 -
Your remark is taken into account.
Best regards0 -
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).
0 -
Altair Forum User said:
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.
0 -
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.
0 -
Hi,
Here is the link :
All this information will be available in Flux 2020.
Best regards.
0 -
Altair Forum User said:
Hi,
Here is the link :
All this information will be available in Flux 2020.
Best regards.
Hi, it seems the link doesn't work yet.
Could you fix it?
Thanks
0 -
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:-
CPython 2.7.1: https://www.python.org/download/releases/2.7.1/
This is the only CPython version for which the NumPy experimentation was tested. Some issues have been observed when other versions were installed instead of or next to version 2.7.1
-
JyNI 2.7 alpha 5: https://github.com/Stewori/JyNI/releases/tag/v2.7-alpha.5
Download both- The generic JyNI.jar
- The platform-specific archive corresponding to your environment. For example on Windows 64 bits use: JyNI-2.7-alpha.5-bin-win-amd64.zip
- NumPy 1.13.3: https://pypi.org/project/numpy/1.13.3/
Download the numpy-1.13.3-cp27-xxxxx.whl archive corresponding to your platform
Step-by-step
Follow the steps below to install and configure NumPy for Flux:- Ensure that no other CPython or NumPy module is already installed on the machine
- Install CPython 2.7.1
- 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
- Create a UserLib directory to store the additional Python module required to use NumPy. For example: %INSTALLFLUX%\Third_party\jython-2.7.1\userlib
- Install JyNI
- Copy JyNI.jar into: %INSTALLFLUX%\Third_party\jython-2.7.1\javalib
- 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
- Install NumPy
- Unzip the numpy-13.3.3-cp27-xxx.whl archive into your UserLib folder
-
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
- Starts Flux Supervisor
- Configure the Flux Supervisor options to use your UserDLL and UserLib folders for all Flux modules (2D, 3D, Skew, PEEC)
- Open the Options dialog by clicking on the Options button in the bottom left
- In the dialog’s navigation tree select the Access Paths > Python node
- Enter the User Python scripts directory by typing the path to your UserLib folder
- Enter the User libraries directory by typing the path to your UserDLL folder
- Apply the changes and close the dialog by clicking OK
- Open the Options dialog by clicking on the Options button in the bottom left
- Start Flux from the Supervisor
- In Flux, test you can use NumPy functions
- In the PyFlux shell enter the following Python code to define a 3x5 matrix and print it in the console:
-
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]]
- In the PyFlux shell enter the following Python code to define a 3x5 matrix and print it in the console:
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
- What should I do?
0 -