How to integrate python Abaqus libraries into a project hosted in PyCharm

A similar question concerns the integration of Abaqus-specific Python libraries into a project hosted in PyDev/Eclipse . But, unfortunately, the answers were not compatible with my problem.

I am using ABAQUS version 6.11-2 and Community Edition PyCharm 3.1.3 . The Abaqus Python interpreter is in the following location on my windows7 (64) machine:

 C:\SIMULIA\Abaqus\6.11-2\Python\Obj\Python.exe Python 2.6.2 for Abaqus 6.11-2 (r262:71600, Jun 29 2011, 19:23:41) [MSC v.1500 64 bit (AMD64)] on win32 

The libraries that I need to allow PyCharm to give free rein to code completion are here - at least the way I think.

 C:\SIMULIA\Abaqus\6.11-2\Python\Lib C:\SIMULIA\Abaqus\6.11-2\Python\Lib\abaqus.pyc C:\SIMULIA\Abaqus\6.11-2\Python\Lib\abaqusConstants.pyc 

Here are the first lines of script code I'm trying to work on.

 from abaqus import * from abaqusConstants import * backwardCompatibility.setValues(includeDeprecated=True, reportDeprecated=False) import sketch import part 

PyCharm marks the import of abaqus and abaqusConstants with a red underline. Showing:

  "Unresolved reference 'abaqus'". 

Can someone explain to me how to set up a project in PyCharm so that PyCharm can allow this import?

Adding the aforementioned Python.exe as a project interpreter in the Settings dialog box will result in the following error message: "Cannot install Python SDK in ~ path ~. SDK seems invalid."

Screenshot - SettingsDialog

Screenshot - ErrorMessageBox

Yours faithfully

+7
python pycharm abaqus
source share
2 answers

Five years late for the party, but it worked for me with Abaqus 2016 and PyCharm 2019.1 Professional for Windows 10:

  1. Open Abaqus CAE, go to the kernel command line interface ( >>> 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 it the system-wide environment variable PYTHONPATH . I trimmed the re-recording and some . the way.

Setting System PYTHONPATH environment variable

  1. Restart PyCharm so that it PYTHONPATH up the new PYTHONPATH , go to File / Settings / Project / Project Interpreter, click the Cog icon, then Add. Select the System Interpreter option, then point it to python.exe in the Abaqus bin . In my case it was C:\SIMULIA\CAE\2016\win_b64\code\bin\python.exe . Not C:\SIMULIA\CAE\2016\win_b64\tools\SMApy\python2.7\python.exe misconception others, such as C:\SIMULIA\CAE\2016\win_b64\tools\SMApy\python2.7\python.exe - they will not work.

This is not bulletproof - for example, your line from abaqus import * will not work for me - even if I add ABA_PATH to the system path, I will get ImportError: abaqus module may only be imported in the Abaqus kernel process . But some debugs and code additions work, for example:

Using the PyCharm debugger with Abaqus

Abaqus Python code completion in PyCharm

Setting up a system-wide path looked a bit tough, but I couldn't get her to go the other way.

+2
source share

I am using abaqus 6.14-4, hopefully useful for you. I think why we need PyCharm, because we want to make full use of its type checking and other functions. If we only need an editor, then Abaqus PDE is enough.

To achieve this, I searched the source code of abaqus python for a long time and could not find it. Since abaqus only provides compiled * .pyc files, I use the uncompyle6 tool to decode * .pyc files and add some functions to it.

Here is my project: abaqus_pycharm

  1. register \SIMULIA\Abaqus\6.14-4\tools\SMApy\python2.7\python.exe as an interpreter (or you can choose whatever you want)

  2. copy the files from the import-files folder to the folder of your package site

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

 def saveAs(self, pathName): if isinstance(self.debug, bool) and self.debug: print(pathName) if 'ABAQUS_BAT_SETTING' in os.environ.keys(): self.abaqus_bat_setting = os.environ['ABAQUS_BAT_SETTING'] if 'ABAQUS_BAT_PATH' in os.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 the environment as:

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

and it will work as:

 D:\SIMULIA\Abaqus\Commands\abaqus.bat -noGUI your_current_working_file.py 
+1
source share

All Articles