Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set PATH before running conda #121

Closed
wants to merge 4 commits into from
Closed

Set PATH before running conda #121

wants to merge 4 commits into from

Conversation

tkf
Copy link
Member

@tkf tkf commented Sep 20, 2018

close #125

src/Conda.jl Outdated
@@ -103,6 +103,8 @@ function _set_conda_env(cmd, env::Environment=ROOTENV)
env_var["PYTHONIOENCODING"]="UTF-8"
env_var["CONDARC"] = conda_rc(env)
env_var["CONDA_PREFIX"] = prefix(env)
path_sep = Compat.Sys.iswindows() ? ';' : ':'
env_var["PATH"] = bin_dir(env) * path_sep * ENV["PATH"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get(ENV, "PATH", "")

test/runtests.jl Outdated

cmd = `python -c "import sys; print(sys.executable)"`
path = rstrip(read(_set_conda_env(cmd, env), String))
@test startswith(normpath(path), normpath(bin_dir(env)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

startwith or normpath(dirname(path)) == normpath(bin_dir(env))?

test/runtests.jl Outdated
@test isfile(pythonpath)

cmd = Conda._set_conda_env(`$pythonpath -c "import zmq"`, env)
@test_throws Exception run(cmd)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work if pyzmq is already installed — people don't necessarily run test Conda on a clean installation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In particular, what happens if you run the tests twice in a row? Won't pyzmq still be installed from the previous run?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, @test !success(cmd) was just a leftover from the previous version.

To make ]test Conda easier, how about doing

try
    Conda.rm("--all", env)
catch
end

(or with something similar with cleaner handling of exception)?

@stevengj
Copy link
Member

I'm still unclear why it is necessary to set the PATH. Can't you just run python by specifying the full pathname?

@tkf
Copy link
Member Author

tkf commented Sep 20, 2018

I don't know, but from JuliaLang/IJulia.jl#739 (comment) and #119 (comment) (and that conda is not super well-behaved package manager, at least ATM), I just thought I'd try. But making the test in #122 fail properly was already hard...

@tkf
Copy link
Member Author

tkf commented Sep 20, 2018

BTW, when I run conda shell.powershell activate base (which is, I suppose, the internal of conda activate), I get:

$env:CONDA_DEFAULT_ENV = "base"
$env:CONDA_EXE = "/home/takafumi/miniconda3/bin/conda"
$env:CONDA_PREFIX = "/home/takafumi/miniconda3"
$env:CONDA_PROMPT_MODIFIER = "(base) "
$env:CONDA_PYTHON_EXE = "/home/takafumi/miniconda3/bin/python"
$env:CONDA_SHLVL = "1"
$env:PATH = "/home/takafumi/miniconda3\bin;..."

(the output is weird since I'm on linux)

So it seems PATH is the only relevant thing conda activate ... alters.

src/Conda.jl Outdated
@@ -103,6 +103,12 @@ function _set_conda_env(cmd, env::Environment=ROOTENV)
env_var["PYTHONIOENCODING"]="UTF-8"
env_var["CONDARC"] = conda_rc(env)
env_var["CONDA_PREFIX"] = prefix(env)
path_sep = Compat.Sys.iswindows() ? ';' : ':'
if haskey(ENV, "PATH")
env_var["PATH"] = bin_dir(env) * path_sep * ENV["PATH"]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#121 (comment): Good catch, but get(ENV, "PATH", "") could put $PWD into $PATH?

@tkf
Copy link
Member Author

tkf commented Sep 20, 2018

@tkf
Copy link
Member Author

tkf commented Sep 20, 2018

But only (random?) half of the tests are fixed by this https://ci.appveyor.com/project/StevenGJohnson/conda-jl/build/1.0.121 So strange...

@tkf
Copy link
Member Author

tkf commented Sep 20, 2018

Reading ContinuumIO/anaconda-issues#10082, it looks like it would be fixed on conda side. Maybe it's better to do Conda.add("python=3.6") inside Conda._install_conda while waiting for that?

@stevengj
Copy link
Member

I'm worried that this will also screw up PyCall… importing Python modules won't work if the Python modules depend on the PATH being set.

@tkf
Copy link
Member Author

tkf commented Sep 20, 2018

Yeah, Conda.jl has to mutate ENV. Or maybe PyCall.jl can temporary mutate ENV in pyimport_conda? (Similar hack for LD_LIBRARY_PATH on Linux won't work, but I don't know what happens in Windows.)

But that's ugly so Conda.add("python=3.6") started sound better to me... Or using slightly old miniconda3 URL would be the easiest solution?

@tkf tkf closed this Sep 21, 2018

Extra `ENV["PATH"]` required for conda environment `env`.
"""
function extra_path(env::Environment)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somebody has to write a code to pass this to SetDllDirectory or AddDllDirectory in PyCall.__init__: #125 (comment)


function _set_path(env_var, env::Environment)
if Compat.Sys.iswindows()
# Environment variables are case-insensitive. `Base.EnvDict`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you file a Julia issue for this? Seems like it should be fixed in Base.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just because

julia> typeof(copy(ENV))
Dict{String,String}

To solve this, I think you need to add a case-insensitive in-memory dict to Base.

Copy link
Member

@stevengj stevengj Jan 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the easiest fix would be to replace copy(ENV) with

env_var = Dict(uppercase(k)=>v for (k,v) in ENV)

(Otherwise the other code in _set_conda_env would have to be fixed too.)

if Compat.Sys.iswindows()
return join([
prefix(env),
joinpath(prefix(env), "Library", "mingw-w64", "bin"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if it is 32-bit Windows?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. I don't notice any branching in conda/activate.py https://github.com/conda/conda/blob/4.6.0b0/conda/activate.py (But I'm not a Python interpreter)

If the folder does not exist, wouldn't it just be ignored? Also, it looks like win-32 and win-64 are different packages for binary libraries: https://anaconda.org/anaconda/pyzmq/files So I guess it wouldn't be installed in the first place?

# * https://github.com/ContinuumIO/anaconda-issues/issues/10082
# * https://github.com/conda/conda/issues/7789
res = "https://repo.continuum.io/miniconda/Miniconda$(MINICONDA_VERSION)-4.5.4-"
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this PR could be done before #125.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well..., the id of this PR is 121 (< #124)

Joking aside, this PR needs a coordination with PyCall to use SetDllDirectory/AddDllDirectory and for IJulia to tweak setup ENV["PATH"] before launching Jupyter Notebook. So I still think it makes sense to release a quick fix with #124 first to help Windows users.

I don't know much about Windows so please feel free to close this PR and implement another solution. I re-opened this PR because I though I'd better cleanup my suboptimal solution.

@stevengj
Copy link
Member

stevengj commented Jan 3, 2019

Sorry I haven't looked at this for a while. CI is failing?

@tkf
Copy link
Member Author

tkf commented Jan 3, 2019

I forgot the status of this PR :)

But I remember thinking that new conda version may provide a better way to do this (via conda run). I'll check if we can do this without hard-coding the paths for Windows.

@tkf
Copy link
Member Author

tkf commented Feb 12, 2020

It looks like #170 supersedes this PR. Closing...

@tkf tkf closed this Feb 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Waiting for upstream] Revert pinning Miniconda3-4.5.4 (Python 3.6) on Windows
2 participants