question

jacopo-r avatar image
0 Likes"
jacopo-r asked jacopo-r commented

Step-by-step guide for installing Cplex and use it in Flexsim

Hi everyone,

I am currently struggling with using Cplex (in a python code) through FlexSim.

I managed to get the connection between FlexSim and Python working and I tested it out with a simple code returning the sum of two numbers I give as parameters, and that works.

I installed Cplex and if I run a python code with a cplex model in Jupyter Notebook it works, but when I try to call that function from FlexSim it does not. I started to think that there could be something wrong "behind the scene". I read something about setting the environment variables properly and stuff like that. I have to admit that I am not an expert in this kind of things, so I decided to look for someone very patient and willing to explain step by step how I should install and make sure that cplex is properly set for FlexSim.

Thank you all in advance :)

FlexSim 23.0.1
pythoncplexsetting cplex
5 |100000

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

1 Answer

Kavika F avatar image
2 Likes"
Kavika F answered jacopo-r commented

Hey @jacopo_r, I have a few questions that may help me identify your issue.

1. What version(s) of Python is installed on your machine? You can identify this by opening up Windows PowerShell and typing

py -0

This will print out the list of python versions you have installed on your Windows machine.

2. Is Python in your System/User Variables? You can find this by going to System Properties (which you can find by simply searching for "Environment Variables").1684343999641.png

After clicking the option above to edit system environment variables, you'll get the window below.

1684344378935.png

Click the Environment Variables button and another window will pop up with those variables. In your User variables and System variables, you'll see variables called "Path". Double click on each of them and look for paths related to Python. For example:

%APPDATA%\..\Local\Programs\Python\<PYTHON_VERSION>\Scripts

Or something along those lines. You can also go to that location by putting the address in your File Explorer to see if there's actually anything there.

3. Does your FlexSim Global Preferences use the same Python version as the one you have installed? You can check this by opening FlexSim, going to Global Preferences, selecting the "Code" tab, and checking your Python Version.

1684344631789.png


1684343999641.png (41.1 KiB)
1684344631789.png (9.2 KiB)
1684344392695.png (37.6 KiB)
· 19
5 |100000

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

jacopo-r avatar image jacopo-r commented ·

Hi @Kavika F ,

my python version is 3.10 and it is in line with the python version I selected in the Global Preferences of Flexsim. However, I don't think I have any Environment Variable related to Python either in the User or System variables. I can see I have variables related to Cplex in the system variables, and the only one containing the name python is the one below, which is the only one called " Path".
1684398489231.png(I had to take a screenshot cause I couldn't copy it, but if you open the image file it should be readable)

(I can see the name Gurobi in the path. I installed Gurobi but I am not actually using it cause I switch to Cplex)

So, I guess this could be at least one issue.

Looking forward to hear back from you!

Thank you very much!

0 Likes 0 ·
1684398489231.png (6.2 KiB)
jacopo-r avatar image jacopo-r jacopo-r commented ·

I forgot to mention that even though there are no Python Path Variables related, I managed to connect FlexSim with Python and run a simple sum or feeding a global table to python and return the sum of rows (as you suggested in here https://answers.flexsim.com/questions/141940/running-a-python-code-with-cplex-through-flexsim.html). But when I try to run a python script including a cplex optimization model, then it does not work.

:)

0 Likes 0 ·
Kavika F avatar image Kavika F ♦ jacopo-r commented ·

Paths are separated by semicolons; I can see that Python actually is in your path. That makes sense since you can use it for FlexSim already.

The only thing I can think of is that maybe your python version doesn't have the docplex or cplex libraries installed. Have you tried opening a PowerShell and running

pip install docplex

and

pip install cplex

? What does it say after you run those? If they are installed, then it should say something along the lines of "you already have this installed" or "this library is up to date". If not, then it will download them.

0 Likes 0 ·
Show more comments