Pyomo 6.0 on WinPython 3940: best way to install Ipopt? - pyomo

There is no "pip install ipopt".
What is the best way to proceed then, once I installed Pyomo?
I dropped a copy of Ipopt.exe in the "python-3.9.4.amd64" forlder, and it works.
But it looks a bit dirty to me!
I use Pyomo since a long time, and installing Ipopt or Glpk has always been an uncertainty.
On colab, azure notebooks, and now winpython.
Thanks
Michel

Place the .exe somewhere and make sure to add the directory to the PATH. The same goes for glpk.
The python folder you mentioned is probably on the system's path and that’s why it works.

Related

Using IPOPT with Openmdao (or pyoptsparse) in python

Hello everyone. I have a little problem : I am working with openmdao and pyOptSparseDriver. It is working for some solvers (SLSQP, PSQP for instance) so there is no problem about that installation.
Now i'd like to try the same with IPOPT, but the code is not given with pyoptsparse. I followed the COIN-OR documentation to install IPOPT (http://www.coin-or.org/Ipopt/documentation/node10.html), and everything SEEMS ok (i don't know how to check it). Now i have a COIN-OR folder on my desk and i don't know how to make pyoptsparse take IPOPT from it (it is the line "from . import pyoptcore" that crashes), from pyIPOPT/pyIPOPT.py.
Can anyone help me ?
Thank you by advance
we're using IPOPT with OpenMDAO through the pytoptsparse package, and installed it as a standalone library, like you've done. To get that to work you need to set the IPOPT_DIR environment variable pointing to the location you installed IPOPT before running the install of pyoptsparse.
So assuming you installed IPOPT in e.g. /usr/local/IPOPT:
$ export IPOPT_DIR=/usr/local/IPOPT
$ cd /path/to/pyoptsparse/
$ python setup.py install
this should result in pyoptsparse compiling the python wrapper for IPOPT and produce the file pyoptcore.so that will be placed in Python's site-packages/pyoptsparse/pyIPOPT.
On our cluster we had to modify the pyoptsparse/pyIPOPT/setup.py file slightly since we compiled everything with Intel, but if you compile with gfortran the official version of pyoptsparse should work for you.
Alternatively, you can do like Justin suggests, which is essentially the instructions you find in the pyoptsparse docs.
you have to put the ipopt source code into the src folder of pyopt-sparse and then recompile the package.

pip not working on windows 10

I am using python 2.7.10 on a windows 10 computer
In power shell pip does not work in any directory. In python27\scripts .\pip will work. My path is correct, but there are two in system variables "Path" and "PSModulePath". The "PSModulePath" has the Python27\Scripts in the proper place.
Any suggestions.
I know that you've checked already but, it's most likely the Environmental Variables.
You can fix this here.
Another reason for pip not working is the version of Python/Pip you're using.
You can update this here.

Python site-packages and corresponding interpreter

I used brew to install python 2.7 and 3.5 on Mac. SOMEHOW I have this site-packages directory /usr/local/lib/python2.7/site-packages.
But every python interpreter on the system points to every other site-packages directory EXCEPT this one. How do I use THIS site-packages directory?
(This is all because I need Vips. I'd installed this before, but now I'm using a different machine and I can't figure out how on Earth I got it to work before.)
The vips docs have a checklist and an explanation of what happens when Python tried to import vips:
http://www.vips.ecs.soton.ac.uk/supported/current/doc/html/libvips/using-from-python.html
But briefly you need to:
You have several Pythons installed, make sure you are invoking the brew one.
Make sure that that Python has a gi repository containing the Vips.py overrides.
Make sure you have a Vips-8.0.typelib file in /usr/local/lib/lib/girepository-1.0/.
SOLVED.
I didn't want to have to resort to resetting my dev box to factory settings, but I did. I hope this helps somebody...
If Python already exists on your system, and you're planning on installing Python yourself or with Homebrew (because you only get python2.7 out of the box), make sure you install the new Python first. Then put the install location first in your PATH. Then install your modules. In that order. I knew something was wrong, so I uninstalled Python/3 and Vips. But when I reinstalled them, for whatever reason Vips still didn't know to bind itself to the Python in /usr/local/Cellar. Even though I had /usr/local/Cellar first in PATH.
So to recap -- first install Homebrew, then set the PATH, then install python/python3, and finally install Vips. And you're good to go.

Pyomo can't locate GLPK solver

I'm trying to use the GLPK solver with Pyomo. I have a working model that's been tested, but keep getting an error saying GLPK can't be found.
WARNING: Could not locate the 'glpsol' executable, which is required for solver 'glpk'
I've installed glpk sucessfully. I also added the directory to my path variable so the executed can be called globally. I tested this with glpsol --help from my command line, and see the help info printed.
The below thread says it should be working, but alas, it is not.
How do you install glpk-solver along with pyomo in Winpython
Any ideas?
This answer is late but I want to share the solution that worked for me.
solvername='glpk'
solverpath_folder='C:\\glpk\\w64' #does not need to be directly on c drive
solverpath_exe='C:\\glpk\\w64\\glpsol' #does not need to be directly on c drive
I used to do this:
sys.path.append(solverpath_folder)
solver=SolverFactory(solvername)
This works for the cbc solver in coin-or but it does not work for glpk. Then I tried something different:
solver=SolverFactory(solvername,executable=solverpath_exe)
This worked for both cbc and glpk. No idea why this works (I really didn't do anything else).
Version: Python 2.7 or Python 3.7 (tested both), glpk 4.65
You can install glpk solver using this command -
brew install glpk
Installing the glpk package worked for me. As I use Anaconda:
conda install -c conda-forge glpk
This was after already including the 'glpsol' exectuable's folder path in my PATH variables.
So it looks like the set path variable is not handled by your Python installation.
A normal Python installation is set up for a seperated "PYTHONPATH" environment variable to look up additional modules.
There is also the option to make an entry in the windows registry or (like you already mentioned) move the files to the Python home directory, which is recognized relative to your installation directory if "PYTHONHOME" is not set.
More information in the Python Documentary under 3.3.3.
https://docs.python.org/2/using/windows.html#finding-modules
I was having the same issue. I don't know if this is a solution but it definitely got the solver working.
After downloading the Windows installation. I copied all the files in the w64 folder and pasted them directly into my Python working directory.
After that my python code could locate the solver.
NOTE: this was for Python 3.4.3.4, Windows 8.1 64 bit
Reading the source code here suggests you try:
from pyutilib.services import register_executable, registered_executable
register_executable(name='glpsol')
maybe will it give a clue
I had the same issue on Windows 10 and it was down to glpk being installed in a different conda environment. Full steps for installing pyomo and glpk below.
Test the installation by running 'Repeated Solves' example from https://pyomo.readthedocs.io/en/latest/working_models.html
Instructions (run at an anaconda prompt)
conda create --name myenv
conda activate myenv
conda install -c conda-forge pyomo
conda install -c conda-forge pyomo.extras
conda install -c conda-forge glpk
Run spyder from myenv so that if finds everything
spyder activate myenv
Here is the relevant part where pyomo 6.2 searches for the glpsol executable
https://github.com/Pyomo/pyomo/blob/568c6595a56570c6ea69c3ae3198b73b9f473abd/pyomo/common/fileutils.py#L288
def _path():
return (os.environ.get('PATH','') or os.defpath).split(os.pathsep)
There are two options to solve the PATH problem:
Putting the executable in an available folder in PATH (recommended practice). The glpsol executable must be in one of the folders present in the PATH system environment variable. Use in your code print(os.environ['PATH']) to see the available folders and put it there.
Adding the folder to PATH at runtime. You can add it to the system PATH statically or use code to add it dynamically (only while your script is running):
GLPK_FOLDER_PATH = "path/to/glpk"
os.environ["PATH"] += os.pathsep + str(GLPK_FOLDER_PATH)
In my case, my Python project has a virtual environment .venv, and I have an installation process that pastes the files essential to the glpsol executable when I install the project inside the .venv/Scripts folder. Because that folder is added automatically to the system PATH when Python is called from the virtual environment, libraries like Pyomo can find it. And I don't have to remember to add the folder to PATH at runtime whenever I want to use Pyomo.
For anyone that has the same issue, I found a workaround (not a solution!). I copied all the glpk files into my C:/Python27 directory, and (Surprise!) Python can now find them.
I'll hold out for a real solution before accepting this one.

Installing PostgreSQL and pyscopg2 on Snow Leopard

I'm still a complete beginner in the field of web development and I'm trying to set up the Django environment. I'm reading "the definitive guide to django" to start my practice.
I'm running Snow Leopard (10.6.2) on a macbook 2.1GHz. It came with Python 2.6.1. Since Snow Leopard cam with Python 2.6.1 preinstalled, so I didn't do any extra set up. Maybe it needs more setup, please let me know. But I've ran it, and it works.
I installed django straight right from the book. I've ran it, and so far it works.
The Database configuration is the one stifling me.
I tried installing MySQL with MySQLdb module for python, but it had complications with the difference between 32 & 64 bit architecture (either mysql had 64 and python had 32 OR vice versa; Either way, I couldn't figure it out). I've read many forums and tinkered with it for hours, still couldn't fix it and I just gave up.
So I tried the next best thing (or so I thought), Let's try to set up Postgre instead. So, I went to the official Postgre website and picked the Mac OS X installment package. I download it, extract it, and all it had was an ".app" installer and a "README". I ran the installer, blah blah blah, I followed the instruction, it did this, it did that. At the end, apparently Postgre is installed.
I didn't feel completely sure if it was installed, so I searched around the internet for some answers. Well, I found the official documentation for installing Django for Mac, but the steps to install
Postgre was completely different. Maybe the ".app" installer did most of the configuration listed in those steps, I don't know.
Then I went to the terminal and type in:
psql -V
(to check which version of Postgre I just installed)
AND
sudo -u postgres pg_ctl start
(to run the database)
'psql' or 'pg_ctl' commands could not be found. To me, this is kind of saying Postgre was not installed or there are some setup I still need to do.
So I started looking at the first steps of installing Postgre from the given instruction by Django (link above). From the instruction it says to edit the '~/.profile', even after unhiding all the files and directories, I still can't find it under my user directory.
At this point I'm just kind of frustrated and don't know where to go. I was wondering if I can get some direction/tips/howto/anythingreallyatthispoint.
I can't really install psycopg2 until I have Postgre running, but from the looks of it, it doesn't look so bad to install it (or so I hope).
Many Many thanks in advance for any help ^_^
-Tri
If you're just getting started, I would try sqlite first. It's file based, so there is almost no configuration. Later, if you want to upgrade to a real database, then it won't be any harder than what you're attempting now.
the easiest way to install these apps would be via macports (http://www.macports.org/). in my experience, the installation was fast and clean. the geodjango installation documentation has a good section on this: http://geodjango.org/docs/install.html#macports.
I suspect the only problem you are having is not setting path. Add this to your ~/.bash_profile:
export PATH=/Library/PostgreSQL/8.4/bin:$PATH
Now you should be able to run the command line tools like psql.
I just spent a couple hours going through multiple different walkthroughs. This was the one that eventually worked:
first install postgress with the dmg:
http://www.enterprisedb.com/products-services-training/pgdownload#osx
then follow this tutorial:
http://stubblog.wordpress.com/2009/06/07/installing-psycopg2-on-osx/
then put this in terminal export DYLD_LIBRARY_PATH=/Library/PostgreSQL/9.3/lib:$DYLD_LIBRARY_PATH
And I'm pretty sure those were the important parts of what I did..
if you get errors try sudo pip uninstall psycopg2 then sudo pip install psycopg2
if you keep getting errors about ".... something < 10.4", reinstall pip. I think I used something like brew install python to update python... if you don't have homebrew, get it. I'm pretty sure that's what got rid of that error.. it may have been a manual install of pip3 though.
Sorry this is all over the place, it should get you a bit closer though. At least, if you (like me) have had none of the other tutorials work.