How to install Gurobi in python 3? - python

I tried to install the gurobi package on python 3 but it didn't work. The command that i am using on my macbook is:
pip install gurobipy, but it doesn't work, it shows me this:
ERROR: Could not find a version that satisfies the requirement gurobipy (from versions: none)
ERROR: No matching distribution found for gurobipy`

On macOS gurobipy is automatically installed in the system's python installation. If you need to install it within another python installation or virtual environment, too, then you need to install gurobipy like described at the end of this section in the quickstart guide. It boils down to going to the installation directory of Gurobi, and running an installer script:
(venv) bash-3.2$ cd /Library/gurobi811/mac64/
(venv) bash-3.2$ python setup.py install

fyi for pip installs:
use the following command for python 3.0+
python -m pip install -i https://pypi.gurobi.com gurobipy
obtain the relevant license and activate using grbgetkey (have to download gurobi install files from website to access grbgetkey as that's not installed using pip
copy the gurobi.lic file wherever you initially installed it to the following directory: [your python dir]/site-packages/gurobipy/.libs
**note there is an existing restricted install license in the directory, simply replace it.
Restart the kernel for python and the new license will be activated. No idea why Gurobi hasn't already published this info on their website for python pip installations.

Given that #Robert's answer focused on macOS, the solution below will work for Windows users. The installation process is as follows, per the Gurobi Documentation:
Step 1: Download and Install Anaconda -- see get anaconda for more details. Obviously, you can skip this step if you have Anaconda already installed (which is not uncommon if you are already a Python user).
Step 2: Install Gurobi into Anaconda, which can be done as follows:
The next step is to install the Gurobi package into Anaconda. You do this by first adding the Gurobi channel to your Anaconda channels and then installing the gurobi package from this channel.
From a terminal window issue the following command to add the Gurobi channel to your default search list:
conda config --add channels http://conda.anaconda.org/gurobi
Now issue the following command to install the Gurobi package:
conda install gurobi
Step 3: Install a Gurobi License The third step is to install a Gurobi license (if you haven't already done so).

In this link it is explainded the three ways of installing it. As the pip way is not working, it is possible to use the other ones. The anaconda way it is already covered in this Stackoverflow question. The third way it is also covered in this quiestion by Robert but he only says that this is for MacOs users. Window and Linux users do also get gurobipy installed after installing the optimizer

Related

chocolatey says it has successfully force reinstalled python 3.11 - but I can't find it

Windows 11.
I am not great at virtual environments, and I have bumped around between a half dozen different "solutions." I thought I had it solved with chocolatey, but I am trying to install python3.11, and not having success. Basically, choco says it is installed, but I can't find it anywhere.
C:\Windows\System32>choco install --force python --version=3.11
Chocolatey v1.2.0
Installing the following packages:
python
By installing, you accept licenses for the packages.
python v3.11.0 already installed. Forcing reinstall of version '3.11.0'.
Please use upgrade if you meant to upgrade to a new version.
Progress: Downloading python 3.11.0... 100%
python v3.11.0 (forced) [Approved]
python package files install completed. Performing other installation steps.
The install of python was successful.
Software installed to 'C:\ProgramData\chocolatey\lib\python'
Chocolatey installed 1/1 packages.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
C:\Windows\System32>
This gives the impression that python would be in C:\ProgramData\chocolatey\lib\python, but the only files in that directory are python.nupkgandpython.nuspec`
Where do I go to find my shiny new python?
From PowerShell, run get-command python.exe
And you will get something like this:
CommandType Name Version Source
----------- ---- ------- ------
Application python.exe 0.0.0.0 C:\Users\Paul\AppData\Local\Microsoft\WindowsApps\python.exe
The Source column is where it is running python.exe from and where python is installed.
The python package on the Chocolatey Community Repository is a metapackage. So it does not install python, instead, it has a dependency on python2 or python3 (depending on the version of python), that dependent package is what actually installs Python. So if you install python v3.11, that will have a dependency on python3 v3.11, and the python3 package will download and run the Python installer.
Instead of force installing python, try for installing python3 to rerun the Python installer.
As for the install location, packages install to $env:ChocolateyInstall\lib\. So the .nupkg, .nuspec, chocolateyInstall.ps1, etc will all be there. But the python3 package runs the Python installer, and the Python 3.11.x installer will by default install to C:\python311 when run by the chocolateyInstall.ps1 in the python3 package.

Python: installing packages and downloads

I am trying to set and install some packages with python. I have already installed python3 along with Anaconda.
My first question is that when I type:
$ python3
Anaconda says: "$" is not an internal or external command. Should I be using a different command or how can I fix this?
My second question is this: I am trying to install the packages from these four sites based on a book I got:
NumPy: http://docs.scipy.org/doc/numpy-1.10.1/user/install.html
SciPy: http://www.scipy.org/install.html
scikit-learn: http://scikit-learn.org/stable/install.html
matplotlib: http://matplotlib.org/1.4.2/users/installing.html
This note was in there as well: "If you are on Windows, you should have installed a SciPy-stack compatible version of Python 3".
When I go to copy the line for installing the packages on windows and pasting it into my terminal, it gives the error: "The system can not find the file specified"
How can I fix this?
Don't type the $, just python3.
The packages you mention are already included in Anaconda python distribution.
$ is usually used to indicate the start of a line that should be executed in a terminal window. So, therefore, remove the $ and write everything that comes afterwards.
If you installed Anaconda, then you should have the conda command available to you. Besides scikit-learn, the packages should already be installed with your Anaconda distribution. What you could do is $ conda install scikit-learn and this should install scikit-learn for you.
I recommend you to look at the documentation of Anaconda at the Anaconda website (https://docs.anaconda.com/anaconda/) to learn more on how Anaconda, packages and Python works.
Just as emmv said, a few other things in my mind:
You installed Python with Anaconda. I assume you did not add Python to PATH. You should check Anaconda website for any further installments, downloads etc.
Anaconda uses a simple "conda" command, after all. Really, just look at Anaconda's website if you are confused.

getting python pyobcd installed

I'm a little lost on how to get pyodbc installed in my computer.
I have python 3.6.1
The link
http://support.esri.com/en/technical-article/000011656
pointed me to another link
https://github.com/mkleehammer/pyodbc
Which is vague.
I'm used to downloading and running an exe for install.
This link is unclear and says all I have to do is:
"pip install pyodbc"
What exactly do I need to do to get this working?
Since you have not mentioned which OS you are using,
I will assume that you are on windows (as you have mentioned that you are used to install using .exe).
Firstly you need to know what a pip is:
pip is basically a package manager for python packages used to install 3 rd party packages which do not bundle along with the python distribution.
On linux pip comes pre installed also if you are using python version 3.4 onwards or python 2.7.9 you will be having pip pre installed on your system.
All you have to do it to open the command prompt issue the command
pip install package-name(pyobdc here)
it will do the job.
If you do not find pip in your distribution you can refer this link
How do I install pip on Windows?
open cmd in your computer and type
pip install pyobdc
Hello there and welcome to python programming. Basically python comes with its package installer so either you can go to any interpreter that you are using and type pip install pyobdc or use the command prompt in windows and type in pip install pyobdc. This would install your module and just remember to put import pyobdc at the top of the code if you want to use this package. Further information can be found on here

pip freeze doesn't show anything in Windows installation?

I have Python27 installed in Windows 7
I am trying to build a reddit bot using this tutorial
I found instructions on how to install pip for windows from here
The page says that after installing pip, I can use pip freeze to check if the installation went correctly
It says pip freeze should display some information as shown below
Microsoft Windows [Version 6.2.9200] (c) 2012 Microsoft Corporation.
All rights reserved.
C:\Users\Username>cd c:\Python27\Scripts
c:\Python27\Scripts>pip freeze
antiorm==1.1.1
enum34==1.0
requests==2.3.0 virtualenv==1.11.6
However pip freeze doesn't show me anything at all
Did pip install correctly, or is there any problem? Is there any other way i can test proper installation?
If you want to test it thoroughly, you can use your actual pip installation to install something. For example, numpy would be a good sized example that can rule many problems out.
> pip install numpy
Now, run pip freeze again to check if pip is working as expected. It should then have something to show.
If you want to test it even further, you can open a terminal and
> python
> import numpy
That should be the complete test of your pip installation.
Additionally, whenever I install a new tool in my stack, I like to validate its path with where <executable name> (on Windows) and which <executable name> (on Linux). There are some compilers like Java that are always conflicting with other installations (like crazy, to the point that a complex setup may sometimes have to inject an absolute path to enforce the use of the correct version).
Also, asking the executable for its version can rule many other problems out. In your case, you can use pip --version to check which version you got and compare it to the stable or latest, according to what you want to use.
windows is a confusing piece of software if your coming from a Linux background... the solution that worked for me is the following
pip list
The problem you are facing is that if you only have de default packages in your installation lets say pip, wheel, pip freeze does not have anything to freeze at the moment so that's why dont show anything. try to install a new package then run the command again.

Install a Python package that built for Windows and MacOS on Linux

I have currently used the python Package Larch (https://pypi.python.org/pypi/larch) on Windows. It works nicely and I am really impressed with its performance. To use the package with some large models I want to install it on a Linux server (Ubuntu 14.04.4) where I do not have the root permissions. Though knowing that the OS requirements for the package are Window or MacOS and being a beginner with Linux, I still gave it a try.
I was able to install python locally using anaconda distribution but when I used pip to install larch, I got the following message
Could not find a version that satisfied the requirement larch (from version: )
No matching distribution found for larch
So it seems to me that I can not just deliberately try to install the package on linux with out any additional work. I then tried to find solutions for my issue but I could not find any. Therefore I would like to ask if there is any workaround for my problem?
Thank you so much for your help!
[Edit]
larch does not support python2.x, and only support Windows, MACOSX.
For installing in Linux, I suggest to use wine to run windows python program with larch.
For more information about wine in Ubuntu. You can search with keyword such as How To Run Windows Software on Ubuntu with Wine
For installing in macosx. Making sure your environment have python3. You can use which python3 to check that.
$ which python3
/usr/local/bin/python3
Then, without root permission, you can install package via virtualenv. (A workstation should provide this command)
$ virtualenv -p $(which python3) env
$ . env/bin/activate
(env) $ python -V
Python 3.x.x
And finally, you can install larch via pip.
(env) $ pip3 install larch
For more information about virtualenv
"Larch can be installed from source code. If not using Anaconda, this is necessary for Linux, and can be done for other systems as well.
The latest releases of the source code will be available from Larch releases (github.com). In addition, you can use git to grab the latest development version of the source code:git clone http://github.com/xraypy/xraylarch.git" After unpacking the source distribution kit, installation from source on any platform is:
python setup.py install
source:http://cars.uchicago.edu/xraylarch/installation/index.html
edit: See this for doing this without root access
How to install python modules without root access?

Categories