Installing Pyomo on Windows with Anaconda (Python) - python

I would like to solve LP and ILP with Pyomo (Coopr) but unfortunately I am so newbie and I cannot run it properly.
I have already installed Pyomo (Coopr) by following its instructions
pip install Coopr
I can import the module without problems:
$ python
Python 2.7.5 |Anaconda 1.8.0 (64-bit)| ...
Type "help", "copyright", "credits" or "license" for more information.
>>> import coopr.pyomo
>>>
At this point is where I get lost since I can't find the path where in theory I have installed the package
(/coopr.pyomo/examples/pyomo/diet).
I think I have to create an enviroment but I have recently read that there is a better integration now with conda v. 2.1 (link)
There is a branch of conda (new-pypi-install) that adds better integration with pip and PyPI. In particular conda list will also show pip installed packages and conda install will first try to find a conda package and failing that will use pip to install the package.
My final goal is to implement this into an IPython notebook and be able obtain the results as output.
Note: I am trying to run the demo file
pyomo diet1.py diet.dat

It is 2017 and pyomo can be easily installed via conda
conda install -c conda-forge pyomo pyomo.extras
To install LP and NLP solvers, conda can also be used.
conda install -c cachemeorg glpk ipopt_bin
If you are in a Mac or linux, you can install updated versions using conda-forge.
conda install -c conda-forge glpk ipopt
If you prefer to install pyomo or solvers via pip:
Check that the PATH on windows where is located pyomo.exe is indeed C:\Anaconda\Scripts
Besides, the PATH was set correctly since the cmd recognized the pyomo command at the beginning
With:
echo %path%
on the cmd you can get a list of all the paths (where the C:\Anaconda\Scripts\ is included"
So with Anaconda it was only necessary to set the path where the glpsol.exe is located, to do that from the cmd.exe and considering that you have unzipped your winglpk on "C:\glpk\w64":
setx path "%path%;c:\glpk\w64"
After that, restart the cmd and navigate with the "cd" command where you have the data.py and data.dat
Finally it works! Thanks to the mailing list of pyomo project for the indications
For more information I recommend to read the next links:
wingplk:
http://en.wikibooks.org/wiki/GLPK/Windows_executables
setting the path on windows 7:
http://www.voidspace.org.uk/python/articles/command_line.shtml
https://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them

In Acandona Navigator, go to "Environments" and then, where says "base (root)", open the terminal and type:
conda install -c conda-forge pyomo
Additionally, if you want to install the glpk solver, execute:
conda install -c conda-forge glpk
To check all your available solvers, executing the following:
pyomo help --solvers
To solve the problem, execute:
pyomo solve diet1.py diet.dat

Related

pybrain install in env but No module named 'pybrain'

I'm new to python and Anaconda
I have python 3.8 in my (base) env, and i need pybrain, so since it's not compatible with my current version of python, i created a new env(first i tried all of it with python 3.5, didn't work, so i tried 2.7, same result):
conda create --name py27 python=2.7
then activated it:
conda activate py27
and installed pybrain there:
conda install -c mq pybrain
I checked that it has been installed successfully with:
conda list
pybrain 0.3.3 py27_0 mq
after launching jupyter notebook from same terminal, with (py27) as the 'header'?? of my command line, it opened successfully, i even checked that currently it's opened in expected environment, by typing in a cell:
!conda info
and as i expected, saw the line
active environment : py27
but also, which i guess is importnant:
python version : 3.8.3.final.0
though i am confused with ouput of:
!python --version
cause it's:
Python 2.7.18 :: Anaconda, Inc.
So when i open my notebook i type
import pybrain
and i get:
No module named 'pybrain'
Please point me in direction: what i'm doing wrong? Also it is my first virtual env(distinct from the (base) one), so i probably missing some important concepts.
Fortunately i've found a solution to use pybrain with python3 - i just downloaded it from source !pip install https://github.com/pybrain/pybrain/archive/0.3.3.zip and it works in python 3.8

The anaconda-navigator stops working after installing gdal

I am new to python and anaconda
I am using Windows 10 and Python 3.5
After installing gdal with the command (in the Anaconda prompt)
>conda install -c conda-forge gdal
the anaconda-navigator does not launch anymore and I get the error message:
pythonw: This application failed to start because it could not find or load the Qt platform plugin "windows" in "".
I think it is because some packages were downgraded... during the installation I got the message:
The following packages will be DOWNGRADED due to dependency conflicts:
anaconda-navigator: 1.3.1-py35_0 --> 1.2.3-py35_0
matplotlib: 1.5.3-np111py35_0 --> 1.5.1-np111py35_0
what is the best way to solve this problem?
I found two solutions to this problem, I think the second one is better:
Solution 1: I first solved this problem by using python 2.7 instead of 3.5.
In fact with the command:
>conda install gdal
I got the following message:
UnsatisfiableError: The following specifications were found to be in conflict:
- gdal
- python 3.5*
Use "conda info <package>" to see the dependencies for each package.
So I created a new environment with python 2.7, following the instructions here
>conda create -n py27 python=2.7 anaconda
activate py27
Then I installed the gdal (and other packages I needed)
>conda install gdal
It is then possible to directly launch the anaconda-navigator (just typing anaconda-navigator in the command line. Also opening the anaconda-navigator from the menu I can select the environment with "application on: py27" and start spyder in this environment.
Solution 2: I kept using python 3.5 but instead of using conda install I downloaded the compatible binaries from the "Unofficial Windows Binaries for Python Extension Packages"
>pip install <package-path>

How can I install XGBoost package in python on Windows

I tried to install XGBoost package in python.
I am using windows os, 64bits . I have gone through following.
The package directory states that xgboost is unstable for windows and is disabled:
pip installation on windows is currently disabled for further invesigation, please install from github.
https://pypi.python.org/pypi/xgboost/
I am not well versed in Visual Studio, facing problem building XGBoost.
I am missing opportunities to utilize xgboost package in data science.
Please guide, so that I can import the XGBoost package in python.
Thanks
If you are using anaconda (or miniconda) you can use the following:
conda install -c anaconda py-xgboost UPDATED 2019-09-20
Docs
Other channels available, such as rapidsai/py-xgboost UPDATED 2021-12-07
Check install by:
Activating the environment (see below)
Running conda list
To activate an environment:
On Windows, in your Anaconda Prompt, run (assumes your environment is named myenv):
activate myenv
On macOS and Linux, in your Terminal Window, run (assumes your environment is named myenv):
source activate myenv
Conda prepends the path name myenv onto your system command.
Build it from here:
download xgboost whl file from here (make sure to match your python version and system architecture, e.g. "xgboost-0.6-cp35-cp35m-win_amd64.whl" for python 3.5 on 64-bit machine)
open command prompt
cd to your Downloads folder (or wherever you saved the whl file)
pip install xgboost-0.6-cp35-cp35m-win_amd64.whl (or whatever your whl file is named)
You first need to build the library through "make", then you can install using anaconda prompt (if you want it on anaconda) or git bash (if you use it in Python only).
First follow the official guide with the following procedure (in Git Bash on Windows):
git clone --recursive https://github.com/dmlc/xgboost
git submodule init
git submodule update
then install TDM-GCC here and do the following in Git Bash:
alias make='mingw32-make'
cp make/mingw64.mk config.mk; make -j4
Last, do the following using anaconda prompt or Git Bash:
cd xgboost\python-package
python setup.py install
Also refer to these great resources:
Official Guide
Installing Xgboost on Windows
Installing XGBoost For Anaconda on Windows
You can pip install catboost. It is a recently open-sourced gradient boosting library, which is in most cases more accurate and faster than XGBoost, and it has categorical features support.
Here is the site of the library:
https://catboost.ai
pip install xgboost works also with python 3.8, whereas other options mentioned above did not work for me
The following command should work but, If you have a problem with this command
conda install -c conda-forge xgboost
First activate your environment . Assume your environment is named
simply write in conda terminal :
activate <MY_ENV>
and then
pip install xgboost
on a macOS the following command worked
conda install -c conda-forge xgboost but before doing this i had read some other article and hence did install gcc using brew
Besides what's already on developers' github, which is building from source(creating a c++ environment, etc.), I have found an easier way to do it, which I explained here with details. Basically, you have to go a website by UC Irvine and download a .whl file, then cd to the folder and install xgboost with pip.
XGBoost is used in Applied Machine Learning and is known for its gradient boost algorithm and it is available as a library in python but has to be compiled using cmake.
Alternatively what you can do is from this link you can download the C pre-compiled library and install it using the pip install < FILE-NAME.whl> command. Ensure you have downloaded the library which is compatible with your python version.
I experienced this problem while I was using the same in Anaconda(Spyder). Then just restart the kernel and your error will go away.

How to install xgboost in Anaconda Python (Windows platform)?

I am a new Python user. I downloaded the latest Anaconda 3 2.4.1 (Python 3.5) from the below link:
https://www.continuum.io/downloads
My PC Configurations are: Windows 10, 64 bit, 4GB RAM
I have spent hours trying to find the right way to download the package after the 'pip install xgboost' failed in the Anaconda command prompt but couldn't find any specific instructions for Anaconda.
Can anyone help on how to install xgboost from Anaconda?
The easiest way (Worked for me) is to do the following:
anaconda search -t conda xgboost
You will get a list of install-able features like this:
for example if you want to install the first one on the list mndrake/xgboost (FOR WINDOWS-64bits):
conda install -c mndrake xgboost
If you're in a Unix system you can choose any other package with "linux-64" on the right.
Update on 22/10/2020:
Without searching in conda list of channels, you can install it using (source: https://anaconda.org/anaconda/py-xgboost) :
conda install -c anaconda py-xgboost
Anaconda's website addresses this problem here: https://anaconda.org/anaconda/py-xgboost.
conda install -c anaconda py-xgboost
This fixed the problem for me with no problems.
Download package from this website.
I downloaded xgboost-0.6-cp36-cp36m-win_amd64.whl for anaconda 3 (python 3.6)
Put the package in directory C:\
Open anaconda 3 prompt
Type cd C:\
Type pip install C:\xgboost-0.6-cp36-cp36m-win_amd64.whl
Type conda update scikit-learn
After trying some things the only thing that worked for me is:
conda install -c anaconda py-xgboost
I was able to install xgboost for Python in Windows yesterday by following this link. But when I tried to import using Anaconda, it failed. I recognized this is due to the fact that Anaconda has a different Python distribution. I then searched again and found this great article which made it!
The trick is after installing successfully for regular Python, to have it work for Anaconda, you just need to pull up the Anaconda prompt and cd into this folder "code\xgboost\python-package", then run:
python setup.py install
And voila! The article says you need to add the path, but for me it worked directly. Good luck!
Also copied below the original contents in case the link is not available...
Once the last command completes the build is done. We can now install
the Python module. What follows depends on the Python distribution
you are using. For Anaconda, I will simply use the Anaconda prompt,
and type the following in it (after the prompt, in my case [Anaconda3]
C:\Users\IBM_ADMIN>):
[Anaconda3] C:\Users\IBM_ADMIN>cd code\xgboost\python-package
The point is to move to the python-package directory of XGBoost. Then type:
[Anaconda3] C:\Users\IBM_ADMIN\code\xgboost\python-package>python setup.py install
We are almost done. Let's launch a notebook to test XGBoost.
Importing it directly causes an error. In order to avoid it we must
add the path to the g++ runtime libraries to the os environment path
variable with:
import os
mingw_path = 'C:\\Program Files\\mingw-w64\\x86_64-5.3.0-posix-seh-rt_v4-rev0\\mingw64\\bin'
os.environ['PATH'] = mingw_path + ';' + os.environ['PATH']
We can then import xgboost and run a small example.
import xgboost as xgb
import numpy as np
data = np.random.rand(5,10) # 5 entities, each contains 10 features
label = np.random.randint(2, size=5) # binary target
dtrain = xgb.DMatrix( data, label=label)
dtest = dtrain
param = {'bst:max_depth':2, 'bst:eta':1, 'silent':1, 'objective':'binary:logistic' }
param['nthread'] = 4
param['eval_metric'] = 'auc'
evallist = [(dtest,'eval'), (dtrain,'train')]
num_round = 10
bst = xgb.train( param, dtrain, num_round, evallist )
bst.dump_model('dump.raw.txt')
We are all set!
I'm able to install using the following commands (in Windows 10) :
conda install -c mikesilva xgboost
conda install -c conda-forge xgboost
GUYS ITS NOT THAT EASY:-
PLEASE FOLLOW BELOW STEP TO GET TO MARK
So here's what I did to finish a 64-bit build on Windows:
Download and install MinGW-64: sourceforge.net /projects/mingw-w64/
On the first screen of the install prompt make sure you set the Architecture to x86_64 and the Threads to win32
I installed to C:\mingw64 (to avoid spaces in the file path) so I added this to my PATH environment variable: C:\ mingw64 \ mingw64 \ bin(Please remove spaces)
I also noticed that the make utility that is included in bin\mingw64 is called mingw32-make so to simplify things I just renamed this to make
Open a Windows command prompt and type gcc. You should see something like "fatal error: no input file"
Next type make. You should see something like "No targets specified and no makefile found"
Type git. If you don't have git, install it and add it to your PATH.
These should be all the tools you need to build the xgboost project. To get the source code run these lines:
cd c:\
git clone --recursive https://github.com/dmlc/xgboost
cd xgboost
git submodule init
git submodule update
cp make/mingw64.mk config.mk
make -j4
Note that I ran this part from a Cygwin shell. If you are using the Windows command prompt you should be able to change cp to copy and arrive at the same result. However, if the build fails on you for any reason I would recommend trying again using cygwin.
If the build finishes successfully, you should have a file called xgboost.exe located in the project root. To install the Python package, do the following:
cd python-package
python setup.py install
Now you should be good to go. Open up Python, and you can import the package with:
import xgboost as xgb
To test the installation, I went ahead and ran the basic_walkthrough.py file that was included in the demo/guide-python folder of the project and didn't get any errors.
if you found an issue when you try to import xgboost (my case it is Windows 10 and anaconda spyder) do the following:
Click on the windows icon (start button!)
Select and expand the anaconda folder
Run the Anaconda Prompt (as Administrator)
Type the following command as it is mentioned in https://anaconda.org/anaconda/py-xgboost
conda install -c anaconda py-xgboost
That's all...Good luck.
You can download the xgboost package to your local computer, and you better place the xgboost source file under D:\ or C:\ (ps: download address: http://www.lfd.uci.edu/~gohlke/pythonlibs/#xgboost, and select "xgboost-0.6-cp35-cp35m-win_amd64.whl",but it is up to your operation system), and you open the Anaconda prompt, type in pip install D:\xgboost-0.6-cp35-cp35m-win_amd64.whl, then you can successful install xgboost into your anaconda
Try running this on Anaconda prompt
pip install xgboost
This worked for me on Spyder with Python 3.5
I figured out easy way to install XgBoost by mix of what is mentioned here.
Step 1:
Install gitbash from here and start gitbash.
Step 2: git clone --recursive https://github.com/dmlc/xgboost
Step 3: git submodule init
git submodule update
step 4: alias make='mingw32-make'
step 5: cp make/mingw64.mk config.mk; make -j4
step 6: Goto Anaconda prompt and if you have a conda environment then activate that environment like my was py35 so I activate it by typing activate py35
cd python-package
python setup.py install
step 7: setup the Path in system environment variable to the path where you installed xgboost/python-package.
Use this in your conda prompt:
python -m pip install xgboost
The following worked for me:
conda install libxgboost
The package directory states that xgboost is unstable for windows and is disabled:
pip installation on windows is currently disabled for further invesigation, please install from github.
https://pypi.python.org/pypi/xgboost/
Anaconda3 version 4.4.0check image
Go to Anaconda -> Environments -> from the dropdown select not installed -> If you can see xgboost pr Py-xgboost select and click apply.
There are a lot of dependencies of anaconda that have changed over the past years and won't work if you used them now. Some of the answers need serious updation.
I found this command did the job for me :
conda install -c conda-forge xgboost
You may also want to look at the official documentation of anaconda for xgboost:
https://anaconda.org/conda-forge/xgboost
I have used this command and it worked for me.
import sys
!{sys.executable} -m pip install xgboost
Open anaconda prompt and run
pip install xgboost
You can install it using pip:
pip3 install --default-timeout=100 xgboost
This simple helped me you don't have to include anything at the end because if you include something, some of your packages will be upgraded but some will be downgraded.
You can get this from this url: https://anaconda.org/anaconda/py-xgboost
conda install -c anaconda py-xgboost
Look here https://github.com/Rafi993/xgboost/ for building xgboost on your machine. There are many different varieties of the solution above, but it seems that the version in the link above is the good one. At least that worked for me: I've tested it on Windows 7 and Windows Server 2008.
Then run the following commands in cmd in order to install python bindings:
cd python-package
python setup.py install
You might also need a proper mingw (google for tdm-gcc)
and the latest setuptools from anaconda.
I hope it will help

Tensorflow and Anaconda on Ubuntu?

On my Ubuntu 14.04, I have installed tensorflow, using "pip", as specified in the Tensorflow Installation instructions and I made sure it was working by importing it in python and it did work.
Then, I installed Anaconda and it changed my .bashrc file by adding the following line to it:
export PATH="/home/sonny/anaconda2/bin:$PATH"
But because of this change, now it looks into the PATH above, which doesn't contain tensorflow. now I can't import tensorflow in my python code.
What is the proper way to extend the $PATH environment variable so that it stays using everything from anaconda2 but it becomes able to import "tensorflow"?
I solved the problem but in a different way!
I found a link where the tensorflow.whl files were converted to conda packages, so I went ahead and installed it using the command:
conda install -c https://conda.anaconda.org/jjhelmus tensorflow
and it worked, since the $PATH points to anaconda packages, I can import it now!
Source is here
Since v0.10.0, tensorflow is a community maintained conda package in the conda-forge channel. Hence, it can be installed directly with the following command:
conda install -c conda-forge tensorflow
The instructions on the TensorFlow documentation has also been updated.
To facilitate future updates, it is probably a good idea to add conda-forge channel into your conda config:
conda config --add channels conda-forge
In fact, tensorflow=0.10.0rc0 was recently added onto the Anaconda default channel and will be installed instead if the conda-forge channel is not specified:
conda install tensorflow
I had the same problem and decided it was easiest to start over, install Anaconda first and then TensorFlow after that.
I suspect that pip is giving you a TensorFlow installation in cpython, not anaconda.
How about a virtualenv?
# Create env
$ virtualenv --python=/path/to/anaconda /path/to/your/env
# Activate env
$ source /path/to/your/env/bin/activate
# Install Tensorflow
$ pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl
Install tensorflow from the following command. Conda will take care of the installation process.
conda install -c conda-forge tensorflow
I solved the problem using this:
conda create --name=tensorenv python=3.4
source activate tensorenv
Actually, the TensorFlow Official website made every detail of installing.
The Operation System Windows, Mac OS, Ubuntu; the environment with GPU or just CPU, every single detail of problems you may come up with.
Check this out
Installing TensorFlow on Ubuntu with Anaconda
you will not regret.
Once you visit that you may also find like
Installing TensorFlow on Windows with Anaconda

Categories

Resources