SciML / diffeqpy

Solving differential equations in Python using DifferentialEquations.jl and the SciML Scientific Machine Learning organization
MIT License
531 stars 39 forks source link

FileNotFoundError when trying to import diffeqpy from Jupyter #58

Closed Omer80 closed 11 months ago

Omer80 commented 4 years ago

I have just installed Julia-1.2 on macOS (version 10.14.6 (18G3020)), and then installed diffeqpy. I tried to import it in a Jupyter notebook with the command from diffeqpy import de, but got this error message:

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-5-65b37eb28595> in <module>
----> 1 from diffeqpy import de
      2 
      3 def f(u,p,t):
      4     return -u
      5 

/opt/anaconda3/lib/python3.7/site-packages/diffeqpy/de.py in <module>
      2 import sys
      3 
----> 4 from julia import Main
      5 
      6 script_dir = os.path.dirname(os.path.realpath(__file__))

/opt/anaconda3/lib/python3.7/importlib/_bootstrap.py in _find_and_load(name, import_)

/opt/anaconda3/lib/python3.7/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

/opt/anaconda3/lib/python3.7/importlib/_bootstrap.py in _load_unlocked(spec)

/opt/anaconda3/lib/python3.7/importlib/_bootstrap.py in _load_backward_compatible(spec)

/opt/anaconda3/lib/python3.7/site-packages/julia/core.py in load_module(self, fullname)
    244         if juliapath == 'Main':
    245             return sys.modules.setdefault(fullname,
--> 246                                           JuliaMainModule(self, fullname))
    247         elif self.julia.isafunction(juliapath):
    248             return self.julia.eval(juliapath)

/opt/anaconda3/lib/python3.7/site-packages/julia/core.py in __init__(self, loader, *args, **kwargs)
    146     def __init__(self, loader, *args, **kwargs):
    147         super(JuliaModule, self).__init__(*args, **kwargs)
--> 148         self._julia = loader.julia
    149         self.__loader__ = loader
    150 

/opt/anaconda3/lib/python3.7/site-packages/julia/core.py in julia(self)
    236     @property
    237     def julia(self):
--> 238         self.__class__.julia = julia = Julia()
    239         return julia
    240 

/opt/anaconda3/lib/python3.7/site-packages/julia/core.py in __init__(self, init_julia, jl_init_path, runtime, jl_runtime_path, debug, **julia_options)
    465             self.api = get_libjulia()
    466         elif init_julia:
--> 467             jlinfo = JuliaInfo.load(runtime)
    468             if jlinfo.version_info < (0, 7):
    469                 raise RuntimeError("PyJulia does not support Julia < 0.7 anymore")

/opt/anaconda3/lib/python3.7/site-packages/julia/juliainfo.py in load(cls, julia, **popen_kwargs)
     71             stderr=subprocess.PIPE,
     72             universal_newlines=True,
---> 73             **popen_kwargs
     74         )
     75 

/opt/anaconda3/lib/python3.7/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
    798                                 c2pread, c2pwrite,
    799                                 errread, errwrite,
--> 800                                 restore_signals, start_new_session)
    801         except:
    802             # Cleanup if the child failed starting.

/opt/anaconda3/lib/python3.7/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
   1549                         if errno_num == errno.ENOENT:
   1550                             err_msg += ': ' + repr(err_filename)
-> 1551                     raise child_exception_type(errno_num, err_msg, err_filename)
   1552                 raise child_exception_type(err_msg)
   1553 

FileNotFoundError: [Errno 2] No such file or directory: 'julia': 'julia'

I tried to install and build IJulia but it doesn't seem to make a difference... any help?

ChrisRackauckas commented 4 years ago

@tkf do you know anything about this?

tkf commented 4 years ago

I think it means that IPython cannot find command line program julia inside Jupyter.

To check if IPython can find julia, you can run !which julia (with !) inside Jupyter. If it says julia not found or sometihng similar, you need to specify the path to julia explicitly when using PyJulia. To find out the absolute path to julia, you can do which julia (no ! here) in the system shell (e.g., bash). Once you get the path, you can then do

from julia import Julia
Julia(runtime="PATH/TO/bin/julia")

from diffeqpy import de

with PATH/TO/bin/julia replaced with the actual path printed by which julia.

Ref: https://pyjulia.readthedocs.io/en/latest/api.html

Omer80 commented 4 years ago

!which julia resulted in:

which julia julia
/usr/local/bin/julia
/usr/local/bin/julia

What seems to work is:

from julia.api import Julia
jl = Julia(compiled_modules=False)
#jl(runtime="/usr/local/bin/julia")

from diffeqpy import de

However it takes quite a long time to import the package...

tkf commented 4 years ago

Do you get the same stacktrace as in the first post if you:

  1. Restart the IPython kernel, and then
  2. Evaluate from julia import Main

?

Omer80 commented 4 years ago

I've restarted the Kernel and used:

import time
start = time.time()
from julia import Main
end = time.time()
print(end - start)

But I have got FileNotFoundError:

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-4-d6cf9f272d96> in <module>
      1 import time
      2 start = time.time()
----> 3 from julia import Main
      4 end = time.time()
      5 print(end - start)

/opt/anaconda3/lib/python3.7/importlib/_bootstrap.py in _find_and_load(name, import_)

/opt/anaconda3/lib/python3.7/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

/opt/anaconda3/lib/python3.7/importlib/_bootstrap.py in _load_unlocked(spec)

/opt/anaconda3/lib/python3.7/importlib/_bootstrap.py in _load_backward_compatible(spec)

/opt/anaconda3/lib/python3.7/site-packages/julia/core.py in load_module(self, fullname)
    244         if juliapath == 'Main':
    245             return sys.modules.setdefault(fullname,
--> 246                                           JuliaMainModule(self, fullname))
    247         elif self.julia.isafunction(juliapath):
    248             return self.julia.eval(juliapath)

/opt/anaconda3/lib/python3.7/site-packages/julia/core.py in __init__(self, loader, *args, **kwargs)
    146     def __init__(self, loader, *args, **kwargs):
    147         super(JuliaModule, self).__init__(*args, **kwargs)
--> 148         self._julia = loader.julia
    149         self.__loader__ = loader
    150 

/opt/anaconda3/lib/python3.7/site-packages/julia/core.py in julia(self)
    236     @property
    237     def julia(self):
--> 238         self.__class__.julia = julia = Julia()
    239         return julia
    240 

/opt/anaconda3/lib/python3.7/site-packages/julia/core.py in __init__(self, init_julia, jl_init_path, runtime, jl_runtime_path, debug, **julia_options)
    465             self.api = get_libjulia()
    466         elif init_julia:
--> 467             jlinfo = JuliaInfo.load(runtime)
    468             if jlinfo.version_info < (0, 7):
    469                 raise RuntimeError("PyJulia does not support Julia < 0.7 anymore")

/opt/anaconda3/lib/python3.7/site-packages/julia/juliainfo.py in load(cls, julia, **popen_kwargs)
     71             stderr=subprocess.PIPE,
     72             universal_newlines=True,
---> 73             **popen_kwargs
     74         )
     75 

/opt/anaconda3/lib/python3.7/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
    798                                 c2pread, c2pwrite,
    799                                 errread, errwrite,
--> 800                                 restore_signals, start_new_session)
    801         except:
    802             # Cleanup if the child failed starting.

/opt/anaconda3/lib/python3.7/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
   1549                         if errno_num == errno.ENOENT:
   1550                             err_msg += ': ' + repr(err_filename)
-> 1551                     raise child_exception_type(errno_num, err_msg, err_filename)
   1552                 raise child_exception_type(err_msg)
   1553 

FileNotFoundError: [Errno 2] No such file or directory: 'julia': 'julia'
PARODBE commented 2 years ago

Hi,

I get the same problem. Could you help me, please?

image

Thanks!

ChrisRackauckas commented 11 months ago

Fixed by PythonCall transition