Skip to content
New issue

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

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

Already on GitHub? # to your account

show python requirements not found message and option to install #712

Merged
merged 10 commits into from
Oct 25, 2023

Conversation

mbektas
Copy link
Member

@mbektas mbektas commented Oct 2, 2023

  • Shows relevant error message when Python dependency packages such as jupyterlab are not found.
  • Provides option to copy the command to clipboard and installing the missing packages for user
  • Adds ability to open app logs from Settings dialog and progress views
  • copyable-span web component to support copying to clipboard from web views
  • Additional logging for shell executions and environment errors

python-env-requirements-message
show-logs

@mbektas mbektas marked this pull request as ready for review October 5, 2023 16:25
@mbektas mbektas requested a review from krassowski October 5, 2023 16:25
@krassowski
Copy link
Member

I started testing it, but did not get to it - I will report back tomorrow.

@krassowski
Copy link
Member

krassowski commented Oct 6, 2023

So when I tried to open an environment with an older version of JupyterLab:

jupyterlab             3.4.4
jupyterlab-server      2.15.0
jupyter-server         1.18.1

I got this distressing screen:

image

which has no environment picker so I cannot change the environment (without restarting app). I was able to use the hamburger menu to go to settings and grab the logs using the new "Show logs" button.

source "/home/krassowski/.pyenv/versions/<sanitized-out>/bin/activate"
        python -m jupyterlab --no-browser --expose-app-in-browser --ServerApp.port=43547 --ServerApp.password="" --ServerApp.token="jlab:srvr:<sanitized out>" --LabApp.quit_button=False --JupyterApp.config_file_name="" --ContentsManager.allow_hidden=True
[2023-10-06 09:31:09.239] [debug] Server launch parameters:
  [script]: /tmp/jlab_desktopIaMVVT/launch.sh
  [options]: {<sanitized out>}
[2023-10-06 09:31:09.589] [error] Error: Reader received error. Reason: Error during socket reconnect: code = 1006, reason = ,,
[2023-10-06 09:31:09.589] [error] Connection closed by the server
[2023-10-06 09:31:09.589] [error] Connection unexpectedly disconnected
[2023-10-06 09:31:10.074] [error] Failed to start server Error: Jupyter Server process terminated before the initialization completed
    at ChildProcess.<anonymous> (/opt/JupyterLab/resources/app.asar/build/out/main/server.js:306:28)
    at ChildProcess.emit (node:events:513:28)
    at Process.onexit (node:internal/child_process:291:12)
[2023-10-06 09:31:10.359] [warn]  Showing error: [object Object]
[2023-10-06 09:31:16.357] [warn]  Showing error: [object Object]

Note: running the command manually in the environment works fine, so I am not sure what is the error. In any way, the point is that there might be something wrong with version checks for Jupyter Server if it does not work?

@mbektas
Copy link
Member Author

mbektas commented Oct 6, 2023

@krassowski was this environment shown in your environment selection list on top right or did you browse the python path to select it? This failure is not due to version incompatibility, running the python -m jupyterlab somehow failed.

@krassowski
Copy link
Member

It's both. I do not have any suggestions in the environment list auto-populated because I use pyenv so I always have to browser for path to select it (hence I wish there was auto-detection for non-conda environments). But once I select it it stays in the environment selection list forever. It used to work previously, so I guess there may be something broken.
Re-iterating, running python -m jupyterlab with exact line as above from command line works fine.

@krassowski
Copy link
Member

I tried another environment which starts up fine with jupyterlab 3.6.3. My hypothesis was that it was the older JupyterLab version, so I downgraded. After downgrading the jupyterlab in the environment the picker tooltip still says that it sees 3.6.3. This is odd. How does it get jupyterlab version?

@mbektas
Copy link
Member Author

mbektas commented Oct 6, 2023

I tried another environment which starts up fine with jupyterlab 3.6.3. My hypothesis was that it was the older JupyterLab version, so I downgraded. After downgrading the jupyterlab in the environment the picker tooltip still says that it sees 3.6.3. This is odd. How does it get jupyterlab version?

Environment metadata is updated after a rediscovery, it should update the version shown in the list after few seconds from launch.

@mbektas
Copy link
Member Author

mbektas commented Oct 6, 2023

I tried in a conda environment with the same versions you posted above, and it worked just fine. jupyterlab >= 3.0.0 is supported

@krassowski
Copy link
Member

Ok, I know how to repro it reliably. It is a conflict of versions problem - it was happening when I stated jlab from my jupyterlab dev. Because of path overshadowing and not using path isolation it was pulling JupyterLab 4.0 Python executables, but then I selected an old environment to test it and it failed with the screen above.

So this is not a typical failure scenario, but it does show that this error screen needs work (in particular it would be lovely if it had the environment selector).

const requirementInstallCmd = encodeURIComponent(
this._registry.getRequirementsPipInstallCommand()
);
message = `Error! Required Python packages not found in the selected environment. You can install using <copyable-span label="${requirementInstallCmd}" copied="${requirementInstallCmd}"></copyable-span> command in the selected environment.`;
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to show the detected version here>

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 is possible. it is easier to just log them though.

this._requirements = [
{
name: 'jupyterlab',
moduleName: 'jupyterlab',
commands: ['--version'],
versionRange: new semver.Range(`>=${minJLabVersionRequired}`)
versionRange: new semver.Range(`>=${MIN_JLAB_VERSION_REQUIRED}`),
pipCommand: 'jupyterlab'
Copy link
Member

Choose a reason for hiding this comment

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

should it include >=${MIN_JLAB_VERSION_REQUIRED} as well?

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 was causing installation to fail on Windows. I will take another look.

@@ -446,6 +468,16 @@ export class Registry implements IRegistry, IDisposable {
return this._requirements;
}

getRequirementsPipInstallCommand(): string {
Copy link
Member

Choose a reason for hiding this comment

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

I am afraid that suggesting pip install will lead to many problems if novice conda users end up executing this in their env. Worst case scenario is having two conflicting versions with assets from one and scripts form another which is quite common problem but hard to debug.

Copy link
Member Author

Choose a reason for hiding this comment

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

is this an issue when an old jupyterlab is installed with conda install, then updated with pip install. I thought pip install was fine in a conda environment.

Copy link
Member

Choose a reason for hiding this comment

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

It will only work when NOT in the base environment (ideally in isolated environment) and if pip was explicitly installed. Many users fall into this trap.

Reference: https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#using-pip-in-an-environment

Copy link
Member

Choose a reason for hiding this comment

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

Of course if you install the same version in base and leaf env, one using pip and the other using conda, it does not matter. Up until the very moment one gets updated and then it breaks.

@mbektas
Copy link
Member Author

mbektas commented Oct 15, 2023

@krassowski could you take another look as I pushed some updates addressing your comments.

@krassowski
Copy link
Member

I think I am seeing an issue with PYTHONPATH. Previously I used to set it like this (simplifying) :

PYTHONPATH=/my/project/root/dir:$PYTHONPATH jlab

but this does not seem to work now? I am not 100% positive if this is due to this PR or because some setting got lost during uninstall/install sequence, but given that this PR touches python path logic it could be related.

This is kind of a deal breaker for me, but possibly not a common usage pattern. Note that configuring this in settings does not seem to work either. Is Python path overwritten at some point, or am I fooling myself?

I am going to try an older version now.

@mbektas
Copy link
Member Author

mbektas commented Oct 19, 2023

I think I am seeing an issue with PYTHONPATH

I tested both from CLI like your example and also from the settings dialog and both worked fine. This PR doesn't make any changes to environment variable setting.

@krassowski
Copy link
Member

Thank you for looking into this! Apologies for the delay with the actual review, will take another look soon.

Copy link
Member

@krassowski krassowski left a comment

Choose a reason for hiding this comment

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

Works great, thank you!

image

A spinner, or even better logs during live installation would be a great future enhancement.

@mbektas
Copy link
Member Author

mbektas commented Oct 25, 2023

A spinner, or even better logs during live installation would be a great future enhancement.

there is actually a subtle animation of the orange part of the logo, like heart beat. but probably too subtle to notice.

@mbektas mbektas merged commit bfd38e2 into master Oct 25, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants