External call to Python3.5 doesnot work from within Abaqus python

徘徊边缘 提交于 2019-12-11 05:14:50

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/44552279/external-call-to-python3-5-doesnot-work-from-within-abaqus-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!