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

Change kernel default install location #25

Open
laszabine opened this issue Jan 13, 2023 · 12 comments
Open

Change kernel default install location #25

laszabine opened this issue Jan 13, 2023 · 12 comments

Comments

@laszabine
Copy link

I'm trying to install the kernel inside a venv by running jupyter pyscript install, as per the instructions in README.md. This is trying to install to /usr/local/share/jupyter, which I do not want. I see that the install_main method is capable of installing the kernel to a custom directory, only not upon first install.

Could you add a parser argument to be able to provide a custom directory? Or set a more user/venv based default?
Thank you!

@CorvetteCole
Copy link

I am also having this issue. Would love to keep things in a virtual environment

@CorvetteCole
Copy link

a good option here would probably be to read an environment variable to allow this to be changed, but really it should default to user dir imo. I have a modified version that successfully installed in my $HOME/.local/share/jupyter/kernels/pyscript and there are no problems as far as I can tell

@tangix
Copy link

tangix commented May 22, 2023

If you are running on macOS and hack the install script to work and install, remember to make a link to the install location in ~/Library/Jupyter/kernels/pyscript to get it listed:

$ jupyter kernelspec list
0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
Available kernels:
  python3     /opt/homebrew/Cellar/jupyterlab/4.0.0/libexec/lib/python3.11/site-packages/ipykernel/resources
  pyscript    /Users/msa/Library/Jupyter/kernels/pyscript

@sajennings79
Copy link

I think I'm having the same issue installing in macOS -- running jupyter pyscript install errors with PermissionError: [Errno 13] Permission denied: '/usr/local/share'

Could someone who got this working share how they hacked the install script? Thank you

@craigbarratt
Copy link
Owner

Have you tried creating a venv and installing and running it from that?

@sajennings79
Copy link

sajennings79 commented Jun 30, 2023 via email

@schniepp
Copy link

I may have a similar/related issue. I am running HA core on ubuntu 22.04. The python version on ubuntu is 3.10 and cannot be upgraded, since apparently, this would break the OS. However, the latest HA versions want python 3.11. Therefore, I had to install 3.11 in /srv/homeassistant, which is then used in the venv that HA is running in. HA is working, and I also got pyscript working.

However, when I activated the venv and executed the instructions to install hass-pyscript-jupyter from within there, it was not working. jupyter kernelspec list and jupyter pyscript info give me the correct answers (pyscript kernel shows up). From within the venv, I can fire up jupyter notebook, however, I only get python3 as a kernel option and not hass-pyscript-jupyter. Also, when I run jupyter console --kernel=pyscript I get the error messages below, which looks like /usr/bin/python3 is being used when it should really be using /srv/homeassistant/bin/python. For starters, it says that the pyscript kernelspec cannot be found...

Is this the same bug, or should I open a new one?

[ZMQTerminalIPythonApp] WARNING | Kernelspec name pyscript cannot be found!                                                                                          
[ZMQTerminalIPythonApp] ERROR | No such kernel named pyscript                                                                                                        
Traceback (most recent call last):                                                                                                                                   
  File "/usr/lib/python3/dist-packages/jupyter_client/manager.py", line 71, in wrapper                                                                               
    out = await method(self, *args, **kwargs)                                                                                                                        
  File "/usr/lib/python3/dist-packages/jupyter_client/manager.py", line 376, in _async_start_kernel                                                                  
    kernel_cmd, kw = await ensure_async(self.pre_start_kernel(**kw))                                                                                                 
  File "/usr/lib/python3/dist-packages/jupyter_client/utils.py", line 26, in wrapped                                                                                 
    raise e                                                                                                                                                          
  File "/usr/lib/python3/dist-packages/jupyter_client/utils.py", line 23, in wrapped                                                                                 
    return loop.run_until_complete(future)                                                                                                                           
  File "/usr/lib/python3/dist-packages/nest_asyncio.py", line 81, in run_until_complete                                                                              
    return f.result()                                                                                                                                                
  File "/usr/lib/python3.10/asyncio/futures.py", line 201, in result                                                                                                 
    raise self._exception.with_traceback(self._exception_tb)                                                                                                         
  File "/usr/lib/python3.10/asyncio/tasks.py", line 232, in __step                                                                                                   
    result = coro.send(None)                                                                                                                                         
  File "/usr/lib/python3/dist-packages/jupyter_client/manager.py", line 339, in _async_pre_start_kernel                                                              
    self.kernel_spec,                                                                                                                                                
  File "/usr/lib/python3/dist-packages/jupyter_client/manager.py", line 169, in kernel_spec                                                                          
    self._kernel_spec = self.kernel_spec_manager.get_kernel_spec(self.kernel_name)                                                                                   
  File "/usr/lib/python3/dist-packages/jupyter_client/kernelspec.py", line 292, in get_kernel_spec                                                                   
    raise NoSuchKernel(kernel_name)                                                                                                                                  
jupyter_client.kernelspec.NoSuchKernel: No such kernel named pyscript                                                                                                
Traceback (most recent call last):                                                                                                                                   
  File "/usr/bin/jupyter-console", line 33, in <module>                                                                                                              
    sys.exit(load_entry_point('jupyter-console==6.4.0', 'console_scripts', 'jupyter-console')())                                                                     
  File "/usr/lib/python3/dist-packages/jupyter_core/application.py", line 264, in launch_instance                                                                    
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)                                                                                               
  File "/usr/lib/python3/dist-packages/traitlets/config/application.py", line 845, in launch_instance                                                                
    app.initialize(argv)                                                                                                                                             
  File "/usr/lib/python3/dist-packages/traitlets/config/application.py", line 88, in inner                                                                           
    return method(app, *args, **kwargs)                                                                                                                              
  File "/usr/lib/python3/dist-packages/jupyter_console/app.py", line 136, in initialize                                                                              
    self.init_shell()                                                                                                                                                
  File "/usr/lib/python3/dist-packages/jupyter_console/app.py", line 103, in init_shell                                                                              
    JupyterConsoleApp.initialize(self)                                            
  File "/usr/lib/python3/dist-packages/jupyter_client/consoleapp.py", line 365, in initialize                                                                        
    self.init_kernel_manager()                                                    
  File "/usr/lib/python3/dist-packages/jupyter_client/consoleapp.py", line 319, in init_kernel_manager                                                               
    self.kernel_manager.start_kernel(**kwargs)                                    
  File "/usr/lib/python3/dist-packages/jupyter_client/utils.py", line 26, in wrapped                                                                                 
    raise e                                                                                                                                                          
  File "/usr/lib/python3/dist-packages/jupyter_client/utils.py", line 23, in wrapped                                                                                 
    return loop.run_until_complete(future)                                        
  File "/usr/lib/python3/dist-packages/nest_asyncio.py", line 81, in run_until_complete                                                                              
    return f.result()                                                                                                                                                
  File "/usr/lib/python3.10/asyncio/futures.py", line 201, in result                                                                                                 
    raise self._exception.with_traceback(self._exception_tb)                      
  File "/usr/lib/python3.10/asyncio/tasks.py", line 232, in __step                                                                                                   
    result = coro.send(None)                                                      
  File "/usr/lib/python3/dist-packages/jupyter_client/manager.py", line 79, in wrapper                                                                               
    raise e                                                                                                                                                          
  File "/usr/lib/python3/dist-packages/jupyter_client/manager.py", line 71, in wrapper                                                                               
    out = await method(self, *args, **kwargs)                                                                                                                        
  File "/usr/lib/python3/dist-packages/jupyter_client/manager.py", line 376, in _async_start_kernel                                                                  
    kernel_cmd, kw = await ensure_async(self.pre_start_kernel(**kw))                                                                                                 
  File "/usr/lib/python3/dist-packages/jupyter_client/utils.py", line 26, in wrapped                                                                                 
    raise e                                                                                                                                                          
  File "/usr/lib/python3/dist-packages/jupyter_client/utils.py", line 23, in wrapped                                                                                 
    return loop.run_until_complete(future)                                                                                                                           
  File "/usr/lib/python3/dist-packages/nest_asyncio.py", line 81, in run_until_complete                                                                              
    return f.result()                                                                                                                                                
  File "/usr/lib/python3.10/asyncio/futures.py", line 201, in result                                                                                                 
    raise self._exception.with_traceback(self._exception_tb)                                                                                                         
  File "/usr/lib/python3.10/asyncio/tasks.py", line 232, in __step                                                                                                   
    result = coro.send(None)                                                                                                                                         
  File "/usr/lib/python3/dist-packages/jupyter_client/manager.py", line 339, in _async_pre_start_kernel                                                              
    self.kernel_spec,                                                                                                                                                
  File "/usr/lib/python3/dist-packages/jupyter_client/manager.py", line 169, in kernel_spec                                                                          
    self._kernel_spec = self.kernel_spec_manager.get_kernel_spec(self.kernel_name)                                                                                   
  File "/usr/lib/python3/dist-packages/jupyter_client/kernelspec.py", line 292, in get_kernel_spec

@schniepp
Copy link

P.S.: where would I find the install script? How to hack it?

@schniepp
Copy link

I don't think my problem was related. I opened a separate issue here: #27 , and I actually found the solution.

@hannonq
Copy link

hannonq commented Oct 30, 2024

a good option here would probably be to read an environment variable to allow this to be changed, but really it should default to user dir imo. I have a modified version that successfully installed in my $HOME/.local/share/jupyter/kernels/pyscript and there are no problems as far as I can tell

Just for future references, this also worked for me. I had to change the install script here and set target_dir to this directory.

@xtex404
Copy link

xtex404 commented Nov 16, 2024

You don't need to change the script -- just install 'ipykernel' before you run 'jupyter pyscript install'. You'll need ipykernel anyway, or you'll get "no native python3 kernel available" errors

I have a "global" home venv (in ~/.local/home-python) with my zsh PATH prepended with ~/.local/home-python/bin .. and because it's in the path, I don't have to activate it.. it's a cheat so I don't have to create yet another venv for quick and dirty scripts, and so I don't accidentally mess with the homebrew install (since my account can write to it).. (and so homebrew doesn't ruin my day when it suddenly switches the 'system' python from python 3.12 to 3.13 )

in the venv, wherever it is, 'pip install ipykernel' ... THEN run 'jupyter pyscript install'. Because ipykernel gets installed in your venv's 'share' directory, pyscript's kernel ends up there too....

% jupyter pyscript install
PermissionError: [Errno 13] Permission denied: '/usr/local/share'

% pip install ipykernel
# lots of output... :)

% jupyter kernelspec list
Available kernels:
  python3    /Users/me/.local/home-python/share/jupyter/kernels/python3

% jupyter pyscript install
installed new pyscript kernel in /Users/me/.local/home-python/share/jupyter/kernels/pyscript
you will need to update the settings in /Users/me/.local/home-python/share/jupyter/kernels/pyscript/pyscript.conf

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

No branches or pull requests

9 participants