anaconda / nb_conda_kernels

Package for managing conda environment-based kernels inside of Jupyter
BSD 3-Clause "New" or "Revised" License
601 stars 70 forks source link

/bin/sh: module: line 1: syntax error: unexpected end of file #134

Closed edurand closed 5 years ago

edurand commented 5 years ago

Hello,

My setup is as follow: I have a conda environment where I installed Jupyter and nb_conda_kernels, and other conda environments where I installed ipykernel (among other things).

I am running into the following error: when starting the Jupyter environment Python kernel, all is fine. However, when starting a kernel from another conda environment, I get the following error message:

/bin/sh: module: line 1: syntax error: unexpected end of file 
/bin/sh: error importing function definition for `BASH_FUNC_module'

Any idea what's going on? I'm out of ideas. Thanks!

edurand commented 5 years ago

OK, this is not a nb_conda_kernels bug, I'm going to close the issue. However, for future reference, here's what happened:

After further investigation, the error is thrown in runner.py by

os.execvpe(command, (command,) + args, env)

The offending key, value in env is

'BASH_FUNC_module()': '() {  eval `/usr/bin/modulecmd bash $*`'

Obviously the function definition lacks a closing bracket. Looking at the output of printenv:

$printenv
...
BASH_FUNC_module()=() {  eval `/usr/bin/modulecmd bash $*`
}
_=/usr/bin/printenv

The function is defined over two lines which causes it to be "incorrectly" parsed in runner.py. I fixed it by downgrading to 2.1.0. Better solution would be to upgrade red hat...

mcg1969 commented 5 years ago

I'm going to leave this open, because frankly it suggests we should be doing a better job of obtaining the environment.

edurand commented 5 years ago

Why not simply call os.environ? It gives you a dict already - no need for manual parsing. In my case, the BASH_FUNC_module() is correctly parsed by os.environ.

mcg1969 commented 5 years ago

We need the environment after it is possibly modified by the subprocess.

edurand commented 5 years ago

OK, would replacing the printenv function by a Python script calling os.environ and serialising (json?) its output to stdout achieve the desired effect?

mcg1969 commented 5 years ago

That may be necessary but I'd prefer to avoid the extra process. (The shell has to happen regardless in order to source any post-activate scripts.)

mcg1969 commented 5 years ago

What am I saying, env is a process!

edurand commented 5 years ago

I could put together a PR if you'd like

On Fri, Mar 22, 2019 at 6:13 PM Michael C. Grant notifications@github.com wrote:

What am I saying, env is a process!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Anaconda-Platform/nb_conda_kernels/issues/134#issuecomment-475703835, or mute the thread https://github.com/notifications/unsubscribe-auth/ABI7KidJPBcAJRQcqBHgmkG3k-2gjsdgks5vZQ9EgaJpZM4b8boT .

mcg1969 commented 5 years ago

Hey, that's great! But I'm working on one now. I'll tag you on the PR for review.