Metadata-Version: 2.4
Name: lingo-api
Version: 23.0.5
Summary: Python interface to LINGO API
Home-page: http://www.lindo.com
Author: Lindo Systems, Inc.
Author-email: support@lindo.com
Platform: Windows, Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: numpy
Requires-Dist: pandas
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: platform
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# The Python Interface to LINGO.

This package requires Lingo and a valid license key. Please refer to the [Lingo user manual](https://lindo.com/downloads/PDF/LINGO.pdf) for installation instructions, and to learn more about the Lingo modeling language.

## LINGO 23 Release

Package version 23.0.5 targets the LINGO 23.0.160 SDK and requires Python 3.9
or newer. The Windows build matrix covers Python 3.9 through 3.15. Linux
builds use the matching LINGO 23 SDK archive and Python matrix configured in
the Dockerfile. The Python package version is independent of the native LINGO
SDK version.

On 64-bit Windows, set `LINGO64_23_HOME` to the LINGO 23 installation directory.
On Linux, set `LINGO_23_HOME` to the LINGO 23 installation directory.
Use `window_build.bat` for Windows builds and `Dockerfile` for Linux builds.

### Windows build server

All Windows wheels are built and tested by `window_build.bat` on one machine.
Linux wheels are built separately (see `DOCKER_NOTES.md`). The machine needs:

- Visual Studio Build Tools 2022 with the C++ workload. setuptools finds it
  through vswhere, so `cl` does not need to be on `PATH`.
- LINGO 23 installed and licensed, with `LINGO64_23_HOME` set to its directory.
- 64-bit Python 3.9 through 3.15 from python.org, installed for all users and
  listed by `py -0p`. The script selects each one with `py -V:3.x`.

From the repository root:

```bat
window_build.bat              rem every Python in the matrix
window_build.bat 3.13 3.14    rem only these versions
```

For each version the script:

1. builds the wheel in a fresh venv under `%TEMP%`;
2. installs the wheel;
3. runs `python -m lingo_test`, a MOSEK/TBB DLL check, `tests\check_numpy.py`
   and `tests\test_regressions.py`.

Wheels go to `dist\`. An earlier wheel of the same version for a Python
being rebuilt is moved to `dist\old-<timestamp>\`, and wheels for other
Pythons are left in place. The full log goes to
`WindowsBuildOutput_<version>.txt`. The script stops at the first failure and
exits 0 only when every version passed and one `win_amd64` wheel exists for
each.

### No license

If LINGO finds no valid license, `lingo_api.solve()` raises
`lingo_api.LingoLicenseError` (a subclass of `LingoError`) instead of
returning 0. The error says where LINGO looked and includes LINGO's own
instructions, such as running `runlingo -d` to create a demo license.

```python
try:
    lingo_api.solve(model)
except lingo_api.LingoLicenseError as e:
    print(e)
```

With LINGO 23.0.167 or later the error code is 7 (`LSERR_INVALID_LICENSE_KEY_LNG`).
Older LINGO libraries report success without a license. For those, `solve()`
reads LINGO's error 171 from the log, so it can only detect a missing
license when the Model has a `logFile` (the default is `TempModel.log`).

## Installation For LINGO 21

This python package can be installed with pip. It is assumed Lingo 21 is installed on host system.

For administrative users: 

```bash
> pip install lingo_api
```

For standard (non-administrative) users:

```bash
> pip install lingo_api --user
```

## Installation For LINGO 20

This python package can be installed with pip. It is assumed Lingo 20 is installed on host system.

For administrative users: 

```bash
> pip install lingo_api==20.0.9
```

For standard (non-administrative) users:

```bash
> pip install lingo_api==20.0.9 --user
```



## Testing

A quick way to test the installation is to run
```bash
> python -m lingo_test
```

It is also good to test the LINGO API on one of the included examples.
```
> cd examples/Chess
> python chess.py
```

## Possible errors due to misconfiguration

If the user does not have the correct LINGO environment variable set, they will not be able to load
the lingo_api library instead they will receive an error message. 

To fix the problem follow these steps

### Using Windows
On the command line depending on the users LINGO installation:

LINGO 23 on windows 64-bit  
```dos
> setx LINGO64_23_HOME "C:\path\to\LINGO64_23" 
```
LINGO 23 on windows 32-bit 
```dos
> setx LINGO_23_HOME "C:\path\to\LINGO23" 
```


### Using Linux
On the command line depending on the users LINGO installation:

LINGO 23
For standard (non-administrative) users:
```    
$ export LINGO_23_HOME="$HOME/LINGO64_23"
```   
For administrative users:
```    
$ export LINGO_23_HOME="/opt/LINGO64_23"	
```   





If a shared library cannot be loaded, add the LINGO library directory to the loader path:
```
$ export LD_LIBRARY_PATH="$LINGO_23_HOME/bin/linux64${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
```

To have these variables set automatically, add the relevant lines to the `~/.bashrc` or `~/.bash_profile` file.


## How to Build Wheel and Install (for package managers)

To build the python package on any operating system first start by creating a whl file. From the top of the lingoapi-python directory run the command.

```bash
> python -m build
```

If the command is successful a new directory named `dist` is created in the lingoapi-python directory. The new directory will have two files with extension `.whl` and `.tar.gz`. For example, if the LINGO API is built it on Windows using Python 3.10 the new directory will look like this.

```bash
├── dist
│  ├── lingo_api-x.y.z-cp310-cp310-win_amd64.whl
│  └── lingo-x.y.z.tar.gz
```

The package can now be installed locally using the command.
```bash
> pip install dist/*.whl
```
