2

I'm a new beginner with python und have recently installed Julia. And as I wrote "from julia import Main" in Jupyter note through Anaconda, an error would occur which is "no module named 'julia'". I don't know which part is wrong or is this about the path of the installation of Julia? enter image description here

I would appreciate it so much if you could help me.

  • 4
    You normally program Julia in a Jupyter notebook with a Julia kernel. What exactly are you trying to do? Perhaps you want to call Julia from Python? If this is true please have a look at my tutorial here: https://stackoverflow.com/questions/64241264/i-have-a-high-performant-function-written-in-julia-how-can-i-use-it-from-python/64241265#64241265 – Przemyslaw Szufel Jun 30 '21 at 18:35
  • Everything works until the fourth setp, as I worte “from julia import Main” another error occured said that "ERROR: zsh: segmentation fault python3" – IchbinAuslander Jul 01 '21 at 07:51
  • Please provide a detailed description what steps are you taking starting from the command line along with all commands and errors. `segmentation fault python3` could be a possible mismatch of versions (running 32-bit Python with 64-bit Julia) or maybe just a Pkg.build("PyCall") could be enough. Hard to tell without more information. – Przemyslaw Szufel Jul 01 '21 at 12:17
  • 2
    Thank you. @PrzemyslawSzufel, I just made it. The problem is that I have to set up the path right first and then Pkg.build("PyCall") as you said – IchbinAuslander Jul 01 '21 at 12:41

1 Answers1

4

"from x import y" is the syntax for importing Python packages in a Python script or notebook, but as you probably know, Julia is a separate language of its own, not a Python package.

If you want to use Julia in a Jupyter notebook, you will instead generally want to change the whole Jupyter kernel to Julia from Python, rather than just adding a package (though see comment from Przemyslaw above if you want to call Julia from Python for any reason).

The easiest way to install a Julia kernel for Jupyter and start a notebook using that kernel is to just start the Jupyter notebook from Julia. In other words, first start Julia, so that you have a Julia REPL that looks something like the image below, and then type

julia> using Pkg; Pkg.add("IJulia") # If IJulia is not already installed
julia> using IJulia
julia> notebook()

Starting a Jupyter instance from Julia

which will open up a Jupyter instance with a Julia kernel installed, from which you can open a new notebook using that Julia kernel

Starting a new Julia notebook

which should look like the following (note the Julia symbol in the upper right corner)

Julia running in Jupyter notebook

Note that at no point in this process do you use Python or Anaconda for anything, and note also that in Julia there is no from keyword and also generally no such thing as Main

cbk
  • 4,225
  • 6
  • 27
  • I did as you said, but the same error still occurs "ModuleNotFoundError: No module named 'julia'" – IchbinAuslander Jul 01 '21 at 07:44
  • Perhaps I did not make my point sufficiently clear: there is no scenario in which you should _ever_ type `from julia import Main`. That is a python-specific syntax and has no meaning in Julia. – cbk Jul 01 '21 at 14:02
  • I have elaborated a bit more above – cbk Jul 01 '21 at 14:58
  • maybe my description is kinda of chaos, but I have solved the problem yesterday, the whole problem is that the "PATH" was not settled to the enviroment, and after that I can do everything as usual. Thank you anyway :) – IchbinAuslander Jul 02 '21 at 17:47