coin-or / pulp

A python Linear Programming API
http://coin-or.github.io/pulp/
Other
2.04k stars 381 forks source link

MOSEK in one Conda environment causing error in another #664

Open haochenz96 opened 1 year ago

haochenz96 commented 1 year ago

Details for the issue

What did you do?

I have two Conda environment: snakemake- I set up this one first and had been using it without issue. It does not have MOSEK solver in it. aa - I recently set up this environment, and MOSEK was installed.

After aa is set up and MOSEK installed into it, I have the following error while trying to import pulp in snakemake:

>>> import pulp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/juno/work/iacobuzc/haochen/mambaforge/envs/snakemake/lib/python3.11/site-packages/pulp/__init__.py", line 34, in <module>
    from .pulp import *
  File "/juno/work/iacobuzc/haochen/mambaforge/envs/snakemake/lib/python3.11/site-packages/pulp/pulp.py", line 99, in <module>
    from .apis import LpSolverDefault, PULP_CBC_CMD
  File "/juno/work/iacobuzc/haochen/mambaforge/envs/snakemake/lib/python3.11/site-packages/pulp/apis/__init__.py", line 7, in <module>
    from .mosek_api import *
  File "/juno/work/iacobuzc/haochen/mambaforge/envs/snakemake/lib/python3.11/site-packages/pulp/apis/mosek_api.py", line 32, in <module>
    class MOSEK(LpSolver):
  File "/juno/work/iacobuzc/haochen/mambaforge/envs/snakemake/lib/python3.11/site-packages/pulp/apis/mosek_api.py", line 40, in MOSEK
    env = mosek.Env()
          ^^^^^^^^^
AttributeError: module 'mosek' has no attribute 'Env'

What did you expect to see?

What did you see instead?

Useful extra information

My guess is that perhaps I installed MOSEK into the base environment and had to remove it and reinstall into aa, or have some environment variables set or that I have the MOSEK license at ~/mosek/mosek.lic, MOSEK is detected by pulp in snakemake but imported as an empty script (per this issue https://groups.google.com/g/mosek/c/MB_-kH-mSaQ).

I changed this line to:

    except (ImportError, AttributeError):

And it seems to have solved the error.

The info below often helps, please fill it out if you're able to. :)

What operating system are you using?

I'm using python version:

I installed PuLP via:

Did you also

pchtsp commented 7 months ago

If I understand the error there, you need to rename the file so it's not mosek. You're confusing python with modules that have the name of libraries.