jupyter / notebook

Jupyter Interactive Notebook
https://jupyter-notebook.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
11.59k stars 4.86k forks source link

[Help wanted] Unable to launch Jupyter Notebook from Terminal #3179

Open TheFloatingString opened 6 years ago

TheFloatingString commented 6 years ago

When I type jupyter notebook in the Terminal prompt, Jupyter would launch without a problem.

However, now, I get the following error:

100955A:~ cliang$ jupyter notebook
Fatal Python error: Py_Initialize: unable to load the file system codec
ImportError: No module named 'encodings'

Current thread 0x00007fff71eec300 (most recent call first):
Abort trap: 6

I tried updating Anaconda and Python to their latest versions (Anaconda 4.3.30 and Python 3.6.2), but the error still persists.

However, when I launch Jupyter Notebook from the Anaconda Navigator, 100955A:~ cliang$ /Users/cliang/anaconda/envs/tensorflow/bin/jupyter_mac.command ; exit; is displayed and the notebook is launched.

What might be the cause of this problem? The only change I have made to my computer (OSX Yosemite) is installing XQuartz X11 beforehand, yet I can't see the link between the installation and a missing 'encodings' module.

akalinovskiy commented 6 years ago

Looks like i've faced with a related issue with the latest version of Anaconda3. My python works fine but jupyter doesn't. It crashes when I try to launch a jupyter notebook.

jupyter error:

[I 10:45:12.736 NotebookApp] Kernel started: cf534302-a4b9-4a25-be29-01523ad7ed7f
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00007fff903e2340 (most recent call first):

System info: mac os high sierra 10.13.2

$ which jupyter
~/anaconda3/bin/jupyter
$ conda info -a

     active environment : None
       user config file : /Users/artem/.condarc
 populated config files : /Users/artem/.condarc
          conda version : 4.4.7
    conda-build version : 3.0.27
         python version : 3.6.3.final.0
       base environment : /Users/artem/anaconda3  (writable)
           channel URLs : https://repo.continuum.io/pkgs/main/osx-64
                          https://repo.continuum.io/pkgs/main/noarch
                          https://repo.continuum.io/pkgs/free/osx-64
                          https://repo.continuum.io/pkgs/free/noarch
                          https://repo.continuum.io/pkgs/r/osx-64
                          https://repo.continuum.io/pkgs/r/noarch
                          https://repo.continuum.io/pkgs/pro/osx-64
                          https://repo.continuum.io/pkgs/pro/noarch
          package cache : /Users/artem/anaconda3/pkgs
                          /Users/artem/.conda/pkgs
       envs directories : /Users/artem/anaconda3/envs
                          /Users/artem/.conda/envs
               platform : osx-64
             user-agent : conda/4.4.7 requests/2.18.4 CPython/3.6.3 Darwin/17.3.0 OSX/10.13.2
                UID:GID : 501:20
             netrc file : None
           offline mode : False

# conda environments:
#
base                  *  /Users/artem/anaconda3

sys.version: 3.6.3 |Anaconda custom (64-bit)| (defaul...
sys.prefix: /Users/artem/anaconda3
sys.executable: /Users/artem/anaconda3/bin/python
conda location: /Users/artem/anaconda3/lib/python3.6/site-packages/conda
conda-build: /Users/artem/anaconda3/bin/conda-build
conda-convert: /Users/artem/anaconda3/bin/conda-convert
conda-develop: /Users/artem/anaconda3/bin/conda-develop
conda-env: /Users/artem/anaconda3/bin/conda-env
conda-index: /Users/artem/anaconda3/bin/conda-index
conda-inspect: /Users/artem/anaconda3/bin/conda-inspect
conda-metapackage: /Users/artem/anaconda3/bin/conda-metapackage
conda-render: /Users/artem/anaconda3/bin/conda-render
conda-server: /Users/artem/anaconda3/bin/conda-server
conda-skeleton: /Users/artem/anaconda3/bin/conda-skeleton
conda-verify: /Users/artem/anaconda3/bin/conda-verify
user site dirs: 

CIO_TEST: <not set>
CONDA_ROOT: /Users/artem/anaconda3
PATH: /Users/artem/anaconda3/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/Users/artem/lib/google-cloud-sdk/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin:/Users/artem/scripts:/Users/artem/bin:/usr/local/apache-maven/apache-maven-3.2.1/bin:/Users/artem/lib/jruby/jruby-9.1.5.0/bin:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home:/usr/local/bin:
REQUESTS_CA_BUNDLE: <not set>
SSL_CERT_FILE: <not set>

License directories:
    /Users/artem/.continuum
    /Users/artem/Library/Application Support/Anaconda
    /Users/artem/anaconda3/licenses
License files (license*.txt):
Package/feature end dates:

env variables:

$ printenv 
TERM_PROGRAM=Apple_Terminal
M2=/usr/local/apache-maven/apache-maven-3.2.1/bin
TERM=xterm-256color
SHELL=/bin/bash
CLICOLOR=1
TMPDIR=/var/folders/xs/xdshh8td7tv8hlghl7skdtcr0000gn/T/
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.MSw7G8Z0rH/Render
TERM_PROGRAM_VERSION=400
TERM_SESSION_ID=F70EC771-D1E4-4179-AA3C-269664843ECA
JRUBY_BIN=/Users/artem/lib/jruby/jruby-9.1.5.0/bin
USER=artem
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.FsVSlqV1xX/Listeners
MAVEN_OPTS=-Xms256m -Xmx512m
LSCOLORS=GxFxCxDxBxegedabagaced
USER_SCRIPTS=/Users/artem/scripts
PATH=/Users/artem/anaconda3/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/Users/artem/lib/google-cloud-sdk/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin:/Users/artem/scripts:/Users/artem/bin:/usr/local/apache-maven/apache-maven-3.2.1/bin:/Users/artem/lib/jruby/jruby-9.1.5.0/bin:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home:/usr/local/bin:
ACTIVATOR_HOME=/Users/artem/lib/play/activator-1.3.12-minimal
PWD=/Users/artem/workspace/ramax/askar
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home
LANG=ru_RU.UTF-8
XPC_FLAGS=0x0
SBT_OPTS=-XX:+CMSClassUnloadingEnabled -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/Users/artem
XPC_SERVICE_NAME=0
M2_HOME=/usr/local/apache-maven/apache-maven-3.2.1
HOME=/Users/artem
SHLVL=1
LOGNAME=artem
LOCAL_BIN=/usr/local/bin
DISPLAY=/private/tmp/com.apple.launchd.qioy3SUlM3/org.macosforge.xquartz:0
SECURITYSESSIONID=186a7
USER_BIN=/Users/artem/bin
ACTIVATOR_BIN=/Users/artem/lib/play/activator-1.3.12-minimal/bin
_=/usr/bin/printenv
takluyver commented 6 years ago

What does jupyter kernelspec list show you?

akalinovskiy commented 6 years ago

Thanks for the fast reply.

$ jupyter kernelspec list
Available kernels:
  python3    ~/Library/Jupyter/kernels/python3

$ ls ~/Library/Jupyter/kernels/python3/
kernel.json    logo-32x32.png logo-64x64.png

$ cat ~/Library/Jupyter/kernels/python3/kernel.json 
{
 "argv": [
  "/Users/artem/tensorflow/bin/python3",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "Python 3",
 "language": "python"
}

$ which python
~/anaconda3/bin/python

So, I understand that jupyter uses wrong python kernel, how to fix it?

takluyver commented 6 years ago

The simplest option is just to delete that directory (~/Library/Jupyter/kernels/python3). If it doesn't find it, it should fall back to a default python3 kernel in the same environment that the notebook server is running.

Otherwise, you can modify that JSON file to point to the Python you want. Or use the nb_conda_kernels extension to have kernels based on available conda environments.

akalinovskiy commented 6 years ago

Wow!!! Thanks a lot, you save my day!