JuliaPy / JuliaPy/PyCall.jl

Trying to get PyCall to function with Abaqus python

Đang mở
#463 7 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Julia
Star
1.5k
Fork
186
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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
```

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Báo cáo không nêu tệp mã nguồn hay bài kiểm thử nào của PyCall; hãy bắt đầu bằng cách tái hiện thiết lập Julia 0.6.2/Python 2.7.3 và lệnh gọi `imp.load_module` đối với `odbAccess.pyd`. So sánh `sys.path` đã cấu hình với các đường dẫn Abaqus được hiển thị, và coi một chẩn đoán có thể tái hiện hoặc một cấu hình được hỗ trợ có tài liệu là tiêu chí hoàn thành.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
julia, python
Lĩnh vực
developer-experience, tooling
Loại issue
Lỗi
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
20/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.