2

What I Want is to have complete synchronization between MACOS system python and Jupyter notebook. Examples:

  1. if I install a package with system python it should be usable even with Jupyter notebook and viceversa
  2. If I specify a Custom package path in .zshrc, it should be possible to directly import those packages even in Jupyter. THIS is not happening and I am looking for a solution.

DETAILS: OS version: Mac OS Big Sur 11.2.3 pyenv version: 1.2.24 python version installed with pyenv: system (MacOS default python2) 3.7.8 3.9.0

I installed pyenv (1.2.24), virtualenv (20.4.3), and pyenv-virtualenv (1.1.5), installed python versions 3.7.8 and 3.9.0 and set 3.9.0 as global through pyenv (pyenv global 3.9.0)

Then I installed Jupiter notebook through pip (pip install Jupiter notebook).

Last, I created a custom package and add its path in the .zshrc file with: export PYTHONPATH=/<my_path>/:$PYTHONPATH

Now: THIS PATH APPEARS correctly when I type: import sys sys.path in system python

THIS PATH DOES NOT APPEAR when I type the same in Jupyter notebook

The same happens when I install a package with pip system python and it is not usable in Jupiter notebook

How can I synchronize system python and Jupyter notebook in MacOS?

thanks

Alex
  • 21
  • 2
  • Does this answer your question? [Jupyter notebook, wrong sys.path and sys.executable](https://stackoverflow.com/questions/46634660/jupyter-notebook-wrong-sys-path-and-sys-executable) – asdf101 Apr 22 '21 at 20:21
  • Not completely. In my opinion, jupyter notebook uses a different python version than system python. Indeed, when I type "jupyter kernel list" I obtain : Users/alesss78/.pyenv/versions/3.9.0/share/jupyter/kernels/python3 However, system python version is (pyenv which python3): /Users/alesss78/.pyenv/versions/3.9.0/bin/python3 So I need to know how to set the second python3 path for the Jupiter notebook – Alex Apr 22 '21 at 20:42
  • in that case maybe https://stackoverflow.com/a/65351485/12337195 this one can help, otherwise I wouldn't know since I don't run macos – asdf101 Apr 22 '21 at 20:52
  • @asdf101 I really need to thank you. I still have to try the procedures reported in your last comment, but it seems it could really work!. Besides, I want to thank you for your kind interest and helpful comments! – Alex Apr 22 '21 at 21:34
  • Happy to help, glad you got to have a positive first experience on SO. If the linked answer works you can help people who might have this problem in the future by answering your own question with the answer but rewritten for your environment (you don't seem to be using Anaconda), with proper credit to the author of course. Maybe format the question a bit nicer with markdown so it is easier to read – asdf101 Apr 22 '21 at 22:37
  • 1
    For seek of completion. In order to change Jupyter notebook kernel, one can directly edit the JSON file (as suggested above). However, I was not able to edit JSON files (didn't know how to do in bash). So I used a different approach: I simply installed jupyter kernel within my python3 environment as following: -m ipykernel install. It worked, now jupyter and system python share the same sys.path and (I suspect, didn't check yet) installing a package through pip in bash mirrors the packages available in jupyter environment. – Alex Apr 23 '21 at 10:20
  • Json files should be editable with any text editor – asdf101 Apr 23 '21 at 10:30

0 Answers0