Python: Overwrite import of numpy from Abaqus with different version of numpy

北城余情 提交于 2020-01-03 04:54:08

问题


The Abaqus that I run has a pre-installed library (numpy) which has version 1.6.2 This is the only pre-installed module which is present as an "addon" for Abaqus (other than the native Abaqus CAE libraries).

I want to be able to run a python script, executed with abaqus cae nogui=makro.py, so that I can have access to scipy as well. I am doing all this in a very strict environment (no moving around of folders at installation directories)

I have tried the following:

import sys
sys.path.insert(0, '/opt/gcdistro/app/anaconda/2.7/lib/python2.7/site-packages')

import numpy
print(str(numpy.__path__) + ' --- ' + str(numpy.__version__))
sys.stdout.flush()

import scipy
print(str(scipy.__path__) + ' --- ' + str(scipy.__version__))
sys.stdout.flush()
from scipy.optimize import curve_fit

So when I add the above to my script 2 things happen:

  1. The import scipy line runs without any problem which means I have successfully imported the module to the Abaqus Python environment.

  2. from scipy.optimize import curve_fit throws the following ImportError: ImportError: numpy.core.multiarray failed to import

Now, the ImportError has to do with the Abaqus environment having an old verison of numpy.

My output:

['/opt/gcdistro/app/abaqus/6.14-5/6.14-5/tools/SMApy/python2.7/lib/python2.7/site-packages/numpy'] --- 1.6.2
['/opt/gcdistro/app/anaconda/2.7/lib/python2.7/site-packages/scipy'] --- 0.16.0

The strange thing here is that even though I inserted the path to the Anaconda site-packages which contains compatible versions of numpy and scipy it only successfully imported scipy from there. The old numpy version that Abaqus wants to use couldn't be "overwritten" with the newer numpy version which is contained in the site-packages directory.

How can I "force" the usage of the Anaconda numpy instead of the Abaqus numpy?

Since I am not a super-user I am unable to alter anything outside of my home folder.

来源:https://stackoverflow.com/questions/38845741/python-overwrite-import-of-numpy-from-abaqus-with-different-version-of-numpy

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