'NoneType' object has no attribute 'encoding'

1,327 views
Skip to first unread message

xiuyuan shi

unread,
Feb 16, 2016, 1:37:44 AM2/16/16
to Pyomo Forum
Hi,
I am a new user of pyomo. When i solve my model using python script "results=opt.solve(instance,tee=True,warmstart=True)", I get "'NoneType' object has no attribute 'encoding'" Error as following. When I use "results=opt.solve(instance)", it return solution status "unkown" without error . But, when I use command line "pyomo --stream-solver --solver=gurobi -c" there is no error and return optimal results.

I do not know what is the problem.  Can anybody help me, thanks a lot.

Exception in thread Thread-2:
Traceback (most recent call last):
  File "C:\Python34\lib\threading.py", line 920, in _bootstrap_inner
    self.run()
  File "C:\Python34\lib\threading.py", line 868, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Python34\lib\site-packages\pyutilib\subprocess\processmngr.py", line 175, in _stream_reader
    encoding = sys.__stdout__.encoding
AttributeError: 'NoneType' object has no attribute 'encoding'
Exception in thread Thread-3:
Traceback (most recent call last):
  File "C:\Python34\lib\threading.py", line 920, in _bootstrap_inner
    self.run()
  File "C:\Python34\lib\threading.py", line 868, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Python34\lib\site-packages\pyutilib\subprocess\processmngr.py", line 175, in _stream_reader
    encoding = sys.__stdout__.encoding
AttributeError: 'NoneType' object has no attribute 'encoding'

Siirola, John D

unread,
Feb 16, 2016, 11:57:22 PM2/16/16
to pyomo...@googlegroups.com

OK, I have an idea of what might be going on here – my guesses are either that you are running within an IDE that is fouling up an assumption in PyUtilib.subprocess, or else a UNICODE issue in python 3.4 that is fouling up the output processing in pyutilib.subprocess when we are streaming output.  By chance, is your computer set up to use a non-ASCII (or non-UTF-8) character set by default (i.e., set up for a non-English locale)?

 

1)      A potential workaround (and this is really a shot in the dark):  try adding the following to the top of your script:

 

import sys

reload(sys)

sys.setdefaultencoding(‘utf-8’)

 

2)      Let’s try actually fixing the root problem…  can you tell us:

a.       what OS?

b.      is your computer set up to run in either a language other than English or a locale other than en_US?

c.       what version of Pyomo (run “pyomo --version” at the command line and share the output)?

d.      are you running in some form of a debugger or IDE?

e.      can you share the script fragment that is running the solver (e.g, the lines starting with “opt = SolverFactory” through the actual call to opt.solve)?

 

Resolving the issue in PyUtilib may take some work (the core PyUtilib developers all develop in the en_US locale, and testing other locales is a bit challenging).

 

john

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

xiuyuan shi

unread,
Feb 17, 2016, 2:54:32 AM2/17/16
to Pyomo Forum
Dear John,

Thanks a lot for your help. I have tried your suggestions and found it is really the problem of default python IDLE I used. When I switch to other ide like spyder, sublime, no such problem happened. But, still there is a problem that "The solver returned a status of:unknown". I think it should be 'optimal'. Here is the script:

from pyomo.environ import *
from pyomo.opt import SolverFactory,SolverStatus
from pyomo.core import Var

opt=SolverFactory("gurobi")
from CSP import model

instance=model.create_instance('csp.dat')
results=opt.solve(instance,tee=True)
instance.solutions.load_from(results)
print ("The solver returned a status of:"+str(results.Solution.Status))

The OS is Win10, and the locale I changed to en_US. The pyomo version is 4.2.10784.

Best regards

在 2016年2月17日星期三 UTC+8下午12:57:22,John写道:
Reply all
Reply to author
Forward
0 new messages