简体   繁体   English

将numpy包导入ABAQUS 6.10 Python环境

[英]Importing numpy package into ABAQUS 6.10 Python environment

I have not been successful at importing numpy package to ABAQUS Python environment from previous discussions on this similar problem. 从关于此类似问题的先前讨论中,我没有成功将numpy包导入ABAQUS Python环境。

I am working on Microsoft Windows 7 (64-bit). 我正在使用Microsoft Windows 7(64位)。 I have installed ABAQUS 6.10. 我已经安装了ABAQUS 6.10。 And by typing the command abaqus python in MS-DOS prompt I figured that ABAQUS 6.10 uses Python 2.6.2 version. 通过在MS-DOS提示符下键入命令abaqus python ,我发现ABAQUS 6.10使用Python 2.6.2版本。 For an important reason, my python script file needs to use the array function available in the numpy package. 出于重要原因,我的python脚本文件需要使用numpy包中可用的array函数。 I undertook the following steps based on previous discussions: 我根据之前的讨论采取了以下步骤:

Python 2.6.2 installation : Python 2.6.2安装

  1. Installed Python 2.6.2 version (32-bit) to C:\\Python26\\ (I already had Python 2.7.6 installed in folder C:\\Python27\\ ) 将Python 2.6.2版本(32位)安装到C:\\Python26\\ (我已经在文件夹C:\\Python27\\安装了Python 2.7.6)
  2. Changed the environment system variables under PATH variable to C:\\Python26\\; PATH 变量下的环境系统变量更改为C:\\Python26\\; (previously it was C:\\Python27\\ ) (以前是C:\\Python27\\
  3. Changed the environment user variables under PYTHONPATH variable to C:\\Python26\\Lib\\site-packages\\ (previously it was C:\\Python27\\ ) PYTHONPATH 变量下的环境用户变量更改为C:\\Python26\\Lib\\site-packages\\ (以前是C:\\Python27\\
  4. Loaded Python 2.6.2 successfully using command python in MS-DOS prompt. 在MS-DOS提示符下使用命令python成功加载了Python 2.6.2。

Numpy installation for Python 2.6.2 : 适用于Python 2.6.2的Numpy安装

  1. Downloaded and installed numpy (32-bit) MSI installer file numpy-1.3.0-win32-superpack-python2.6 from Sourceforge.net- NumPy 1.3.0 in C:\\Python26\\Lib\\site-packages folder. Sourceforge.net- NumPy 1.3.0在C:\\ Python26 \\ Lib \\ site-packages文件夹中下载并安装了numpy(32位)MSI安装程序文件numpy-1.3.0-win32-superpack-python2.6
  2. Loaded Python 2.6.2 successfully using command python in MS-DOS prompt. 在MS-DOS提示符下使用命令python成功加载了Python 2.6.2。
  3. Imported numpy successfully using the command import numpy in python environment. 在python环境中使用命令import numpy numpy成功import numpy

Numpy installation for ABAQUS 6.10 : ABAQUS 6.10的Numpy安装

  1. Copied the numpy folder from C:\\Python26\\Lib\\site-packages\\ and pasted to D:\\SIMULIA\\Abaqus\\6.10-1\\Python\\Lib\\site-packages , which is the python modules folder for ABAQUS. C:\\Python26\\Lib\\site-packages\\复制numpy文件夹,然后粘贴到D:\\SIMULIA\\Abaqus\\6.10-1\\Python\\Lib\\site-packages ,这是ABAQUS的python modules文件夹。 Please note I have installed ABAQUS 6.10 in D: drive. 请注意,我已经在D:驱动器中安装了ABAQUS 6.10。
  2. Created a python script file, myScript.py, containing just the following line of code: from numpy import * and saved it in the desktop. 创建了一个python脚本文件myScript.py,其中仅包含以下代码行: from numpy import *并将其保存在桌面中。
  3. Opened MS-DOS prompt and changed folder destination to my desktop containing myScript.py . 打开MS-DOS提示符,并将文件夹目标更改为包含myScript.py桌面。
  4. I finally typed the following commands in MS-DOS prompt to run the script file in the ABAQUS Python environment: abaqus cae noGUI=myScript.py and I got the following errors: 我最终在MS-DOS提示符下键入了以下命令,以在ABAQUS Python环境中运行脚本文件: abaqus cae noGUI=myScript.py ,出现以下错误:
 Abaqus License Manager checked out the following license(s): "cae" release 6.10 from 127.0.0.1 <2010 out of 2011 licenses remain available>. ImportError: DLL load failed: %1 is not a valid Win32 application. File "myScript.py", line 4, in <module> from numpy import array File "C:\\Python26\\Lib\\site-packages\\numpy\\__init__.py", line 130, in <module> import add_newdocs File "C:\\Python26\\Lib\\site-packages\\numpy\\add_newdocs.py", line 9, in <module> from lib import add_newdoc File "C:\\Python26\\Lib\\site-packages\\numpy\\lib\\__init__.py", line 4, in <module> from type_check import * File "C:\\Python26\\Lib\\site-packages\\numpy\\lib\\type_check.py", line 8, in <module> import numpy.core.numeric as _nx File "C:\\Python26\\Lib\\site-packages\\numpy\\core\\__init__.py", line 5, in <module> import multiarray Abaqus Error: cae exited with an error. 

Note: I installed Python 2.6.2 32-bit because the numpy available for 64-bit was showing a warning that it is unstable and would subsequently crash. 注意:我安装了32位Python 2.6.2,因为可用于64位的numpy显示了一个警告,警告它不稳定并随后会崩溃。

My basic question is: " How can I successfully import numpy package into ABAQUS environment? " 我的基本问题是:“ 如何将numpy包成功导入到ABAQUS环境中?

Honestly, the 32-bit version of numpy will not work with a 64-bit version of Python. 老实说,numpy的32位版本不适用于Python的64位版本。 Therefore, the error is quite expected. 因此,该错误是完全可以预期的。 Even if Abaqus were to use a 32-bit version, I would strongly advise not to copy and paste the directory of the library. 即使Abaqus使用32位版本,我也强烈建议不要复制和粘贴该库的目录。

dim_voly answer is an easy way to get around this problem, but here are some instructions if you really want to use numpy inside Abaqus dim_voly答案是解决此问题的简便方法,但是如果您真的想在Abaqus中使用numpy,则可以使用以下说明

  • This link explains quite clearly how to install numpy. 链接非常清楚地说明了如何安装numpy。 You will need to include the Abaqus Python directory in the PATH environmental variable. 您将需要在PATH环境变量中包含Abaqus Python目录。 Once pip is installed, it should be easy to install numpy and any other library you need. 安装pip ,应该很容易安装numpy和您需要的任何其他库。

  • I am currently using Abaqus 6.13 which already comes installed with numpy. 我当前正在使用已经随numpy一起安装的Abaqus 6.13。 Thus, upgrading your software can also be a viable solution. 因此,升级软件也是可行的解决方案。

Hope this helps 希望这可以帮助

I had trouble importing anything into the Abaqus python environment. 我在将任何内容导入Abaqus python环境时遇到了麻烦。 The workaround I used was to generate the .py script using a main .py script. 我使用的解决方法是使用主.py脚本生成.py脚本。 So all the calculations are done and pasted in as text into a template .py script. 因此,所有计算都已完成,并以文本形式粘贴到模板.py脚本中。 Then later the main script calls abaqus to run the python script. 然后,主脚本随后调用abaqus来运行python脚本。

I generally found that the python version within Abaqus is behind the mainstream python version and doing anything remotely out of the ordinary doesn't work as it depends on Simulia to update things. 我通常发现Abaqus中的python版本落后于主流python版本,并且远程执行任何与众不同的操作均不起作用,因为它依赖Simulia来进行更新。 I use too many custom packages as well. 我也使用了太多的自定义程序包。

In any case you end up wanting a master python script to set up high level things like folders and reading in data from tables. 无论如何,您最终都希望使用主python脚本来设置高级内容,例如文件夹和从表中读取数据。 And if you're running a script to build a model, I don't doubt that you're doing a parametric study so your loops for that can be in the main script. 而且,如果您正在运行用于构建模型的脚本,那么我不怀疑您正在进行参数研究,因此您的循环可以在主脚本中进行。

What also sometimes works for passing data into the abaqus .py file is setting up a struct or class and saving it using pickle . 有时将数据传递到abaqus .py文件中的方法是设置结构或类,并使用pickle保存。 As far as I recall pickle works and is importable as long as the class does not contain any custom imports. 据我记得,pickle的工作原理是可以导入的,只要该类不包含任何自定义导入即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM