JuliaPy / JuliaPy/PyCall.jl

Trying to get PyCall to function with Abaqus python

オープン
#463 コメント 7 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Julia
スター
1.5k
フォーク
186
PR マージ指標
30日以内にマージされた PR はありません

説明

Dear all,

I’m taking a stab to try to get the python distributed with SIMULIA Abaqus version “2017” (also known as v6.14-5, which reports that it comes with python 2.7.3) to work from Julia 0.6.2 with PyCall. I'm on Windows 10.

I know PyCall only recommends calling Anaconda python (which works great), but if the Abaqus scripting interface could be directly exposed to Julia this would be extremely useful for job control, post processing, etc. I hope this is the best place to post this query.

I can get PyCall setup for Abaqus python and import my own `.py` modules, but run into trouble trying to successfully import Abaqus `.pyd` modules (although these files are being found). In other words, I can get python’s `Inp.module_find()` to find and identify a `.pyd` module correctly, but `Inp.module_load()` runs into trouble, for example reporting

```
PyError (ccall(@pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, arg, C_NULL))
ImportError('DLL load failed: The specified procedure could not be found.',)
File "C:\SIMULIA\CAE\2017\win_b64\tools\SMApy\python2.7\Lib\odb2vtk.py", line 15, in
from odbAccess import *
```
when my own `odb2vtk.py` module does `from odbAccess import *`. The steps I've taken are explained in full below.

I’m wondering if there are other Abaqus locations that need to be added to the `pyimport` path. odbAccess.pyd is a very small file (20 kB) which is exposing a large part of the Abaqus scripting interface.
Any hints or suggestion highly appreciated, and apologies for the length of this post.

GC

The following is how I proceeded. I did this from Jupyter 5.4.0 running Julia 0.6.2

`
ENV["PYTHON"] = "C:\\SIMULIA\\CAE\\2017\\win_b64\\tools\\SMApy\\python2.7\\python.exe" Pkg.build("PyCall")
`

Then I restarted the Julia kernel.
Checking things out from the a Jupyter Julia cell looks good:

```
PyCall.pyprogramname
"C:\\SIMULIA\\CAE\\2017\\win_b64\\tools\\SMApy\\python2.7\\python.exe"

PyCall.libpython
"C:\\SIMULIA\\CAE\\2017\\win_b64\\tools\\SMApy\\python2.7\\python27"

pyversion
v"2.7.3"
```

Then I added some locations to the `pyimport` path as per the PyCall docs – the last one added has the Abaqus `.pyd` file I want to access.

```
unshift!(PyVector(pyimport("sys")["path"]), "")
pypath = unshift!(PyVector(pyimport("sys")["path"]), "C:\\SIMULIA\\CAE\\2017\\win_b64\\tools\\SMApy\\python2.7\\Lib");
pypath = unshift!(PyVector(pyimport("sys")["path"]), "C:\\SIMULIA\\CAE\\2017\\win_b64\\code\\bin");
[println("$(pn)") for pn in pypath];
C:\SIMULIA\CAE\2017\win_b64\code\bin
C:\SIMULIA\CAE\2017\win_b64\tools\SMApy\python2.7\Lib

C:\SIMULIA\CAE\2017\win_b64\tools\SMApy\python2.7\python27.zip
C:\Program Files\FreeCAD 0.16\bin
C:\SIMULIA\CAE\2017\win_b64\tools\SMApy\python2.7\DLLs
C:\SIMULIA\CAE\2017\win_b64\tools\SMApy\python2.7\lib
C:\SIMULIA\CAE\2017\win_b64\tools\SMApy\python2.7\lib\plat-win
C:\SIMULIA\CAE\2017\win_b64\tools\SMApy\python2.7\lib\lib-tk
C:\Users\graham\AppData\Local\Julia-0.6.2\bin
C:\SIMULIA\CAE\2017\win_b64\tools\SMApy\python2.7
C:\SIMULIA\CAE\2017\win_b64\tools\SMApy\python2.7\lib\site-packages
C:\SIMULIA\CAE\2017\win_b64\tools\SMApy\python2.7\lib\site-packages\win32
C:\SIMULIA\CAE\2017\win_b64\tools\SMApy\python2.7\lib\site-packages\win32\lib
C:\SIMULIA\CAE\2017\win_b64\tools\SMApy\python2.7\lib\site-packages\Pythonwin
```

While `@pyimport` fails for my module `odb2vtk.py`, the following code suggestion from https://github.com/dhoegh/Hawk.jl/blob/master/src/Hawk.jl#L7-13 works, at least up to the point of importing Abaqus module `odbAccess.pyd`:

```
@pyimport imp
filename = "C:\\SIMULIA\\CAE\\2017\\win_b64\\tools\\SMApy\\python2.7\\Lib\\odb2vtk.py"
(path, name) = dirname(filename), basename(filename)
# (name, ext) = rsplit(name, '.', 2) # Deprecated way to do this - rsplit no longer exists
(ext, name) = reverse.(split(reverse(name),'.'; limit=2)) # Keep only first two results (in case of more .'s)
# Using python module search
(file, pathname, description) = imp.find_module(name, [path])
println("name: $(name)")
println("file: $(file)")
println("pathname: $(pathname)")
println("description: $(description)")
odb2vtk = imp.load_module(name, file, pathname, description)
```

Outputing

```
name: odb2vtk
file: PyObject
pathname: C:\SIMULIA\CAE\2017\win_b64\tools\SMApy\python2.7\Lib\odb2vtk.py
description: (".py", "U", 1)
PyError (ccall(@pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, arg, C_NULL))
ImportError('DLL load failed: The specified procedure could not be found.',)
File "C:\SIMULIA\CAE\2017\win_b64\tools\SMApy\python2.7\Lib\odb2vtk.py", line 15, in
from odbAccess import *

Stacktrace:
[1] pyerr_check at C:\Users\graham\.julia\v0.6\PyCall\src\exception.jl:56 [inlined]
[2] pyerr_check at C:\Users\graham\.julia\v0.6\PyCall\src\exception.jl:61 [inlined]
[3] macro expansion at C:\Users\graham\.julia\v0.6\PyCall\src\exception.jl:81 [inlined]
[4] #_pycall#67(::Array{Any,1}, ::Function, ::PyCall.PyObject, ::RevString{SubString{String}}, ::Vararg{Any,N} where N) at C:\Users\graham\.julia\v0.6\PyCall\src\PyCall.jl:653
[5] _pycall(::PyCall.PyObject, ::RevString{SubString{String}}, ::Vararg{Any,N} where N) at C:\Users\graham\.julia\v0.6\PyCall\src\PyCall.jl:641
[6] #pycall#71(::Array{Any,1}, ::Function, ::PyCall.PyObject, ::Type{PyCall.PyAny}, ::RevString{SubString{String}}, ::Vararg{Any,N} where N) at C:\Users\graham\.julia\v0.6\PyCall\src\PyCall.jl:675
[7] pycall(::PyCall.PyObject, ::Type{PyCall.PyAny}, ::RevString{SubString{String}}, ::Vararg{Any,N} where N) at C:\Users\graham\.julia\v0.6\PyCall\src\PyCall.jl:675
[8] #call#72(::Array{Any,1}, ::PyCall.PyObject, ::RevString{SubString{String}}, ::Vararg{Any,N} where N) at C:\Users\graham\.julia\v0.6\PyCall\src\PyCall.jl:678
[9] (::PyCall.PyObject)(::RevString{SubString{String}}, ::Vararg{Any,N} where N) at C:\Users\graham\.julia\v0.6\PyCall\src\PyCall.jl:678
[10] include_string(::String, ::String) at .\loading.jl:522
```

Then if I try to import odbAccess.pyd myself directly in a Jupyter Julia cell using the Inp interface and PyCall, I get the same error:

```
filename = "C:\\SIMULIA\\CAE\\2017\\win_b64\\code\\bin\\odbAccess.pyd"

@pyimport imp
(path, name) = dirname(filename), basename(filename)
# (name, ext) = rsplit(name, '.', 2) # Deprecated way to do this - rsplit no longer exists
(ext, name) = reverse.(split(reverse(name),'.'; limit=2)) # Keep only first two results (in case of more .'s)
# Using python module search
println("Using python module search to look for $(name) in $(path)")
(file, pathname, description) = imp.find_module(name, [path])
println("name: $(name)")
println("file: $(file)")
println("pathname: $(pathname)")
println("description: $(description)")

odb = imp.load_module(name, file, pathname, description)

```

Giving

```
Using python module search to look for odbAccess in C:\SIMULIA\CAE\2017\win_b64\code\bin
name: odbAccess
file: PyObject
pathname: C:\SIMULIA\CAE\2017\win_b64\code\bin\odbAccess.pyd
description: (".pyd", "rb", 3)
PyError (ccall(@pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, arg, C_NULL))
ImportError('DLL load failed: The specified procedure could not be found.',)

Stacktrace:
[1] pyerr_check at C:\Users\graham\.julia\v0.6\PyCall\src\exception.jl:56 [inlined]
[2] pyerr_check at C:\Users\graham\.julia\v0.6\PyCall\src\exception.jl:61 [inlined]
[3] macro expansion at C:\Users\graham\.julia\v0.6\PyCall\src\exception.jl:81 [inlined]
[4] #_pycall#67(::Array{Any,1}, ::Function, ::PyCall.PyObject, ::RevString{SubString{String}}, ::Vararg{Any,N} where N) at C:\Users\graham\.julia\v0.6\PyCall\src\PyCall.jl:653
[5] _pycall(::PyCall.PyObject, ::RevString{SubString{String}}, ::Vararg{Any,N} where N) at C:\Users\graham\.julia\v0.6\PyCall\src\PyCall.jl:641
[6] #pycall#71(::Array{Any,1}, ::Function, ::PyCall.PyObject, ::Type{PyCall.PyAny}, ::RevString{SubString{String}}, ::Vararg{Any,N} where N) at C:\Users\graham\.julia\v0.6\PyCall\src\PyCall.jl:675
[7] pycall(::PyCall.PyObject, ::Type{PyCall.PyAny}, ::RevString{SubString{String}}, ::Vararg{Any,N} where N) at C:\Users\graham\.julia\v0.6\PyCall\src\PyCall.jl:675
[8] #call#72(::Array{Any,1}, ::PyCall.PyObject, ::RevString{SubString{String}}, ::Vararg{Any,N} where N) at C:\Users\graham\.julia\v0.6\PyCall\src\PyCall.jl:678
[9] (::PyCall.PyObject)(::RevString{SubString{String}}, ::Vararg{Any,N} where N) at C:\Users\graham\.julia\v0.6\PyCall\src\PyCall.jl:678
[10] include_string(::String, ::String) at .\loading.jl:522
```

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

The report names no PyCall source file or test; begin by reproducing the Julia 0.6.2/Python 2.7.3 setup and the `imp.load_module` call against `odbAccess.pyd`. Compare the configured `sys.path` with the Abaqus paths shown, and treat a reproducible diagnosis or documented supported configuration as the completion criteria.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
julia, python
領域
developer-experience, tooling
issue の種類
バグ
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
20/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。