JuliaPy / PyCall.jl

Package to call Python functions from the Julia language
MIT License
1.47k stars 187 forks source link

Pycall Gets Error in PyCharm and in Jupyter Lab but works in iPython #1037

Closed dbl001 closed 1 year ago

dbl001 commented 1 year ago

I am running Julia and Python on MacOS 13.4. Python 3.11, Julia 1.9.0

 % ipython
Python 3.11.0 | packaged by conda-forge | (main, Oct 25 2022, 06:24:51) [Clang 14.0.4 ]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.7.0 -- An enhanced Interactive Python. Type '?' for help.

% julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.9.0 (2023-05-07)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using Pkg

julia> Pkg.update("PyCall")
  No Changes to `~/anaconda3/envs/pysr_test/share/julia/environments/pysr_test/Project.toml`
  No Changes to `~/anaconda3/envs/pysr_test/share/julia/environments/pysr_test/Manifest.toml`
[ Info: We haven't cleaned this depot up for a bit, running Pkg.gc()...
      Active manifest files: 3 found
      Active artifact files: 5 found
      Active scratchspaces: 4 found
     Deleted 2 package installations (354.976 KiB)
     Deleted 2 scratchspaces (110.000 byte)

julia> 

If I try to debug 'PySR' code in PyCharm or JupyterLab I get this error:

/Users/davidlaxer/anaconda3/envs/pysr_test/bin/python /Users/davidlaxer/PySR/test.py 
DEBUG (70325) 
DEBUG (70325) Debug-level logging is enabled for PyJulia.
DEBUG (70325) PyJulia version: 0.6.0
DEBUG (70325) 
/Users/davidlaxer/anaconda3/envs/pysr_test/lib/python3.11/site-packages/julia/juliainfo.py:93: UserWarning: julia warned:
Installing Julia 1.9.0+0.x64.apple.darwin14
  warnings.warn("{} warned:\n{}".format(julia, stderr))
DEBUG (70325) pyprogramname = None
DEBUG (70325) sys.executable = /Users/davidlaxer/anaconda3/envs/pysr_test/bin/python
DEBUG (70325) bindir = /Users/davidlaxer/.julia/juliaup/julia-1.9.0+0.x64.apple.darwin14/bin
DEBUG (70325) libjulia_path = /Users/davidlaxer/.julia/juliaup/julia-1.9.0+0.x64.apple.darwin14/lib/libjulia.1.9.dylib
DEBUG (70325) is_compatible_python = None
DEBUG (70325) use_custom_sysimage = False
DEBUG (70325) compiled_modules = 'no'
DEBUG (70325) argv_list = [b'/Users/davidlaxer/anaconda3/envs/pysr_test/bin/python', b'--compiled-modules=no', b'--threads=auto']
DEBUG (70325) argc = c_int(3)
DEBUG (70325) jl_parse_opts called
DEBUG (70325) argc = c_int(0)
DEBUG (70325) calling jl_init_with_image(/Users/davidlaxer/.julia/juliaup/julia-1.9.0+0.x64.apple.darwin14/bin, /Users/davidlaxer/.julia/juliaup/julia-1.9.0+0.x64.apple.darwin14/lib/julia/sys.dylib)
DEBUG (70325) seems to work...
┌ Error: Failed to import PyCall
│   exception =
│    ArgumentError: Package PyCall [438e738f-606a-5dbb-bf0a-cddfbfd45ab0] is required but does not seem to be installed:
│     - Run `Pkg.instantiate()` to install all recorded dependencies.
│    
│    Stacktrace:
│     [1] _require(pkg::Base.PkgId, env::Nothing)
│       @ Base ./loading.jl:1739
│     [2] _require_prelocked(uuidkey::Base.PkgId, env::Nothing)
│       @ Base ./loading.jl:1625
│     [3] _require_prelocked
│       @ ./loading.jl:1623 [inlined]
│     [4] macro expansion
│       @ ./lock.jl:267 [inlined]
│     [5] require(uuidkey::Base.PkgId)
│       @ Base ./loading.jl:1620
│     [6] top-level scope
│       @ none:3
└ @ Main none:5
DEBUG (70325) exception occured? 5658609680
Traceback (most recent call last):
  File "/Users/davidlaxer/PySR/test.py", line 11, in <module>
    julia = Julia(compiled_modules=False, debug=True, threads='auto')
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/davidlaxer/anaconda3/envs/pysr_test/lib/python3.11/site-packages/julia/core.py", line 702, in __init__
    self.__julia = Julia(*args, **kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/davidlaxer/anaconda3/envs/pysr_test/lib/python3.11/site-packages/julia/core.py", line 510, in __init__
    self._call("""
  File "/Users/davidlaxer/anaconda3/envs/pysr_test/lib/python3.11/site-packages/julia/core.py", line 555, in _call
    self.check_exception(src)
  File "/Users/davidlaxer/anaconda3/envs/pysr_test/lib/python3.11/site-packages/julia/core.py", line 609, in check_exception
    raise JuliaError(u'Exception \'{}\' occurred while calling julia code:\n{}'
julia.core.JuliaError: Exception 'ArgumentError' occurred while calling julia code:

            const PyCall = try
                Base.require(Base.PkgId(Base.UUID("438e738f-606a-5dbb-bf0a-cddfbfd45ab0"), "PyCall"))
            catch err
                @error "Failed to import PyCall" exception = (err, catch_backtrace())
                rethrow()
            end

SYSTEM: caught exception of type :ArgumentError while trying to print a failed Task notice; giving up

Process finished with exit code 1
Screenshot 2023-05-19 at 12 46 21 PM

From terminal:

DEBUG (70594) calling jl_init_with_image(/Users/davidlaxer/anaconda3/envs/pysr_test/share/julia/juliaup/julia-1.9.0+0.x64.apple.darwin14/bin, /Users/davidlaxer/anaconda3/envs/pysr_test/share/julia/juliaup/julia-1.9.0+0.x64.apple.darwin14/lib/julia/sys.dylib)

From PyCharm:

DEBUG (70325) calling jl_init_with_image(/Users/davidlaxer/.julia/juliaup/julia-1.9.0+0.x64.apple.darwin14/bin, /Users/davidlaxer/.julia/juliaup/julia-1.9.0+0.x64.apple.darwin14/lib/julia/sys.dylib)
dbl001 commented 1 year ago

PyCharm was getting Julia from ~/.julia/juliaup/julia-1.9.0+0.x64.apple.darwin14/bin NOT my conda virtual environment!