对 Python3.5 的外部调用在 Abaqus python 中不起作用 [英] External call to Python3.5 doesnot work from within Abaqus python

查看:105
本文介绍了对 Python3.5 的外部调用在 Abaqus python 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Abaqus 是一种基于物理的机械模拟工具.它与 python 2.7.3 捆绑在一起.我使用 python 脚本来自动化某些操作.最近,我不得不使用 os.system() 通过 Abaqus CAE python 交互界面运行一个 Python3.5 脚本.subprocess.call 或 subprocess.popen 也不起作用.Abaqus python 一直报错:

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:

致命的 Python 错误:Py_Initialize:无法加载文件系统编解码器文件C:\SIMULIA\CAE\2016\win_b64\tools\SMApy\python2.7\lib\encodings__init__.py",第123行引发CodecRegistryError,\

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,\

遇到类似错误的人可以通过更正路径信息来调试他们的代码.无论我尝试什么,abaqus python 都坚持使用自己的 init.py 文件初始化 python3,这会导致语法错误.以下是我尝试过的一些方法:

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:

  • 我定义了 PYTHONHOME 和 PYTHONPATH 变量指向 v3.5 文件夹
  • 我将 v3.5 文件夹附加到 sys.path.
  • 我从 sys.path 中删除了冲突的 init.py 文件的文件夹,并将 v3.5 文件夹附加到 sys.path
  • 我重置了 sys.path 并将 v3.5 文件夹附加到了 sys.path.
  • 我手动修改了 sys.prefix 以指向 v3.5 文件夹
  • 我创建了一个调用 v3.5 的 DOS 批处理文件.我从 Abaqus 调用了这个批处理文件.同样的错误.
  • 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.

知道发生了什么吗?我可以从 abaqus 之外的 python 2 脚本中成功地对 python 3 进行外部调用.

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.

推荐答案

我在从 abaqus 附带的 Python 捆绑版本运行 Python 3 时遇到了同样的问题.

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

对我有用的解决方案是在调用我的 python 3 脚本之前清除环境变量 PYTHONHOME.

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.

这篇关于对 Python3.5 的外部调用在 Abaqus python 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆