JuliaPy / JuliaPy/PythonCall.jl

error when executing a executable builded by pyinstaller

Abierto
#90 7 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Julia
Estrellas
1.1k
Forks
86
Merge medio
1 d 22 h
PR fusionados (30 d)
3

Descripción

I'm trying to use pyinstaller to build a executable with juliacall , here is my code:

```python
from juliacall import Main as jl

def hello(u = "world"):
jl.println(f"hello {u}!")

hello()
```

This works good in REPL, but runs into a error after pack it into a executable using pyinstaller:

```
Querying Julia versions from https://julialang-s3.julialang.org/bin/versions.json
Found Julia 1.7.1 at 'C:\\Users\\ash\\.julia\\pythoncall\\julia-1.7.1\\bin\\julia.exe'
isdev: False
JULIA_PYTHONCALL_LIBPTR: 140717263618048
JULIA_PYTHONCALL_EXE: D:\codehub\Instrument.jl\EC22.jl\temp\dist\hello\hello.exe
script:

try
if ENV["JULIA_PYTHONCALL_EXE"] != "" && get(ENV, "PYTHON", "") == ""
# Ensures PyCall uses the same Python executable
ENV["PYTHON"] = ENV["JULIA_PYTHONCALL_EXE"]
end
import Pkg
Pkg.activate(raw"C:\Users\ash\.julia\environments\PythonCall", io=devnull)
Pkg.add([Pkg.PackageSpec(name="PythonCall", uuid="6099a3de-0909-46bc-b1f4-468b9a2dfc0d")])
import PythonCall
catch err
@error "Error loading PythonCall.jl" err=err
rethrow()
end

Updating registry at `C:\Users\ash\.julia\registries\General.toml`
Resolving package versions...
Updating `C:\Users\ash\.julia\environments\PythonCall\Project.toml`
[6099a3de] + PythonCall v0.4.3
Updating `C:\Users\ash\.julia\environments\PythonCall\Manifest.toml`
[8f4d0f93] + Conda v1.6.0
[9a962f9c] + DataAPI v1.9.0
[e2d170a0] + DataValueInterfaces v1.0.0
[82899510] + IteratorInterfaceExtensions v1.0.0
[682c06a0] + JSON v0.21.2
[1914dd2f] + MacroTools v0.5.9
[69de0a69] + Parsers v2.1.3
[6099a3de] + PythonCall v0.4.3
[ae029012] + Requires v1.2.0
[3783bdb8] + TableTraits v1.0.1
[bd369af6] + Tables v1.6.1
[e17b2a0c] + UnsafePointers v1.0.0
[81def892] + VersionParsing v1.2.1
[0dad84c5] + ArgTools
[56f22d72] + Artifacts
[2a0f44e3] + Base64
[ade2ca70] + Dates
[f43a241f] + Downloads
[b77e0a4c] + InteractiveUtils
[b27032c2] + LibCURL
[76f85450] + LibGit2
[8f399da3] + Libdl
[37e2e46d] + LinearAlgebra
[56ddb016] + Logging
[d6f4376e] + Markdown
[a63ad114] + Mmap
[ca575930] + NetworkOptions
[44cfe95a] + Pkg
[de0858da] + Printf
[3fa0cd96] + REPL
[9a3f8284] + Random
[ea8e919c] + SHA
[9e88b42a] + Serialization
[6462fe0b] + Sockets
[fa267f1f] + TOML
[a4e569a6] + Tar
[8dfed614] + Test
[cf7118a7] + UUIDs
[4ec0a83e] + Unicode
[e66e0078] + CompilerSupportLibraries_jll
[deac9b47] + LibCURL_jll
[29816b5a] + LibSSH2_jll
[c8ffd9c3] + MbedTLS_jll
[14a3606d] + MozillaCACerts_jll
[4536629a] + OpenBLAS_jll
[83775a58] + Zlib_jll
[8e850b90] + libblastrampoline_jll
[8e850ede] + nghttp2_jll
[3f19e933] + p7zip_jll
Precompiling project...
1 dependency successfully precompiled in 15 seconds (18 already precompiled)
res: None

Traceback (most recent call last):
File "hello.py", line 1, in
File "", line 1027, in _find_and_load
File "", line 1006, in _find_and_load_unlocked
File "", line 688, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
File "juliacall\__init__.py", line 4, in
File "", line 1027, in _find_and_load
File "", line 1006, in _find_and_load_unlocked
File "", line 688, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
File "juliacall\init.py", line 167, in
Exception: PythonCall.jl did not start properly
[6060] Failed to execute script 'hello' due to unhandled exception!
```

**I installed juliacall by `pip install -e .` in order to do some modification with `juliacall/init.py` to print some info.**
here is my modification with `juliacall/init.py`
```python
...
script = '''
try
if ENV["JULIA_PYTHONCALL_EXE"] != "" && get(ENV, "PYTHON", "") == ""
# Ensures PyCall uses the same Python executable
ENV["PYTHON"] = ENV["JULIA_PYTHONCALL_EXE"]
end
import Pkg
Pkg.activate(raw"{}", io=devnull)
{}
import PythonCall
catch err
@error "Error loading PythonCall.jl" err=err
rethrow()
end
'''.format(jlenv, install, c.pythonapi._handle)

# print some info
print(f"isdev: {isdev}")
print(f"JULIA_PYTHONCALL_LIBPTR: {os.environ['JULIA_PYTHONCALL_LIBPTR']}")
print(f"JULIA_PYTHONCALL_EXE: {os.environ['JULIA_PYTHONCALL_EXE']}")
print(f"script:\n{script}\n")
res = lib.jl_eval_string(script.encode('utf8'))
print(f"res: {res}\n")

...
```

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.