JuliaLang / IJulia.jl

Julia kernel for Jupyter
MIT License
2.8k stars 412 forks source link

%load_ext julia.magic #206

Closed stonebig closed 8 years ago

stonebig commented 10 years ago

Over a Ipython installation (winpython, windows7 32 bits,julia-0.3.0-rc1-c4547e6-win32.exe, Ijulia), I'm trying to have "%load_ext julia.magic" working, but I get the following error. As anyone a suggestion ?

%load_ext julia.magic

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-dfc2ccac1e3e> in <module>()
----> 1 get_ipython().magic('load_ext julia.magic')

D:\result_tests\WinPython-32bit-3.4.1.1_build05c\python-3.4.1\lib\site-packages\IPython\core\interactiveshell.py in magic(self, arg_s)
   2203         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2204         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2205         return self.run_line_magic(magic_name, magic_arg_s)
   2206 
   2207     #-------------------------------------------------------------------------

D:\result_tests\WinPython-32bit-3.4.1.1_build05c\python-3.4.1\lib\site-packages\IPython\core\interactiveshell.py in run_line_magic(self, magic_name, line)
   2124                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2125             with self.builtin_trap:
-> 2126                 result = fn(*args,**kwargs)
   2127             return result
   2128 

D:\result_tests\WinPython-32bit-3.4.1.1_build05c\python-3.4.1\lib\site-packages\IPython\core\magics\extension.py in load_ext(self, module_str)

D:\result_tests\WinPython-32bit-3.4.1.1_build05c\python-3.4.1\lib\site-packages\IPython\core\magic.py in <lambda>(f, *a, **k)
    191     # but it's overkill for just that one bit of state.
    192     def magic_deco(arg):
--> 193         call = lambda f, *a, **k: f(*a, **k)
    194 
    195         if callable(arg):

D:\result_tests\WinPython-32bit-3.4.1.1_build05c\python-3.4.1\lib\site-packages\IPython\core\magics\extension.py in load_ext(self, module_str)
     61         if not module_str:
     62             raise UsageError('Missing module name.')
---> 63         res = self.shell.extension_manager.load_extension(module_str)
     64 
     65         if res == 'already loaded':

D:\result_tests\WinPython-32bit-3.4.1.1_build05c\python-3.4.1\lib\site-packages\IPython\core\extensions.py in load_extension(self, module_str)
     96             if module_str not in sys.modules:
     97                 with prepended_to_syspath(self.ipython_extension_dir):
---> 98                     __import__(module_str)
     99             mod = sys.modules[module_str]
    100             if self._call_load_ipython_extension(mod):

D:\result_tests\WinPython-32bit-3.4.1.1_build05c\python-3.4.1\lib\site-packages\julia\__init__.py in <module>()
      1 """Julia/IPython bridge."""
      2 
----> 3 from core import Julia

ImportError: No module named 'core'

installation process was

D:\result_tests\WinPython-32bit-3.4.1.1_build05c\settings\.julia\v0.3\IJulia\pyt
hon>python setup.py install
running install
running build
running build_py
running install_lib
running install_egg_info
Removing D:\result_tests\WinPython-32bit-3.4.1.1_build05c\python-3.4.1\Lib\site-
packages\julia-0.1-py3.4.egg-info
Writing D:\result_tests\WinPython-32bit-3.4.1.1_build05c\python-3.4.1\Lib\site-p
ackages\julia-0.1-py3.4.egg-info

D:\result_tests\WinPython-32bit-3.4.1.1_build05c\settings\.julia\v0.3\IJulia\pyt
hon>

i my python-3.4.1\Lib\site-packages\julia, I have init.py core.py magic.py

stonebig commented 10 years ago

If i tweak a little bit the source of init.py

"""Julia/IPython bridge."""

from .core import Julia

i get that

`()
     19 import os
     20 import sys
---> 21 import commands
     22 
     23 #-----------------------------------------------------------------------------

ImportError: No module named 'commands'

what is this "commands module" ? (I'm python3.4)

stonebig commented 10 years ago

Haaaaaaaaaaaaaaaaarg https://docs.python.org/2/library/commands.html

Deprecated since version 2.6: The commands module has been removed in Python 3. Use the subprocess module instead.

Has anyone a guess on how to pythonize-3 this part ?

stevengj commented 10 years ago

We've been hoping to move the magics stuff over to @jakebolewski's pyjulia project, but right now it needs some loving care. The basic problem is that no one seems to be using it except for demos. People working in Julia want to call Python from Julia, but have no need for the reverse.

stonebig commented 10 years ago

ah ... if it's final decision, wouldn't it be better to just leave a Readme.txt re-orienting adventurous people to the 'better' project ? and it seems there is no 'magic' in this other project.

fixing the python3 part, I fell there, so I suppose this is the end of the road for my attempt.

D:\result_tests\WinPython-32bit-3.4.1.1_build05c\python-3.4.1\lib\site-packages\IPython\core\magic.py in register(self, *magic_objects)
    389             if type(m) in (type, MetaHasTraits):
    390                 # If we're given an uninstantiated class
--> 391                 m = m(shell=self.shell)
    392 
    393             # Now that we have an instance, we can register it and update the

D:\result_tests\WinPython-32bit-3.4.1.1_build05c\python-3.4.1\lib\site-packages\julia\magic.py in __init__(self, shell)
     47         # Flush, otherwise the Julia startup will keep stdout buffered
     48         sys.stdout.flush()
---> 49         self.julia = Julia(init_julia=True)
     50         print()
     51 

D:\result_tests\WinPython-32bit-3.4.1.1_build05c\python-3.4.1\lib\site-packages\julia\core.py in __init__(self, init_julia)
     87                 raise ValueError("Julia release library not found\n"
     88                                  "  searched %s\n   and %s"
---> 89                                  % (jpath_so, jpath_dylib))
     90 
     91             j = ctypes.PyDLL(jpath, ctypes.RTLD_GLOBAL)

ValueError: Julia release library not found
  searched D:\result_tests\WinPython-32bit-3.4.1.1_build05c\tools\Julia\lib\libjulia.so
   and D:\result_tests\WinPython-32bit-3.4.1.1_build05c\tools\Julia\lib\libjulia.dylib
stevengj commented 10 years ago

It's not clear that pyjulia is read for prime-time either, so things are in an unfortunate state of flux. (See also jakebolewski/pyjulia#1) Once pyjulia seems usable, I definitely would like to delete the code from IJulia and direct people there.

What was the Python 3 fix?

Regarding finding the shared library, I think pyjulia fixed this on Windows.

All the pieces are there, we just really need someone who is motivated to work on this.

stonebig commented 10 years ago

Well, I'm not sure it's a right fix, but I did that in _init__.py , replace "core" per ".core"

from .core import Julia

in core.py, I did that

import sys
try:  # python 2.6
    import commands
except:  # python 3.3 
    import subprocess as commands

then i have the issue I described, that may be my fault, but I don't guess what my next fix should be. (ok looking what pyjulia did now)

stonebig commented 10 years ago

if I replace core.py of ijulia per core.py of pyjulia, I go one inch further

System image file "D\../lib/julia/sys.ji" not found

Do i need to have %JULIA_HOME%..\lib\julia in the path ? (\bin alone is not sufficient ?) this "D\" is wrong under windows (i don't catch what program did invent that)

posting my path and 'set' for anyone having a clue on next fix

!echo %path%
D:\result_tests\WinPython-32bit-3.4.1.1_build05c\python-3.4.1\lib\site-packages\numpy\core;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\..\tools\Julia\bin\;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\..\tools\Julia\bin\..\lib\julia;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\Lib\site-packages\PyQt4;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\DLLs;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\Scripts;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\..\tools;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\..\tools\gnuwin32\bin;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\..\tools\mingw32\bin;C:\Python34\;C:\Python34\Scripts;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Users\Lauriane\Downloads\ruby-Scite\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\Common Files\Ulead Systems\MPEG;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;C:\Program Files (x86)\Windows Live\Shared;C:\Users\Lauriane\Downloads\Install\android-sdk-windows\tools;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Users\Lauriane\Downloads\ruby-Scite\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\Common Files\Ulead Systems\MPEG;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;C:\Program Files (x86)\Windows Live\Shared;C:\Users\Lauriane\Downloads\Install\android-sdk-windows\tools;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Users\famille\AppData\Local\Programs\Git\cmd;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\..\tools\TortoiseHg
!set
CLICOLOR=1
CM2013DIR=C:\Program Files (x86)\Common Files\Autodesk Shared\Materials\
GIT_PAGER=cat
PAGER=cat
PCBRAND=Pavilion
SYSTEMROOT=C:\Windows
FP_NO_HOST_CHECK=NO
APPDATA=C:\Users\famille\AppData\Roaming
NUMBER_OF_PROCESSORS=4
ONLINESERVICES=Online Services
PUBLIC=C:\Users\Public
SYS_PATH=D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\Lib\site-packages\PyQt4;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\DLLs;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\Scripts;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\..\tools;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\..\tools\gnuwin32\bin;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\..\tools\mingw32\bin;C:\Python34\;C:\Python34\Scripts;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Users\Lauriane\Downloads\ruby-Scite\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\Common Files\Ulead Systems\MPEG;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;C:\Program Files (x86)\Windows Live\Shared;C:\Users\Lauriane\Downloads\Install\android-sdk-windows\tools;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Users\Lauriane\Downloads\ruby-Scite\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\Common Files\Ulead Systems\MPEG;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;C:\Program Files (x86)\Windows Live\Shared;C:\Users\Lauriane\Downloads\Install\android-sdk-windows\tools;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Users\famille\AppData\Local\Programs\Git\cmd;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\..\tools\TortoiseHg
OS=Windows_NT
ILLDIR=C:\Program Files (x86)\Common Files\Autodesk Shared\Materials\
PSMODULEPATH=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
TERM=xterm-color
VS100COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\
WINPYVER=3.4.1.1
JULIA_EXE=julia.exe
LOCALAPPDATA=C:\Users\famille\AppData\Local
HOME=D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\..\settings
USERPROFILE=C:\Users\famille
PATH=D:\result_tests\WinPython-32bit-3.4.1.1_build05c\python-3.4.1\lib\site-packages\numpy\core;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\..\tools\Julia\bin\;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\..\tools\Julia\bin\..\lib\julia;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\Lib\site-packages\PyQt4;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\DLLs;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\Scripts;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\..\tools;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\..\tools\gnuwin32\bin;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\..\tools\mingw32\bin;C:\Python34\;C:\Python34\Scripts;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Users\Lauriane\Downloads\ruby-Scite\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\Common Files\Ulead Systems\MPEG;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;C:\Program Files (x86)\Windows Live\Shared;C:\Users\Lauriane\Downloads\Install\android-sdk-windows\tools;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Users\Lauriane\Downloads\ruby-Scite\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\Common Files\Ulead Systems\MPEG;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;C:\Program Files (x86)\Windows Live\Shared;C:\Users\Lauriane\Downloads\Install\android-sdk-windows\tools;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Users\famille\AppData\Local\Programs\Git\cmd;D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\..\tools\TortoiseHg
JULIA=D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\..\tools\Julia\bin\julia.exe
WINPYDIR=D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1
PROMPT=$P$G
SESSIONNAME=Console
SYSTEMDRIVE=C:
USERDOMAIN=Sauron
TMP=C:\Users\famille\AppData\Local\Temp
TEMP=C:\Users\famille\AppData\Local\Temp
ALLUSERSPROFILE=C:\ProgramData
LOGONSERVER=\\SAURON
PROGRAMFILES=C:\Program Files (x86)
RUBYOPT=-rubygems
PROGRAMFILES(X86)=C:\Program Files (x86)
HOMEDRIVE=C:
WINDIR=C:\Windows
PROGRAMDATA=C:\ProgramData
COMSPEC=C:\Windows\system32\cmd.exe
PRIVATE_LIBDIR=bin
PLATFORM=MCD
PROCESSOR_LEVEL=6
PROCESSOR_ARCHITECTURE=x86
COMPUTERNAME=SAURON
ILBDIR=C:\Program Files (x86)\Common Files\Autodesk Shared\Materials\
PROGRAMW6432=C:\Program Files
USERNAME=famille
VBOX_INSTALL_PATH=D:\Program Files\Oracle\VirtualBox\
PROCESSOR_ARCHITEW6432=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 37 Stepping 2, GenuineIntel
PROCESSOR_REVISION=2502
HOMEPATH=\Users\famille
COMMONPROGRAMFILES=C:\Program Files (x86)\Common Files
JULIA_HOME=D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts\..\python-3.4.1\..\tools\Julia\bin\
COMMONPROGRAMW6432=C:\Program Files\Common Files
OMP_NUM_THREADS=4
COMMONPROGRAMFILES(X86)=C:\Program Files (x86)\Common Files
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.RB;.RBW;.PY
jakebolewski commented 10 years ago

pyjulia was mostly created to demo to someone using julia from python. At one point I was using a hybrid of python and julia so I thought I would have a stake in pushing this forward. Now I just use Julia so I have less incentive to work on this :-).

I do think that better python -> Julia support is important, but julia moves fast so I feel that support for this should come from someone who would be invested in actively maintaining it. Thoughts on better Python integration have been hashed out pretty thoroughly on the mailing list so searching there is probably the best place to look anyone is interested in this.

With regards to just getting something working for moment. The relative path to the system image used to be hard coded, now it looks like you can pass it in as a parameter: https://github.com/JuliaLang/julia/blob/master/src/jlapi.c#L53. You may have to play around with setting up the paths correctly on windows as I don't have any real knowledge of windows and windows support in pyjulia was contributed by someone else.

stonebig commented 10 years ago

when I try

api.jl_init_with_image(jl_init_path, os.path.join(jl_init_path, "..\lib\julia\sys.ji"))

the error changes, which is good news in itself, but message is unexpected

System image file "D\D" not found

Could there be a Python3 "string" handling issue ?

If I try

api.jl_init_with_image(jl_init_path.encode('ascii'), "..\\lib\\julia\\sys.ji".encode('ascii'))

I get , in the notebook this time

D:\result_tests\WinPython-32bit-3.4.1.1_build05c\python-3.4.1\lib\site-packages\julia\core.py in __init__(self, init_julia, jl_init_path)
    366                 self.call('using PyCall')
    367             except:
--> 368                 raise JuliaError("Julia does not have package PyCall")
    369             try:
    370                 self.call('pyinitialize(C_NULL)')

JuliaError: Julia does not have package PyCall

... progress , so

julia> Pkg.add("PyCall")
julia> Pkg.update()

but then Load_magic does nothing but lock my notebook,

If I try

import julia
j = julia.Julia()

I get a

D:\result_tests\WinPython-32bit-3.4.1.1_build05c\python-3.4.1\lib\site-packages\julia\core.py in __init__(self, init_julia, jl_init_path)
    370                 self.call('pyinitialize(C_NULL)')
    371             except:
--> 372                 raise JuliaError("Failed to initialize PyCall package")
    373 
    374         # Whether we initialized Julia or not, we MUST create at least one

JuliaError: Failed to initialize PyCall package

and in the dos window

symbol could not be found Py_IsInitialized (-1): no error

so, 2 inches further, but no clue after that.

stonebig commented 10 years ago

Is this relevant for my problem ? https://groups.google.com/forum/#!topic/julia-users/lDM7-YXT2LU

To make PyCall work with python3, the following environment variable needs to be set:
julia> ENV["PYTHON"]="python3"
If that doesn't work, try:
julia> ENV["PYTHON"]="/usr/bin/python3"

(seems not, and setting %PYTHONHOME% neither)

stevengj commented 10 years ago

No, that shouldn't be relevant. When you call Julia from Python, the Python library is already loaded in memory, and so it doesn't need to know the name of the Python executable. Here, it's not even getting to the point where Python 2 vs. Python 3 should matter .... it's just trying to look up the symbol Py_IsInitialized (part of libpython) in the default/global namespace (which is where libpython is on other systems when you are running from python) and failing.

stonebig commented 10 years ago

do you mean I need to install this on my windows python ?

http://www.lfd.uci.edu/~gohlke/pythonlibs/#libpython
Libpython installs the libpython??.a and libmsvcr??.a libraries to Python\libs. For use with MinGW64/Rtools.

(I see only a 64 bit version on Christoph Gohlke site..) does it mean it can only work with a python 64 bits ?

jakebolewski commented 10 years ago

Can use use pycall from julia to talk to python? Getting that to work is a necessary first step towards calling julia from python.

stonebig commented 10 years ago
D:\result_tests\WinPython-32bit-3.4.1.1_build05c\scripts>julia
               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "help()" to list help topics
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.3.0-rc1+61 (2014-07-17 20:55 UTC)
 _/ |\__'_|_|_|\__'_|  |  Commit c4547e6 (1 day old master)
|__/                   |  i686-w64-mingw32

julia> using PyCall

julia> @pyimport math

julia> math.sin(math.pi / 4) - sin(pi / 4)
0.0

julia> @pyimport numpy.random as nr

julia> nr.rand(3,4)
3x4 Array{Float64,2}:
 0.832927  0.0302319  0.349613  0.111176
 0.374895  0.221529   0.999916  0.510089
 0.621628  0.21596    0.530169  0.00968739

julia>
stonebig commented 10 years ago

I assume that, maybe, the test "self.call('pyinitialize(C_NULL)')" is irrelevant in Windows 32bit mode, so I put this line in comment, and try something that ... seems to work, so the 'assumation' seems not impossible to me... ''''

raise JuliaError("Failed to initialize PyCall package")

            print(" Julia error ? Failed to initialize PyCall package")

'''' python_calling_julia_v01

To get there, I had to do a dir(j) and discover that 'j.run("2+2")' must be replaced by 'j.eval("2+2")'

so, the magic error seems to be just the same problem

%load_ext julia.magic
%%julia
println("Hello from Julia!\n")
[1:10]

gives

D:\result_tests\WinPython-32bit-3.4.1.1_build05c\python-3.4.1\lib\site-packages\julia\magic.py in julia(self, line, cell)
     57         """
     58         src = str(line if cell is None else cell)
---> 59         return self.julia.run(src)
     60 
     61 

D:\result_tests\WinPython-32bit-3.4.1.1_build05c\python-3.4.1\lib\site-packages\julia\core.py in __getattr__(self, name)
    419 
    420     def __getattr__(self, name):
--> 421         bases = object.__getattribute__(self, 'bases')
    422         if not name in bases:
    423             raise AttributeError("Name {} not found".format(name))

AttributeError: 'Julia' object has no attribute 'bases'

so replacing 'run' per 'eval' in julia\magic.py

        #return self.julia.run(src)
        return self.julia.eval(src)

I get ..... python_calling_julia_v02

.. I'm not sure where the patches should be done, and don't feel expert enough in julia to propose them, If I register my steps well

                api.jl_init(jl_init_path)

should be replaced by

                api.jl_init_with_image(jl_init_path.encode('ascii'), "..\\lib\\julia\\sys.ji".encode('ascii')) 
self.call('pyinitialize(C_NULL)')
        #return self.julia.run(src)
        return self.julia.eval(src)
stevengj commented 10 years ago

No, you definitely need to call pyinitialize, or PyCall will not work. If PyCall can't find Py_IsInitialized that means it is unable to call functions in libpython, and nothing will work.

stonebig commented 10 years ago

so my call is failing, but still doing something usefull ? catching the error and getting over it in win32 is ok ?

stevengj commented 10 years ago

@stonebig, I have to admit that I'm pretty confused by why Py_IsInitialized would not exist but that anything else would work.

stonebig commented 10 years ago

WinRPM includes "i686-w64-mingw32\sys-root\mingw\binlibgcc_s_sjlj-1.dll" The initial mingw I used (for cython), includes "libgcc_s_dw2-1.dll" After reading the site http://tdm-gcc.tdragon.net/quirks, it may be an explanation. Does WinRPM rely on the "MinGW-w64" project for its 32 bit binary, in i686-w64-mingw32 , or on "Mingw" project ? (I took the most popular by downloads)

ihnorton commented 10 years ago

I can't read through this discussion right now, but my concern would be that those DLLs have different exception models - sjlj vs dwarf. Not sure why that would be relevant to missing symbol though if that is the problem. You may want to check the libpythpn exports with sysinternals dep explorer On Jul 24, 2014 1:09 PM, "stonebig" notifications@github.com wrote:

WinRPM includes "i686-w64-mingw32\sys-root\mingw\binlibgcc_s_sjlj-1.dll" The initial mingw I used (for cython), includes "libgcc_s_dw2-1.dll" After reading the site http://tdm-gcc.tdragon.net/quirks, it may be an explanation. Does WinRPM rely on the "MinGW-w64" project for its 32 bit binary, in i686-w64-mingw32 , or on "Mingw" project ?

— Reply to this email directly or view it on GitHub https://github.com/JuliaLang/IJulia.jl/issues/206#issuecomment-50047949.

stonebig commented 10 years ago

It's still written "Do not install Python 3" on the windows readme, so my troubles may be just that

https://github.com/JuliaLang/julia/blob/master/README.windows.md

ihnorton commented 10 years ago

That is referring to building Julia from source.

You will probably need to try to isolate things step by step.

julia> h = dlopen("/path/to/libpython.dll")
julia> dlsym(h, "Py_IsInitialized")
stonebig commented 10 years ago

hi, Thing are getting sorted on windows

takluyver commented 10 years ago

To replace the use of the commands module, which is gone in Python 3, you can do this:

            try:
                JULIA_HOME = subprocess.check_output(
                                     ['julia', '-e', "print(JULIA_HOME)"],
                                     universal_newlines=True)
            except subprocess.CalledProcessError:
                raise JuliaMagicError('error starting up the Julia process')

I can't test much beyond that point because of issue #220.

stevengj commented 8 years ago

Closing as is now purely a pyjulia thing.