1

Abaqus is a physics based mechanical simulation tool. It comes bundled with python 2.7.3. I use python scripts to automate certain operations. Recently, I had to run a Python3.5 script through Abaqus CAE python interactive interface using os.system(). subprocess.call or subprocess.popen did not work either. Abaqus python kept giving the following error:

Fatal Python error: Py_Initialize: unable to load the file system codec File "C:\SIMULIA\CAE\2016\win_b64\tools\SMApy\python2.7\lib\encodings__init__.py", line 123 raise CodecRegistryError,\

People who got similar errors were able to debug their codes by correcting the path information. No matter what I tried abaqus python insists on initializing python3 using its own init.py file, which gives the syntax error. Below are some of the things I have tried:

  • I defined PYTHONHOME and PYTHONPATH variables point to the v3.5 folder
  • I appended v3.5 folders to the sys.path.
  • I removed the folder of the conflicting init.py file from sys.path and appended v3.5 folders to sys.path
  • I reset sys.path and appended v3.5 folders to the sys.path.
  • I manually modified sys.prefix to point to v3.5 folder
  • I created a DOS batch file which calls v3.5. I called this batch file from Abaqus. Same error.

Any ideas what is going on? I can successfully place an external call to python 3 from within a python 2 script outside of abaqus.

A Gokce
  • 31
  • 4
  • maybe precompile? https://docs.python.org/3/library/py_compile.html – agentp Jun 15 '17 at 10:08
  • 1
    searching "python system codec" yields lots of related questions, eg https://stackoverflow.com/questions/5694706/py-initialize-fails-unable-to-load-the-file-system-codec – agentp Jun 15 '17 at 10:15
  • I am having the same issue, and precompile doesn't seem to solve the issue for me. – CodeCupboard Jan 19 '18 at 11:12

1 Answers1

2

I was having the same issue when running python 3 from the bundled version of python that is included with abaqus.

The solution that worked for me was to clear the environmental variable PYTHONHOME just before calling my python 3 script.

os.environ["PYTHONPATH"] = ""

I am not sure if this is best answer to this issue and if it will work for every case, but I hope this answer will be helpful to anyone else in this position.

CodeCupboard
  • 1,507
  • 3
  • 17
  • 26