Skip to content Skip to sidebar Skip to footer

How Integrate Abaqus Python Libraries Into A Project Hosted In Pycharm

There is a similar question regarding the integration of Abaqus specific python libraries into a project hosted in PyDev/Eclipse. But unfortunately the answers were not compatible

Solution 1:

I'm using abaqus 6.14-4, hopefully helpful for you. I think why we need PyCharm is because we want to fully use its type checker and other functions. If we only need a editor, then Abaqus PDE is enough.

In order to achieve this goal, I have been search for abaqus python's source code for long time and couldn't find it. Since abaqus only provide the compiled *.pyc files, I use the tool uncompyle6 to decode the *.pyc files and add some functions in it.

There is my project: abaqus_pycharm

  1. register \SIMULIA\Abaqus\6.14-4\tools\SMApy\python2.7\python.exe as your interpreter (Or you can choose any you want)

  2. copy the files at import-files folder to your site-packages folder

notices that this program used os.system command to run abaqus command line, shown as below:

def saveAs(self, pathName):
    if isinstance(self.debug, bool) andself.debug:
        print(pathName)
    if'ABAQUS_BAT_SETTING'inos.environ.keys():
        self.abaqus_bat_setting = os.environ['ABAQUS_BAT_SETTING']
    if'ABAQUS_BAT_PATH'inos.environ.keys():
        self.abaqus_bat_path = os.environ['ABAQUS_BAT_PATH']
    os.system(self.abaqus_bat_path + ' cae -' + self.abaqus_bat_setting + ' ' + os.path.abspath(sys.argv[0]))

so we need to set environment like:

environ['ABAQUS_BAT_PATH'] = 'D:\\SIMULIA\\Abaqus\\Commands\\abaqus'
environ['ABAQUS_BAT_SETTING'] = 'noGUI'

and it will run as:

D:\SIMULIA\Abaqus\Commands\abaqus.bat -noGUI your_current_working_file.py

Solution 2:

Five years late to the party but this worked for me with Abaqus 2016 and PyCharm 2019.1 Professional on Windows 10:

  1. Open Abaqus CAE, go to the Kernel Command Line Interface (the >>> icon) and enter the following:
>>>import os>>>print(os.environ['PYTHONPATH'])
C:\SIMULIA\CAE\2016;C:\SIMULIA\CAE\2016\win_b64;C:\SIMUL ...
  1. Copy the output and make that your system-wide PYTHONPATH environment variable. I trimmed a repeat entry and some . paths.

Setting System PYTHONPATH environment variable

  1. Restart PyCharm so it picks up the new PYTHONPATH, go to File/Settings/Project/Project Interpreter, click the Cog icon then Add. Choose the System Interpreter option then point it towards the python.exe in the Abaqus bin directory. In my case this was C:\SIMULIA\CAE\2016\win_b64\code\bin\python.exe. Don't be misled by other ones like C:\SIMULIA\CAE\2016\win_b64\tools\SMApy\python2.7\python.exe - they won't work.

This isn't bulletproof - for example, your line from abaqus import * won't work for me - even if I add ABA_PATH to the system path I get ImportError: abaqus module may only be imported in the Abaqus kernel process. But some debugging and code completion works, for example:

Using the PyCharm debugger with Abaqus

Abaqus Python code completion in PyCharm

Setting the system-wide path seemed a bit heavy-handed but I wasn't able to get it going any other way.

Post a Comment for "How Integrate Abaqus Python Libraries Into A Project Hosted In Pycharm"