Using live-py with Abaqus' python distribution
See original GitHub issueHello again,
Disclamer: I wrote this before having read the built in Emacs documentation.
System information
- Windows 10
- System Python:
Python 2.7.13 :: Anaconda 4.3.1 (64-bit)
- GNU Emacs 25.1.1 (x86_64-w64-mingw32) of 2016-11-15
- Spacemacs v.0.200.9
- live-py-mode-20170429.2207
- Abaqus 2017
abaqus python --version
gives 2.7.3
Overview
I’d like to use Live-py with Abaqus’ python distribution. The documentation is usually comprehensive.
I’ve tried various things, probably in all the ways they were not intended. Not sure if this can be done in Live-py, but I’d really like to give it a shot.
I’ll try to provide any other debug information that may be useful.
Step 1: live-py-set-version with python interpreter and arguments
Using M-x live-py-set-version
, I was able to specify a custom python interpreter.
To run Python applications in an Abaqus context, the command abaqus python
can be used; thus if I want to run my own_script.py
, I execute abaqus python own_script.py
in a terminal. I then have access to the custom Abaqus imports that allows me to interact with FEM models and analysis results. The abaqus
command resolves to the batch script C:\SIMULIA\Commands\abaqus.bat
on my system, which starts C:\SIMULIA\CAE\2017\win_b64\code\bin\ABQLauncher.exe
with any arguments list (eg python own_script.py
passed through). The executable then again passes control to a bundled python.exe, after doing some magic that allows me to access the API. I haven’t been able to load the API on a python.exe of my choosing without going through this magic executable.
When I M-x live-py-set-version
"c:/SIMULIA/Commands/abaqus.bat python"
, I get this in the preview Window:
'"c:/SIMULIA/Commands/abaqus.bat python"' is not recognized as an internal or external command,
operable program or batch file.
- Is it possible to specify arguments to the Python interpreter used with
live-py
?
Step 2: Custom batch script that wraps arguments
- I create
apyth.bat
in the same directory asown_script.py
containing"C:\SIMULIA\Commands\abaqus.bat" python %*
- I set my
M-x live-py-set-version
toapyth
, and it seems to be getting a little further:d:\workspace\python>"C:\SIMULIA\Commands\abaqus.bat" python "c:/Users/thlhe/.emacs.d/elpa/live-py-mode-20170429.2207/code_tracer.py" -f "d:/workspace/python/abaqus_live.py" - abaqus_live python Traceback (most recent call last): File "c:/Users/thlhe/.emacs.d/elpa/live-py-mode-20170429.2207/code_tracer.py", line 23, in <module> arg = locate('ast.arg') File "C:\SIMULIA\CAE\2017\win_b64\tools\SMApy\python2.7\lib\pydoc.py", line 1471, in locate nextmodule = safeimport(join(parts[:n+1], '.'), forceload) File "C:\SIMULIA\CAE\2017\win_b64\tools\SMApy\python2.7\lib\pydoc.py", line 310, in safeimport raise ErrorDuringImport(path, sys.exc_info()) pydoc.ErrorDuringImport: problem in ast.arg - <type 'exceptions.ImportError'>: No module named arg
- Seems like the
locate
function behaves differently with the two python interpreters, returningNone
on Anaconda Python 2.7 and throwing an error with Abaqus Python 2.7:
Step 3: Attempting to fix the locate
issue
I tried modifying the beginning of code_tracer.py
to this to wrap the error:
import pydoc # no longer import the locate function
import sys
import traceback
import types
import os
import importlib
from canvas import Canvas
from mock_turtle import MockTurtle
from report_builder import ReportBuilder
# Instead, wrap it in a try-catch
def locate(*args, **kwargs):
try:
return pydoc.locate(*args, **kwargs)
except ImportError:
return None
But I still kept getting the same error. My suspect is my lack of understanding plugin internals.
Summary
- Trying to specify which abaqus interpreter to use was a little clunky, especially with command line arguments.
live-py-set-version
may be the wrong function to use? Is there a better way? - I’d like feedback on how to fix the error with
locate
.
Ideas?
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
I noticed the same thing on Ubuntu when specifying a virtualenv or Python 3, so I’ve opened issue #123.
Thanks for letting me know that the interpreter arguments are working.
I added the
live-py-set-args
command (C-c M-a
). You should be able to set the version toabaqus
and the args topython
.