wiki:IDEforOT

How to setup a Integrated Development Environment for OpenTURNS

Abstract

In this page, we describe how to install and configure a development environment for OpenTURNS. More precisely, we present a method to install an configure the Spyder interactive development environment for the Python language on Windows and on Linux.

Installing OT+Spyder on Windows

Introduction

The Python environment we suggest to use is Python XY, which comes with Spyder IDE.

On Windows, for OpenTURNS >= 1.1, the steps are:

  • install PythonXY 2.7,
  • install OpenTURNS 1.1,
  • check the installation.

This process is simple, because OpenTURNS now comes as a Python module, directly installed into the Python environment. This way, the user has nothing to do to let OpenTURNS Spyder.

However, OpenTURNS v<=1.0 comes with an independent Python environment. Hence, we have to let Spyder know where OpenTURNS is installed. In other words, on Windows, for OpenTURNS <= 1.0, the steps are:

  • install PythonXY 2.6,
  • install OpenTURNS 1.0,
  • setup the PYTHONPATH and PATH environment variables,
  • check the installation.

Install Pythonxy for Windows

PythonXY installers are available at:

http://code.google.com/p/pythonxy/wiki/Downloads

It should be noticed that the installed version of Pythonxy must be consistent with the Python interpreter used by OpenTURNS.

For example, for OpenTURNS 1.1, this is Python 2.7. Therefore, we can install the binary "Python(x,y)-2.7.3.1.exe" from :

http://ftp.ntua.gr/pub/devel/pythonxy/

By default, this executable installs the binaries into the

C:\Python27

directory.

Install the Windows version of OpenTURNS

The files are available at :

http://sourceforge.net/projects/openturns/files/openturns/

More precisely, we can install:

  • openturns-1.1-py27.exe
  • openturns-developer-1.1.exe

By default, the OpenTURNS files are then installed into the directory:

C:\Python27\Lib\site-packages

This is the default directory for Python packages, so that the OT module is automatically known by the Python environment, including Spyder.

Check the installation for OT v>=1.1

Now that Spyder is launched, we can just import the openturns module, as shown in the following figure.

Notice that no message is printed in the console, as for other regular Python modules.

That's it ! No other manual tuning is necessary for OpenTURNS v1.1.

If, on the other hand, we use OpenTURNS v1.0 (or older), then the next steps might be required.

Run Spyder from a script for OpenTURNS v<=1.0

We now make the assumption that OpenTURNS was installed in the

C:\OpenTURNS

directory.

Perhaps the simplest method is to run Spyder from the following script:

SpyderForOpenTURNS-1.1.bat

This script defines the environment variables that Spyder needs to know where OpenTURNS is installed. To use this script, we simply click on it: this launches Spyder with a pre-configured OpenTURNS-aware environment.

Check the installation for OT v<=1.0

The following graphics shows how OpenTURNS 1.0 is imported within Python 2.6:

A screenshot of the OpenTURNS module in Spyder

Manage the environment "by hand" for OT v<=1.0

It is also possible to manage the environment by defining the appropriate environment variables.

Let Spyder know OpenTURNS

To do this, we just have to define the PYTHONPATH environment variable, so that it contains the directory where OpenTURNS is installed.

This can be done by different ways:

  • defining the variable from the Windows configuration dialog,
  • by using the Spyder PYTHONPATH dialog box.

Since the Spyder PYTHONPATH dialog box is simpler, we present this method.

In Spyder, go to the "Tools > Management of PYTHONPATH" dialog box.

The Tools > Manage PYTHONPATH menu entry.

Then push the "+ Add a directory" button and add the directory:

C:\OpenTURNS\lib\python26\site-packages

as in the following figure.

The Spyder PYTHONPATH dialog.

Update the PATH environment variable

This makes so that the dll from OpenTURNS can be known.

This can be done by two different ways:

  • update the PATH environment variable in the Environment Variables Windows dialog box,
  • update the PATH environment variable from a .bat script and run Spyder from there.

Let us present how to update the environment variable from the Environment Variables Windows dialog box.

  • Right-click on "My Computer", select Properties, then Advanced (or open the Configuration Panel, open System and security > System). This may require the admin privileges.
  • Click on the "Environment variables..." button on the bottom right.

This button in the red circle in the following figure.

The System Properties dialog box in Windows

  • This opens a dialog box, where the top part present the user variables, and the bottom part present the system variables.

The Environment Variables dialog box in Windows.

  • In the "System variables" pane, find the "PATH" variable and click on the "Edit..." button.
  • Add the following directory at the begining of the PATH:
C:\OpenTURNS\bin;C:\OpenTURNS\lib\bin;C:\OpenTURNS\opt\R-2.12.0\bin;[other directories...]

Installing OT+Spyder on Linux

On Linux, the simplest way to install OpenTURNS within Spyder is to use the packaging system of the associated distribution.

Install OpenTurns

This can be done by three ways.

For example, on a Ubuntu distribution, we may use the following commands:

sudo apt-get install python-openturns
sudo apt-get install openturns-examples
sudo apt-get install openturns-validation
sudo apt-get install openturns-wrapper

More details are available at:

http://trac.openturns.org/wiki/HowToInstall

Install Spyder

To install Spyder on Linux, we may use the binaries packaged in the Linux distribution.

For example, on a Ubuntu distribution, we may use the following command:

sudo apt-get install spyder

More details are provided at:

http://code.google.com/p/spyderlib/wiki/Installation

Troubleshooting

In this section, we report common errors when we try to use OpenTURNS from Spyder.

Error: ImportError: No module named openturns

On Windows, we try to import the openturns module in the IPython console of Spyder.

In [1]: from openturns import *
------------------------------------------------------------
Traceback (most recent call last):
  File "<ipython console>", line 1, in <module>
ImportError: No module named openturns

The solution is to update the PYTHONPATH variable in order to add the directory where the Python package of OpenTURNS can be found. From the PYTHONPATH dialog box of Spyder, we can add the directory "C:\OpenTURNS\lib\python26\site-packages". See the previous "Let Spyder know OpenTURNS" section above.

Error: ImportError: DLL load failed

On Windows, when we import openturns from Spyder, we get an "ImportError: DLL load failed" error.

In [1]: from openturns import * 
------------------------------------------------------------ 
Traceback (most recent call last): 
  File "<ipython console>", line 1, in <module> 
  File "C:\OpenTURNS\lib\python26\site-packages\openturns\__init__.py", line 89, in <module> 
    from common import * 
  File "C:\OpenTURNS\lib\python26\site-packages\openturns\common.py", line 29, in <module> 
    _common = swig_import_helper() 
  File "C:\OpenTURNS\lib\python26\site-packages\openturns\common.py", line 25, in swig_import_helper 
    _mod = imp.load_module('_common', fp, pathname, description) 
ImportError: DLL load failed: Le module spécifié est introuvable. 

The solution is to update the PATH environment variable in order to add the directories where the OpenTURNS DLLs can be found. See the previous "Update the PATH environment variable" section above.

Another solution is to open a DOS console, and type:

SET PATH=C:\OpenTURNS\bin;C:\OpenTURNS\lib\bin;%PATH%
start C:\Python26\pythonw.exe "C:\Python26\Scripts\spyder"

Error : Unknown R.exe

On Windows, when we try to produce a graphics, OpenTURNS fails with the message:

In [22]: myGraph.draw("MyGraphics")
ViewImage(myGraph.getBitmap())
'R.exe' n'est pas reconnu en tant que commande interne
ou externe, un programme ex‚cutable ou un fichier de commandes.
------------------------------------------------------------
Traceback (most recent call last):
  File "<ipython console>", line 1, in <module>
  File "C:\OpenTURNS\lib\python26\site-packages\openturns\graph.py", line 1471, in draw
    return _graph.Graph_draw(self, *args)
RuntimeError: InternalException : GraphImplementation: error trying to execute R command=R.exe --no-save --silent < "C:\\Users\\Myname\\AppData\\Local\\Temp\\tmp65D.tmp" > NUL

The solution is to update the PATH environment variable and add the path to the directory where R is installed. This is the "C:\OpenTURNS\opt\R-2.12.0\bin" directory. See the previous "Update the PATH environment variable" section above.

Debugging an OT script with Spyder

More details on how to debug an OpenTURNS script with Spyder are presented at:

http://trac.openturns.org/wiki/DebugOTScript

Acknowledgments

Thanks to François Deheeger for sharing his .bat script.

Last modified 5 years ago Last modified on 05/17/13 18:19:25

Attachments (8)

Download all attachments as: .zip