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 with my problem at hand.
I am using ABAQUS
Version 6.11-2 and the Community Edition of PyCharm 3.1.3
. The Abaqus python interpreter resides at 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 I need PyCharm to resolve in order to give it's code completion magic a go are residing here - at least that's what I believe them to be.
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 code of the script I am trying to work on.
from abaqus import *
from abaqusConstants import *
backwardCompatibility.setValues(includeDeprecated=True, reportDeprecated=False)
import sketch
import part
PyCharm marks the abaqus and abaqusConstants import with red underlining. Showing:
"Unresolved reference 'abaqus'".
Can someone explain to me how to configure the project in PyCharm so that PyCharm can resolve these imports?
Adding the mentioned Python.exe as a Project Interpreter in the Settings Dialog will lead to the following error messagebox saying 'Cannot setup a python SDK at ~path~. The SDK seems invalid'.
Regards
Five years late to the party but this worked for me with Abaqus 2016 and PyCharm 2019.1 Professional on Windows 10:
>>>
icon) and enter the following: >>> import os
>>> print(os.environ['PYTHONPATH'])
C:\SIMULIA\CAE\2016;C:\SIMULIA\CAE\2016\win_b64;C:\SIMUL ...
PYTHONPATH
environment variable. I trimmed a repeat entry and some .
paths. 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:
Setting the system-wide path seemed a bit heavy-handed but I wasn't able to get it going any other way.
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
register \\SIMULIA\\Abaqus\\6.14-4\\tools\\SMApy\\python2.7\\python.exe
as your interpreter (Or you can choose any you want)
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) 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 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
I would recommend using the abqpy library in Python: https://abqpy.com
It provides code completion for Abaqus commands in any IDE
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.