question

Guillem F avatar image
0 Likes"
Guillem F asked Guillem F commented

v22.1 "Code Binding Error: could not bind to function"

I'm trying to test the new python external code functionality (release 22.1) through alan.zhang's example on 'Future Python and FlexSim integration':

pymod.py

python-test.fsm

The following error pops:

exception: Code Binding Error: could not bind to function
Node: /Tools/UserCommands/python_test/code
Binding string: external python "pymod" "PyFunc"
Windows Error Code : 126

A similar error was discussed in 'Cannot bind to Python function', but quite not the same, as I'm saving both the flexsim and the python docs in the same folder.

I'm not sure if the python environment matters (currently using Spyder), but at this point I could blame it on anything, since I tried many things but the error persists.

I appreciate any attention, thanks in advance.

FlexSim 22.1.0
python
pymod.py (34 B)
python-test.fsm (28.2 KiB)
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Guillem F avatar image Guillem F commented ·
0 Likes 0 ·

1 Answer

Phil BoBo avatar image
1 Like"
Phil BoBo answered Guillem F commented

The model and python script are fine.

Make sure you have installed and configured python correctly on your system.

Python's location should be in your PATH environment variable, and the correct version number of that Python install should be specified in the Code tab of your Global Preferences in FlexSim:

1650471072768.png



1650471072768.png (178.8 KiB)
· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Guillem F avatar image Guillem F commented ·

I've added python to my User and System PATH environment variables (Not sure if I should change both). Now my flexsim model crashes when it connects to external code. The name of the archive makes no difference: the model would just crash with any given archive name on the 'external code' code.

When checking if python is on my PATH with cmd, it shows the following:

Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated.  Libraries may fail to load.  To activate this environment
please see https://conda.io/activation

Which I could solve temporarily by executing in cmd:

C:\Users\Flexsim\anaconda3\Scripts\activate base

But still get the same crashing problem on flexsim.

(I also tried reinstalling python and anaconda, and tried many other that led to no improvement)

0 Likes 0 ·
Guillem F avatar image Guillem F Guillem F commented ·

It worked, by uninstalling anaconda and reinstalling python from python.org.

0 Likes 0 ·