How do you install glpk-solver along with pyomo in Winpython - python

I want to use "pyomo" for my studies. I installed pyomo via easy_install
coopr install instructions, Pyomo needs a solver to work so I wanted to install the
(GNU Linear Programming Kit) glpk_webpage, pyomo seems to be installed just right because I can import it in spyder (i am using WinPython-64bit-2.7.5.3) with
import coopr.pyomo
However, I cannot do anything without glpk I guess...
I downloaded glpk-4.52 (latest version) from the ftp server but I do not know what to do with the batch files I found in the "w64"-folder I should use(?) according to "Installing GLPK"
I do not have Visual Studio installed - Isn't it possible to work without it?

I recently installed GLPK for use with python 3.5 and pyomo under windows 7 and would like to report how I succeeded. I installed pyomo via:
pip install pyomo
Then, download WinGLPK 4.55 from here: WinGLPK
This does not work for newer versions at the moment.
Unzip it and copy the whole w64 folder to C:\w64
Include folder C:\w64 in your system PATH (so that glpsol.exe is found).
Check your installation using the simple example from the official pyomo documentation:
pyomo solve abstract1.py abstract1.dat --solver=glpk
The files abstract1.py and abstract1.dat can also be found in the pyomo documentation.
I hope this will help the next desperate GLPK installer.

FYI, you can now use Coopr without installing local solvers. The latest Coopr release supports an interface with the NEOS solver. For example, if your MILP model is in the file model.py, then the following command would optimize the model using CBC:
pyomo --solver-manager=neos --solver=cbc model.py

Better late than never: in order to use GLPK (executable glpsol.exe), it must be somewhere on your sytem environment variable "Path". For sake of an example, let's assume you put the GLPK executable into the folder C:\GLPK\bin. Then (steps copied from this answer by melhosseiny):
Hold Win and press Pause.
Click Advanced System Settings.
Click Environment Variables.
Append ;C:\GLPK\binto the Path variable.
Restart command prompt.
Now try to launch glpsol from any directory. If it is found, pyomo should now be able to use it.

If you are using Anaconda, both pyomo and glpk can be installed with conda install. In the Windows terminal, activate your conda environment, then:
conda install -c conda-forge pyomo
conda install -c conda-forge glpk
To test the glpk installation:
glpsol --help

Related

System libraries in conda environment not seen by reticulate

I'm trying to get the R package reticulate working on a CentOS 7.8 system using RStudio Server v1.2.5042 with a custom environment created with conda. When I initiate a Python job with reticulate, I get an error that some system libraries are not the correct versions, specifically, libstdc++.so.6 and libz.so.1.
First off, I realize CentOS 7.8 is a bit old and some of the problem might be solved by upgrading the OS, but that's not an option in this case.
The conda environment does work and I can run the target Python script in a terminal window without any errors. In RStudio using reticulate, the code is extremely simple at this point:
library(reticulate)
use_condaenv('test')
py_run_file('test_script.py')
When the script is run, I get the following error:
ImportError: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by /home/<user>/.conda/envs/test/lib/python3.8/site-packages/scipy/_lib/_uarray/_uarray.cpython-38-x86_64-linux-gnu.so)
When I look into the /usr/lib64 directory, I find libstdc++.so, but running strings libstdc++.so | grep ^GLIBC | sort shows me that it indeed does not support version GLIBCXX 3.4.21. No surprises. If I navigate to the /home/<user>/.conda/envs/test/lib directory, I find another copy of libstdc++.so.6 and this one does support version GLIBCXX 3.4.21. So, the correct version of the library is present in the correct conda environment directory, but for some reason RStudio and reticulate are not finding it.
I tried changing LD_LIBRARY_PATH to have the conda environment directory listed first, but that does not work. I found a lengthy discussion here, which points out that LD_LIBRARY_PATH isn't really a good fix unless it is set prior to the RStudio process initialization. (And then goes on a tangent about which version of Python gets used.) For my situation, there may be multiple conda environments to support and it isn't possible to know which will be active for any given session, and any given user my use different/multiple environments. I would rather not try to harmonize all conda environments into one, big, uber-environment.
I've also verified that the Python version and other libraries are correctly set:
python: /home/<user>/.conda/envs/test/bin/python
libpython: /home/<user>/.conda/envs/test/lib/libpython3.8.so
pythonhome: /home/<user>/.conda/envs/test:/home/<user>/.conda/envs/test
version: 3.8.5 (default, Aug 5 2020, 08:36:46) [GCC 7.3.0]
numpy: /home/<user>/.conda/envs/test/lib/python3.8/site-packages/numpy
numpy_version: 1.19.1
NOTE: Python version was forced by use_python function
I have been able to get it running by resetting the links in /usr/lib64 to point to the copy in the conda directory. While this gets it working for this instance, I'm not sure I want to push a fix like this to production. My guess is that if I link to the most inclusive version of the library across all conda environments, and that version fully supports all versions that the system level library supports, everything will be fine, but this feels like a hack, at best.
If anyone has found a good solution to this, I would appreciate to know the details.
After struggling with a similar issue for several days, and trying many of the suggested solutions on the web (mostly based on symlinks, LD_LIBRARY_PATH variable, or installing/upgrading/downgrading packages like libgcc), I finally found something that is only mentioned once here : https://github.com/rstudio/reticulate/issues/338#issuecomment-415472406
The problem possibly seems to be a conflict when R is installed on the OS (with apt-get r-base for example) rather than with (Ana/Mini)conda.
In that case, it will try to load system libraries rather than conda environment ones.
So here is a possible solution to people still having this kind of issue, that worked for me :
(maybe optional) uninstall R on the local system : apt-get remove r-base r-base-dev
Activate conda environment : conda activate my_R_env
Install R within this environment : conda install r r-essentials --channel conda-forge
Install R packages like reticulate inside the same env : conda install r-reticulate --channel conda-forge
You can check that your Python packages installed within your conda environment are now properly loaded with reticulate :
R
> library(reticulate)
> repl_python()
>>> import pandas or any package that was causing the initial issue
Note : I still had some issues due to R loading base conda environment instead of activated one, but deactivating/reactivating environments or calling use_condaenv('my_R_env') seems to solve the problem.

unable to install pymorph

I'm trying to install 'pymorph' on mac os x with 'PIP':
sudo pip install pymorph
I'm getting the following error:
NameError: name 'execfile' is not defined
Command "python setup.py egg_info" failed with error code 1 in
/private/tmp/pip-build-9hjd5tfm/pymorph/
I have read that using a python version different from 2.7 could lead to this kind of problem. Yet, I'm using the 2.7 version:
python --version
Python 2.7.13
Any ideas to solve this issue ?
Thank you in advance
It's possible to have a pip command on your PATH that comes from a different Python installation than the python command. (Each entry script to a Python-based tool is bound to the Python installation that was used to install the package that provided it. This means that the pip command does not search PATH for a python installation.) If this pip comes up later on PATH than python, it would lead to behaviour that you describe.
This can happen, say, if you first install a Python 2.7 without pip, and then a Python 3.x with pip, if the installers prepend to PATH.
You can verify which version of Python pip is using and where it's installed by running pip -V.
The robust solution to this should be using a virtual environment that lets you tie the base python installation and libraries specific to your application alone with your project, as well as avoid cluttering your global site-packages, and prevent inadvertent compatibility issues from different versions of the same package being needed by different projects.
It seems that the current (as of late 2017) recommended virtual environment solution is Pipenv. A decent-looking introduction to virtual environments using Pipenv, by the author of Pipenv, can be found here.

Can't install PuLP in Anaconda

Python newbie here. I am trying to install PuLP. So I do a pip install Pulp in conda command prompt and looks like pulp gets installed. I run a conda list and I can see that PuLP is there in the list (please see image).
However, when I try importing PuLP in IDLE,i get an error and I also can't see PuLP in the list of environments in Anaconda navigator (not sure if I am supposed to).
If Pulp is in the list, why can't I import it or see it in Navigator. Any inputs will be appreciated.
You can try:
conda install -c conda-forge pulp
You have installed an standalone Python, and other Python with Anaconda.
First, if you installed a package by the pip, it is O.K. that it is not displayed in installed packages in Anaconda environment(s) (as you installed it out of Anaconda) and at the same time it is fully functional.
Second, you have to install PuLP again for your standalone Python (with the same pip install command - this time not in conda command prompt, but directly in you OS console / terminal / DOS-prompt (depends of your OS).

How do you install Tensorflow on Windows?

I am trying to install Tensorflow on Windows.
I have Anaconda 4.2.0. I tried running
conda create -n tensorflow python=3.5
in my command prompt. This seemed to do something, but I'm not sure what this accomplished. It created a folder within the Anaconda3 program in my username folder.
This folder is filled with the following content:
Over the summer, I used mainly Jupyter Notebooks to do my python coding. Within this environment, there is a tab marked Condas
So it looks like I should be able to switch to the Tensorflow environment. But this doesn't work when I try to switch, there is no option to change my kernel to a Tensorflow one.
I tried running
conda search tensorflow
But nothing appears.
I'm not sure what to do. I asked a few grad students in my economics research group, but they weren't sure what to do either.
My Question
How do I properly install Tensorflow on Windows?
The syntax of the command is conda create -n <name_of_new_env> <packages>. As a result, you created a clean environment named tensorflow with only Python 3.5 installed. Since conda search tensorflow returned nothing, you will have to use pip or some other method of installing the package. Since there is spotty official support for Windows, the conda-forge package (CPU only) at https://github.com/conda-forge/tensorflow-feedstock is probably the best way.
People have also reported success installing Tensorflow with docker, if you have docker set up already.
I was able to run it under the Windows 10 linux subsystem (https://msdn.microsoft.com/en-us/commandline/wsl/install_guide)
Which is basically a linux environment within windows.
The latest tensorflow version (0.12) added windows support
https://www.tensorflow.org/get_started/os_setup#pip_installation_on_windows
just run:
pip install --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-0.12.1-cp35-cp35m-win_amd64.whl
(the url is for the specific version - you will need to change it for future versions or other setups)
An Anaconda environment isolates itself completely with the outer world, so all the packages you installed outside the virtualenv is nothing in the virtualenv, if you want to use Tensorflow in the environment(seems like the only way with Anaconda), use activate tensorflow command and install the packages you want seperately.
pip provides an easy method to install tensorflow on windows machine.
use the following pip command
pip install --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-0.12.0rc0-cp35-cp35m-win_amd64.whl
Tensorflow only support python3.5 x64 bit on windows machines and it requires that you install Visual C++ 2015 redistributable (x64 version) to be able to import tensorflow

Python - pip install pandas, not working

I am trying to install pandas via pip install pandas but when I do, I get the error:
Command python setup.py egg_info failed with error code 1 in
c:\users[username]\appdata\local\temp\pip_build_[username]\pandas
I followed the answer given here and installed ez_setup.py without incident, but still get the error when doing pip install pandas.
Thanks for any help, if I can provide more information please let me know.
The easiest way to install pandas and its dependencies on Windows is to download the relevant packages from Christoph Gohlke's Python Extension Packages for Windows repository. You'll find the files for pandas here as well as a list of other required dependencies.
On Linux (Debian / Ubuntu varieties), when NOT installing inside a virtual environment, but in the main system, I find it best to just use the Synaptic Package Manager (because even the --user switch seems to fail when trying to install pandas without sudo). Search for pandas inside Synaptic PM. There's varieties for python 2 and 3.
However, on linux, I have generally found the cleanest, easiest, and overall safest approach to be creating virtual environments and then use pip install <package name> inside the virtual environment. I believe this would be best on Windows too.
I installed Pandas package following procedure listed after the following disclaimer section:
Disclaimer:
- I don't consider myself a computer expert so follow the instructions at your own risk.
- My procedure worked on my windows computer
- My windows computer has python 2.7 installed from python.org
- My python GUI is IDLE
- I don't recall installing pip, it is possible that it installs at the time of installing python 2.7 from python.org (not sure)
- The directory in which my pip.exe is located is under C:\Python27\Scripts
Procedure:
Open a command window for the directory under which you have pip.exe, (in my case is Scripts). The prompt looks like this in my case: C:\Python27\Scripts>
At the prompt type pip install pandas. The prompt looks like this in my case: C:\Python27\Scripts>pip install pandas
Press ENTER key. You should see message: "Collecting pandas" being displayed in the command window.
Once the system completes collecting pandas, you should see message "Successfully installed pandas-0.22.0" , or similar depending on version collected.
Picture shows steps 1 -4 as shown in my computer command window.collecting_pandas

Categories

Resources