ModuleNotFoundError: No module named '_gams2numpy' Topic is solved

Questions on using the GAMS APIs (Python, .NET, etc.)
Post Reply
Jan
User
User
Posts: 9
Joined: 6 years ago

ModuleNotFoundError: No module named '_gams2numpy'

Post by Jan » 8 months ago

Dear all,

I try to install the GAMS python API under GAMS version 38.2.1 on Windows10 system. Using the setup.py command seems to work. However, trying to import gamstransfer I receive an error message:

Code: Select all

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Input In [1], in <cell line: 1>()
----> 1 import gamstransfer as gt

File <frozen zipimport>:259, in load_module(self, fullname)

File ~\miniconda3\envs\gamsNeu\lib\site-packages\gamstransfer-0.1-py3.9.egg\gamstransfer.py:32, in <module>
     30 import warnings
     31 import copy
---> 32 import gams2numpy
     33 from gdxcc import *
     34 from gmdcc import *

File <frozen zipimport>:259, in load_module(self, fullname)

File ~\miniconda3\envs\gamsNeu\lib\site-packages\gams2numpy-0.1-py3.9.egg\gams2numpy.py:26, in <module>
      1 #
      2 # GAMS - General Algebraic Modeling System Python API
      3 #
   (...)
     23 # SOFTWARE.
     24 #
---> 26 import _gams2numpy
     27 from gdxcc import *
     28 from gmdcc import *

ModuleNotFoundError: No module named '_gams2numpy'
Likewise when I try to import the gams module:

Code: Select all

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Input In [3], in <cell line: 1>()
----> 1 import gams

File <frozen zipimport>:259, in load_module(self, fullname)

File ~\miniconda3\envs\gamsNeu38\lib\site-packages\gams-1.0-py3.8.egg\gams\__init__.py:32, in <module>
      1 #
      2 # GAMS - General Algebraic Modeling System Python API
      3 #
   (...)
     24 #
     25 # This file was generated.
     27 __all__ = ["DebugLevel", "GMS_MAX_INDEX_DIM", "SV_UNDEF", "SV_EPS", "GamsCheckpoint", "GamsDatabase", "GamsJob", "UpdateAction", "SymbolUpdateType", "GamsModifier", "GamsModelInstanceOpt", "GamsModelInstance", "Action", "CharSet", "GamsOptions", \
     28            "GamsEquationRecord", "GamsParameterRecord", "GamsSetRecord", "GamsVariableRecord", "GamsVariable", "GamsParameter", "GamsSet", "GamsEquation", "EquType", "VarType", "SolveStat", \
     29            "ModelStat", "GamsWorkspace", "GamsException", "GamsExceptionExecution", "GamsExitCode", \
     30            "PageContr", "Action", "LogLine", "AppendOut", "StepSum", "Suppress", "DFormat", "TFormat", "IntVarUp", "Case", "DumpParms", "ForceWork", "DumpOpt", "ErrMsg", "StringChk", "CharSet", "Keep", "TraceOpt", "SysOut", "SolPrint", "HoldFixed", "On115", "ExecMode", "InteractiveSolver", "FileCase", "SavePoint", "SolveLink", "Sys10", "Sys11", "ZeroResRep", "gdxCompress", "gdxConvert", "AppendExpand", "NoNewVarEqu", "gdxUels", "strictSingleton", "FDOpt", "PrefixLoadPath", "AsyncSolLst", "PyMultInst", "ShowOSMemory", "LstTitleLeftAligned", "FreeEmbeddedPython", "CaptureModelInstance", "CheckErrorLevel", "SuffixDLVars", "Digit", "Empty", "Filtered", "Listing", "PutNR", "PreviousWork", "HoldFixedAsync", "ReferenceLineNo", "ProcTreeMemMonitor" ]
---> 32 from .workspace import *
     33 from .database import *
     34 from .options import *

File <frozen zipimport>:259, in load_module(self, fullname)

File ~\miniconda3\envs\gamsNeu38\lib\site-packages\gams-1.0-py3.8.egg\gams\workspace.py:32, in <module>
     30 from subprocess import Popen
     31 import threading
---> 32 from .database import *
     33 from .execution import *
     34 from .options import *

File <frozen zipimport>:259, in load_module(self, fullname)

File ~\miniconda3\envs\gamsNeu38\lib\site-packages\gams-1.0-py3.8.egg\gams\database.py:26, in <module>
      1 #
      2 # GAMS - General Algebraic Modeling System Python API
      3 #
   (...)
     23 # SOFTWARE.
     24 #
---> 26 from gdxcc import *
     27 from gmdcc import *
     28 import os

File <frozen zipimport>:259, in load_module(self, fullname)

File ~\miniconda3\envs\gamsNeu38\lib\site-packages\gams2numpy-0.1-py3.8.egg\gdxcc.py:11, in <module>
      8 if _swig_python_version_info < (2, 7, 0):
      9     raise RuntimeError("Python 2.7 or later required")
---> 11 import _gdxcc
     13 try:
     14     import builtins as __builtin__

ModuleNotFoundError: No module named '_gdxcc'
I tried this in Conda environments using python version 3.8 and 3.9. But the error occurs for both versions.

Do I miss something? Any hints are more than welcome.
Best
Jan

User avatar
Clemens
Posts: 55
Joined: 6 years ago

Re: ModuleNotFoundError: No module named '_gams2numpy'

Post by Clemens » 8 months ago

Jan,

With setuptools>=60.0.0 a breaking change has been introduced. Due to this breaking change the GAMS Python files are not installed correctly. To solve the issue, please try setting SETUPTOOLS_USE_DISTUTILS=stdlib before running setup.py

Let me know if this helps,
Clemens

Jan
User
User
Posts: 9
Joined: 6 years ago

Re: ModuleNotFoundError: No module named '_gams2numpy'

Post by Jan » 8 months ago

Dear Clemens,

I tested it under python 3.8 and both import (gamstransfer and gams module) work fine.

Many thanks for your help!
Jan

gams_learner58
User
User
Posts: 8
Joined: 1 year ago

Re: ModuleNotFoundError: No module named '_gams2numpy'

Post by gams_learner58 » 1 month ago

Clemens wrote:
8 months ago
Jan,

With setuptools>=60.0.0 a breaking change has been introduced. Due to this breaking change the GAMS Python files are not installed correctly. To solve the issue, please try setting SETUPTOOLS_USE_DISTUTILS=stdlib before running setup.py

Let me know if this helps,
Clemens
I tried to do this, but got this error:

Code: Select all

File "C:\Users\<name>\anaconda3\lib\re.py", line 210, in sub
    return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or bytes-like object
Is there a way to fix this? Thank you!

User avatar
bussieck
Moderator
Moderator
Posts: 859
Joined: 6 years ago

Re: ModuleNotFoundError: No module named '_gams2numpy'

Post by bussieck » 1 month ago

What anaconda version, what Python version? See https://conda.io/projects/conda/en/late ... vironments to produce a spec list. Please share this and give the exact sequence of command that resulted in the failure.

-Michael

gams_learner58
User
User
Posts: 8
Joined: 1 year ago

Re: ModuleNotFoundError: No module named '_gams2numpy'

Post by gams_learner58 » 1 month ago

bussieck wrote:
1 month ago
What anaconda version, what Python version? See https://conda.io/projects/conda/en/late ... vironments to produce a spec list. Please share this and give the exact sequence of command that resulted in the failure.

-Michael
I'm using Python 3.9.12 and Anaconda 2022.05.

I simply

Code: Select all

cd C:\GAMS\wind64\40\apifiles\Python\api_39
then

Code: Select all

python setup.py install
then in python program:

Code: Select all

from gams import *
And I got the above error.

User avatar
bussieck
Moderator
Moderator
Posts: 859
Joined: 6 years ago

Re: ModuleNotFoundError: No module named '_gams2numpy'

Post by bussieck » 1 month ago

Was the "python setup.py install" successful? Perhaps you can share the output of the command. What about setting the SETUPTOOLS_USE_DISTUTILS environment variable? -Michael

gams_learner58
User
User
Posts: 8
Joined: 1 year ago

Re: ModuleNotFoundError: No module named '_gams2numpy'

Post by gams_learner58 » 1 month ago

bussieck wrote:
1 month ago
Was the "python setup.py install" successful? Perhaps you can share the output of the command. What about setting the SETUPTOOLS_USE_DISTUTILS environment variable? -Michael
python setup.py install was not successful for me. I did set:

Code: Select all

set SETUPTOOLS_USE_DISTUTILS=stdlib
prior to running python setup.py install, and get this error:

Code: Select all

File "C:\Users\<name>\anaconda3\lib\site-packages\setuptools\_vendor\importlib_metadata\__init__.py", line 855, in normalize
    return re.sub(r"[-_.]+", "-", name).lower().replace('-', '_')
  File "C:\Users\<name>\anaconda3\lib\re.py", line 210, in sub
    return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or bytes-like object

gams_learner58
User
User
Posts: 8
Joined: 1 year ago

Re: ModuleNotFoundError: No module named '_gams2numpy'

Post by gams_learner58 » 1 month ago

Updated: I can now python setup.py install successfully. I can see gams module in my conda list.

However, trying to from gams import * I got this error:

Code: Select all

File "C:\Users\<name>\AppData\Roaming\Python\Python39\site-packages\gams2numpy-0.1-py3.9.egg\gmdcc.py", line 71, in <module>
    GMD_NRSYMBOLSWITHALIAS = _gmdcc.GMD_NRSYMBOLSWITHALIAS
AttributeError: module '_gmdcc' has no attribute 'GMD_NRSYMBOLSWITHALIAS'
So it looks like the python apis are still not installed properly?

User avatar
bussieck
Moderator
Moderator
Posts: 859
Joined: 6 years ago

Re: ModuleNotFoundError: No module named '_gams2numpy'

Post by bussieck » 1 month ago

This now sounds like a version mix up. Which GAMS system is active? Why did the GAMS installation files end up in the USER_BASE directory rather than the site-package directory of the conda environment? I also see that you had interaction with GAMS support and ran python setup.py install from the PowerShell but used the the CMD method to set environment variables. All these experiments resulted probably is a pretty messed up setup which is difficult to debug and rectify with email or thread ping pong. I suggest that you contact GAMS support to arrange for an interactive session to get this sorted out.

-Michael

Post Reply