Hi Guys, am new to Julia and am developing a Tic Tac Toe AI board game and i happen to have issues with importing board.I know in python it’s
import board
how do i do this in Julia?
Hi Guys, am new to Julia and am developing a Tic Tac Toe AI board game and i happen to have issues with importing board.I know in python it’s
import board
how do i do this in Julia?
using Board
Or are you talking about importing a python package in julia?
using PyCall
board = pyimport("board")
I have tried using Board
but I get the following error
julia> Pkg.add(“Board”)
Updating registry at C:\Users\NEW\.julia\registries\General
Updating git-repo https://github.com/JuliaRegistries/General.git
ERROR: The following package names could not be resolved:
name=uuid
.It is
include("board.jl")
In python import load a file, but in Julia using read a package, not a file, and a package has a specific structure.
@dmolina am trying this but it doesn’t work, could kindly provide more info on how i should use it? thanks
It is not fully clear to me, what you are trying to do. So is board.jl
some file you created on your computer? Or is it some repo on github? Or is it a python package?
The PyCall docs:
By default on Mac and Windows systems,
Pkg.add("PyCall")
orPkg.build("PyCall")
will use the Conda.jl package
Implying not used on Linux (is that outdated, and used there too?). At least on Linux, where you have Python 3 preinstalled, I could do (and I don’t find that package in Anaconda), and note the 3 in pip3, therefore may be important:
shell> pip3 install board
but then had to build PyCall correctly:
julia> ENV["PYTHON"] = "python3" # will not be enough on Windows, see docs
julia> using Pkg; Pkg.build("PyCall")
exit Julia and start again:
julia> using PyCall
julia> board = pyimport("board")
julia> b[0, 0] = "X" # works, but warning:
┌ Warning: `setindex!(o::PyObject, v, i1::Integer, i2::Integer)` is deprecated, use `set!(o, (i1 - 1, i2 - 1), v)` instead.
│ caller = top-level scope at REPL[12]:1
└ @ Core REPL[12]:1
"X"
You can e.g. do as in Python (for strings and this package, index from the end of the board):
julia> set!(b, (-1, 0), "X")
"X"
julia> get(b, (-1, 0))
"X"
Note, in general such negative indexing or starting from 0 in not done in Julia. I believe the deprecation above (can you disable the warning? I think it’s only in the REPL, not your working program) is there to allow the usual indexing as done in Julia, in a future PyCall version, for Python objects, shifting for you by one (and I guess loosing out on the negative, Julia uses “end” for that, or end-n).