hzjken / crypto-arbitrage-framework

A cryptocurrency arbitrage framework implemented with ccxt and cplex. It can be used to monitor multiple exchanges, find a multi-lateral arbitrage path which maximizes rate of return, calculate the optimal trading amount for each pair in the path given flexible constraints, and execute trades with multi-threading implemenation.
552 stars 172 forks source link

docplex does not work - docplex.mp.utils.DOcplexException: CPLEX runtime not found #15

Open ahmoosavi opened 3 years ago

ahmoosavi commented 3 years ago

Hello,

I have coded a mathematical model and want to solve it using DOCPLEX module. My interpreter is Python 3.7. However, after doing a lot of effort, I will face the following error:

Traceback (most recent call last):
File "C:/Users/xxx/PycharmProjects/pythonProject/EPC _LTC.py", line 155, in <module>
solution = mdl.solve(log_output=True)
File "C:\Users\xxx\PycharmProjects\pythonProject\venv\lib\site-packages\docplex\mp\model.py", line 4222, in solve
return self.fatal("CPLEX runtime not found: please install CPLEX or solve this model on DOcplexcloud")
File "C:\Users\xxx\PycharmProjects\pythonProject\venv\lib\site-packages\docplex\mp\model.py", line 894, in fatal
self._error_handler.fatal(msg, args)
File "C:\Users\xxx\PycharmProjects\pythonProject\venv\lib\site-packages\docplex\mp\error_handler.py", line 210, in fatal
raise DOcplexException(resolved_message)
docplex.mp.utils.DOcplexException: CPLEX runtime not found: please install CPLEX or solve this model on DOcplexcloud

I have already run the following codes in my Pycharm's terminal:

cd C:\Program Files\IBM\ILOG\CPLEX_Studio201\python
python setup.py install

or

cd C:\Program Files\IBM\ILOG\CPLEX_Studio201\python
python setup.py install --home C:\Users\xxx\PycharmProjects\pythonProject\venv\Lib\site-packages\cplex

Finally, I also set the path variables of my own username to something like below:

"C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\python\3.6\x64_win64" and
"C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\bin\x64_win64\cplex.exe"
hubuser3976 commented 3 years ago

Hi moosavi-69, "I have already run the following codes in my Pycharm's terminal:

cd C:\Program Files\IBM\ILOG\CPLEX_Studio201\python python setup.py install I have already run the following codes in my Pycharm's terminal:"

I solved this issue on Fedora 33 by taking these steps:-

Activate your virtual environment from the command prompt. then...

cd C:\Program Files\IBM\ILOG\CPLEX_Studio201\cplex\python\VERSION\PLATFORM\ Then I used "pip install ." You should be able to use YOUR python package manager (no sure if it is pip or not) on Windows

This will install the cplex runtime base files in your virtual environment (NOTE: your virtual environment must be activated for this to work)

Hope that helps :)

ahmoosavi commented 3 years ago

Hi moosavi-69, "I have already run the following codes in my Pycharm's terminal:

cd C:\Program Files\IBM\ILOG\CPLEX_Studio201\python python setup.py install I have already run the following codes in my Pycharm's terminal:"

I solved this issue on Fedora 33 by taking these steps:-

Activate your virtual environment from the command prompt. then...

cd C:\Program Files\IBM\ILOG\CPLEX_Studio201\cplex\python\VERSION\PLATFORM Then I used "pip install ." You should be able to use YOUR python package manager (no sure if it is pip or not) on Windows

This will install the cplex runtime base files in your virtual environment (NOTE: your virtual environment must be activated for this to work)

Hope that helps :)

Thank you so much for your help. I have already done that. But it was not helpful because I am facing another error. You might kindly see the new error that I am facing on this page.

If you still need any information to be able to help me, please let me know to provide them.

Thanks!

hubuser3976 commented 3 years ago

Hi moosavi-69,

I came across that page in my search for a solution too....but it not the solution to your problem. Did you carefully check the path I posted? I does not point to the \python\setup.py file you already executed.

The path I posted points to YOUR_CPLEX_DIR\cplex\python\VERSION_NUMBER\YOUR_PLATFORM\

Once you cd into that directory you can type "pip install ." from inside your virtual environment. (NOTE: Be sure to include the . ) Thats it! Done.

Also, make sure you did not receive the "no cplex wrapper detected" warning when you first ran the cplex installer. If you did receive this warning you may have to re-install from inside your activated virtual environment. This will install a local virtual environment copy of cplex. With that done, you can then cd to the path above and type "pip install ."

Let me know how you go. :)

ahmoosavi commented 3 years ago

Hi moosavi-69,

I came across that page in my search for a solution too....but it not the solution to your problem. Did you carefully check the path I posted? I does not point to the \python\setup.py file you already executed.

The path I posted points to YOUR_CPLEX_DIR\cplex\python\VERSION_NUMBER\YOUR_PLATFORM\

Once you cd into that directory you can type "pip install ." from inside your virtual environment. (NOTE: Be sure to include the . ) Thats it! Done.

Also, make sure you did not receive the "no cplex wrapper detected" warning when you first ran the cplex installer. If you did receive this warning you may have to re-install from inside your activated virtual environment. This will install a local virtual environment copy of cplex. With that done, you can then cd to the path above and type "pip install ."

Let me know how you go. :)

Hiii!

Thank you so much for spending your time and helping me. I did what you said as shown in the below image:

image

However, I am again facing the bellow error :(

image

hubuser3976 commented 3 years ago

ok...I think perhaps you first may have installed Cplex initially from outside your virtual environment. That's fine...but now you have to install another copy INSIDE your environment before running the next script.

Try this:- RUN WINDOWS TERMINAL AND NOT CMD TERMINAL Install "Windows Terminal" from the Micosoft Store (this is a PowerShell Terminal) Run Windows Terminal

CHECK VIRTUAL ENVIRONMENT SITE-PACKAGES FOR CPLEX INSTALLATION cd "C:\Users\xxx\PycharmProjects\pythonProject\venv\lib\site-packages\cplex\ dir (or ls) You should see something like the screenshot below. If you do not, or the cplex directory does not exist in site-packages above, then it needs to be installed there. You can do this by following the steps below.

Screenshot from 2021-04-19 09-10-14

REMOVE ENVIRONMENT VARIABLES "C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\python\3.6\x64_win64" and "C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\bin\x64_win64\cplex.exe"

FROM WINDOWS TERMINAL PROMPT cd "C:\Users\xxx\PycharmProjects\pythonProject (Activate your VENV) source venv/bin/activate (venv) cd C:\Program Files\IBM\ILOG\CPLEX_Studio201\python (venv) python setup.py install --home C:\Users\xxx\PycharmProjects\pythonProject\venv\Lib\site-packages\cplex (This command needs to be run from (venv) promtp )

Then, rerun the next script like so:- (venv) cd C:\Program Files\IBM\ILOG\CPLEX_Studio201\cplex\python\3.7\x64_win64\ (venv) pip install . ***(Try to avoid using --ignore-installed -V) and don't forget the dot

If all goes well, Cplex should correct any errors. Let me know how it goes.

ahmoosavi commented 3 years ago

ok...I think perhaps you first may have installed Cplex initially from outside your virtual environment. That's fine...but now you have to install another copy INSIDE your environment before running the next script.

Try this:- RUN WINDOWS TERMINAL AND NOT CMD TERMINAL Install "Windows Terminal" from the Micosoft Store (this is a PowerShell Terminal) Run Windows Terminal

REMOVE ENVIRONMENT VARIABLES "C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\python\3.6\x64_win64" and "C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\bin\x64_win64\cplex.exe"

If all goes well, Cplex should correct any errors. Let me know how it goes.

Thank you again. I did what you said (the first part) and saw a very similar result as your screenshots. Please see my own results below:

image

Anyway, I tried to go to the second stage and see what happens. Thus, I removed the abovementioned paths from both "user variable" and "system variable." For example, the paths in my "user variable" look like below:

image

Finally, I run the coded you mentioned in Windows PowerShell as below:

image

However, I face the same error! Sorry if it is causing inconvenience. Your help is much appreciated. If you do not have time, please ignore this message (I do not want to take your time more than this.)

hubuser3976 commented 3 years ago

@moosavi-69

You haven't done what I suggested. What you have done is run the YOUR_CPLEX_DIR\cplex\python\3.7\x64_win64\setup.py script.... (you missed an important step)

If you don't want to follow my suggestions, that's fine, we can do this instead:- As a test case, create a new venv of your choice *(do not delete your existing environment) Once you activated your new (venv) prompt, do this:-** STEPS TO TAKE:- (PLEASE NOTE: There are two different paths shown below for Cplex folders)

  1. (venv) pip install ccxt
  2. (venv) pip install docplex
  3. (venv) cd C:\Program Files\IBM\ILOG\CPLEX_Studio201\python ****(this is the first cplex folder shown)
  4. (venv) python install setup.py ***(no need to specify --home path since your (venv) is active)
  5. (venv) cd C:\Program Files\IBM\ILOG\CPLEX_Studio201\cplex\python\3.7\x64_win64 ****(this is the second, and different, cplex folder shown)
  6. (venv) pip install . ***(Try to avoid using --ignore-installed -V) and don't forget the dot
  7. (venv) cd
  8. (venv) cp "C:\Users\xxx\PycharmProjects\pythonProject\"*.py . ***(this will copy only .py files from your old project)
  9. (venv) cp -r "C:\Users\xxx\PycharmProjects\pythonProject\crypto" ***(this will copy the crypto folder from your old project)
  10. (venv) python main.py

I hope this is helpful. :)

PS. If you want, you can create your package.json and package-lock.json files like this:-

  1. (venv) cd
  2. (venv) pip install
ahmoosavi commented 3 years ago

@moosavi-69

You haven't done what I suggested. What you have done is run the YOUR_CPLEX_DIR\cplex\python\3.7\x64_win64\setup.py script.... (you missed an important step)

  1. (venv) python main.py

I hope this is helpful. :)

PS. If you want, you can create your package.json and package-lock.json files like this:-

  1. (venv) cd
  2. (venv) pip install

Ohh, I see my mistakes. Sorry for that. I do want to follow your suggestion. Just now, I did your previous suggestion (as shown below), but still the problem exists.

image

I will do your latest suggestion and will update you about the result. Thanks so much.

ahmoosavi commented 3 years ago

@hubuser3976

Holly molly. I just created a new project file and followed your second suggestion. Everything is fine now. I do not know why it was not working with the previous project! Anyway, I am so so much grateful for your time and kind attention. Without your help, I could not resolve this problem.

hubuser3976 commented 3 years ago

@moosavi-69

Welcome