This problem occurs every time I run mfix, even with the case model


reinstalling anaconda and mfix did not solve the problem either.

This is happening because you have set a default Chinese encoding and the file is being opened here without explicitly specifying an character encoding. This is a bug in MFiX which we will fix for the next release, we did not see this in testing because we don’t test with default Chinese locale! Thanks for bringing this to our attention.

If you can help me test a possible fix:

Open the file

F:\anaconda\envs\mfix-21.3.2\lib\site-packages\mfixgui\gui.py

in the text editor of your choice (avoid Chinese character encoding!) and find the definition of datfile starting at line 2765

and change this line:

        with open(self.get_project_file()) as datfile:

to

        with open(self.get_project_file(encoding='utf-8')) as datfile:

That is, we are explicitly specifying ‘utf-8’ for the character encoding.
If this doesn’t work, try the same thing with ‘ascii’ as the character encoing.

Please let me know if this works! Thanks.

– Charles

Another thing to try: set the environment variable PYTHONIOENCODING to utf8

Thanks for help.
When i add encoding = ‘utf-8’ to this line and run mfix,it reports an error
get_project_file()got an unexpected keyword argument 'encoding
So here’s how I modified it and mfix can run without bugs:
with open(self.get_project_file(),encoding = ‘utf-8’) as datfile:

1 Like

Also I add this environment variable to my computer.But I don’t know if that has an effect on it

Thanks for testing! As you figured out, the ‘encoding’ argument goes to ‘open’, not ‘get_project_file’. I typed my answer too fast. Sorry for the confusion.

This change will be added to the next release of MFiX.

Setting the environment variable will change the default encoding for all Python-based software on your system. If you have other code which is written in Python and deals with Chinese text, it may stop working when you set this variable. So changing the code in MFiX is a more narrowly-targeted fix, which is probably better.

– Charles