Skip to content

Commit d737299

Browse files
authored
default to python3 on Unix (#512)
1 parent e42d165 commit d737299

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private to Julia (not in your `PATH`). You can use the `Conda` Julia
3535
package to install more Python packages, and `import Conda` to print
3636
the `Conda.PYTHONDIR` directory where `python` was installed.
3737
On GNU/Linux systems, PyCall will default to using
38-
the `python` program (if any) in your PATH.
38+
the `python3` program (if any, otherwise `python`) in your PATH.
3939

4040
The advantage of a Conda-based configuration is particularly
4141
compelling if you are installing PyCall in order to use packages like
@@ -48,7 +48,7 @@ your own packages, use the `pyimport_conda` function described below.)
4848

4949
If you want to use a different version of Python than the default, you
5050
can change the Python version by setting the `PYTHON` environment variable
51-
to the path of the `python` executable and then re-running `Pkg.build("PyCall")`.
51+
to the path of the `python` (or `python3` etc.) executable and then re-running `Pkg.build("PyCall")`.
5252
In Julia:
5353

5454
ENV["PYTHON"] = "... path of the python program you want ..."
@@ -251,7 +251,7 @@ a NumPy array (currently of numeric types or objects only). Just use
251251
`PyArray` as the return type of a `pycall` returning an `ndarray`, or
252252
call `PyArray(o::PyObject)` on an `ndarray` object `o`. (Technically,
253253
a `PyArray` works for any Python object that uses the NumPy array
254-
interface to provide a data pointer and shape information.)
254+
interface to provide a data pointer and shape information.)
255255

256256
Conversely, when passing arrays *to* Python, Julia `Array` types are
257257
converted to `PyObject` types *without* making a copy via NumPy,
@@ -336,7 +336,7 @@ and also by providing more type information to the Julia compiler.
336336
Python object reference, or of `PyAny` to request an automated conversion).
337337
For convenience, a macro `@pycall` exists which automatically converts
338338
`@pycall function(args...)::returntype` into
339-
`pycall(function,returntype,args...)`.
339+
`pycall(function,returntype,args...)`.
340340

341341
* `pyimport(s)`: Import the Python module `s` (a string or symbol) and
342342
return a pointer to it (a `PyObject`). Functions or other symbols

deps/build.jl

+12-1
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,21 @@ function writeifchanged(filename, str)
157157
end
158158
end
159159

160+
# return the first arg that exists in the PATH
161+
function whichfirst(args...)
162+
for x in args
163+
if Compat.Sys.which(x) !== nothing
164+
return x
165+
end
166+
end
167+
return ""
168+
end
169+
160170
try # make sure deps.jl file is removed on error
161171
python = try
162172
let py = get(ENV, "PYTHON", isfile("PYTHON") ? readchomp("PYTHON") :
163-
(Compat.Sys.isunix() && !Compat.Sys.isapple()) || Sys.ARCH (:i686, :x86_64) ? "python" : ""),
173+
(Compat.Sys.isunix() && !Compat.Sys.isapple()) || Sys.ARCH (:i686, :x86_64) ?
174+
whichfirst("python3", "python") : "Conda"),
164175
vers = isempty(py) || py == "Conda" ? v"0.0" : vparse(pyconfigvar(py,"VERSION","0.0"))
165176
if vers < v"2.7"
166177
if isempty(py) || py == "Conda"

0 commit comments

Comments
 (0)