Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
calculate_python_expression [2020/04/28 12:24]
argemiro created
calculate_python_expression [2023/07/13 15:45] (current)
admin
Line 3: Line 3:
 ===== Description ===== ===== Description =====
  
-This functor runs an Python instance with the defined user expression.+This functor runs an Python instance with the defined user expression. For an overview of how Dinamica and Python can be linked together check the documentation about [[python_coupling|Dinamica EGO and Python Coupling]]
  
 ===== Inputs ===== ===== Inputs =====
Line 15: Line 15:
 ^ Name ^ Type ^ Description ^ ^ Name ^ Type ^ Description ^
 | result | [[struct_type|Struct]]| A struct containing the output values generated by the expression. ​ | | result | [[struct_type|Struct]]| A struct containing the output values generated by the expression. ​ |
 +
 +===== Notes =====
 +
 +DinamicaEGO allows installing libraries from within python scripts:
 +
 +Simply install and load the numpy library:
 +<​code>​dinamica.package("​numpy"​)</​code>​
 +
 +You can specify a version like you do on pip:
 +<​code>​dinamica.package("​numpy",​ "​numpy==1.19.5"​)</​code>​
 +
 +You can install and load a library that has different name from its project, in this case the package is called "​segment_anything_py"​ but it can only be imported "​segment_anything":​
 +<​code>​dinamica.package("​segment_anything_py",​ "​segment_anything_py",​ "​segment_anything"​)</​code>​
 +
 +And you can also use all pip parameters as you want, for example installing from a remote wheel and loading dependencies from a custom repository ​ "​--index-url https://​download.pytorch.org/​whl/​cu118"​.
 +<​code>​dinamica.package("​segment_anything_py",​ "​https://​files.pythonhosted.org/​packages/​43/​2f/​dabe75d90a7eb54a0a609a0fc5c36d1933256319beaea5d6b2f176e213a2/​segment_anything_py-1.0-py3-none-any.whl ​ --index-url https://​download.pytorch.org/​whl/​cu118",​ "​segment_anything"​)</​code>​
 +
 +Or use it in a more complex pipeline. For example: install the "​cython"​ and "​numpy"​ dependencies to clone and compile a python library from a git repository: ( of course the git executable must be on the path for cloning a repository)
 +<​code>​
 +dinamica.package("​cython"​)
 +dinamica.package("​numpy"​)
 +dinamica.package("​pycocotools",​ "​git+https://​github.com/​philferriere/​cocoapi.git#​egg=pycocotools&​subdirectory=PythonAPI"​)
 +</​code>​
  
 ===== Group ===== ===== Group =====