jupyter / notebook

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

Failure to launch kernel if project directory has an empty file named "profile.py" #2306

Open syntaxaire opened 7 years ago

syntaxaire commented 7 years ago

As in title. Attempting to create a new notebook or open an existing one fails to launch the kernel. My profile.py is an empty, zero length file. Fresh install of Python 3.6 with only Jupyter installed.

Traceback (most recent call last):
  File "c:\users\user\appdata\local\programs\python\python36\lib\runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "c:\users\user\appdata\local\programs\python\python36\lib\runpy.py", line 142, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "c:\users\user\appdata\local\programs\python\python36\lib\runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "c:\users\user\appdata\local\programs\python\python36\lib\site-packages\ipykernel\__init__.py", line 2, in <module>
    from .connect import *
  File "c:\users\user\appdata\local\programs\python\python36\lib\site-packages\ipykernel\connect.py", line 13, in <module>
    from IPython.core.profiledir import ProfileDir
  File "c:\users\user\appdata\local\programs\python\python36\lib\site-packages\IPython\__init__.py", line 49, in <module>
    from .terminal.embed import embed
  File "c:\users\user\appdata\local\programs\python\python36\lib\site-packages\IPython\terminal\embed.py", line 19, in <module>
    from IPython.terminal.ipapp import load_default_config
  File "c:\users\user\appdata\local\programs\python\python36\lib\site-packages\IPython\terminal\ipapp.py", line 30, in <module>
    from IPython.core.magics import ScriptMagics
  File "c:\users\user\appdata\local\programs\python\python36\lib\site-packages\IPython\core\magics\__init__.py", line 21, in <module>
    from .execution import ExecutionMagics
  File "c:\users\user\appdata\local\programs\python\python36\lib\site-packages\IPython\core\magics\execution.py", line 22, in <module>
    import cProfile as profile
  File "c:\users\user\appdata\local\programs\python\python36\lib\cProfile.py", line 22, in <module>
    run.__doc__ = _pyprofile.run.__doc__
AttributeError: module 'profile' has no attribute 'run'
syntaxaire commented 7 years ago

This seems to have bitten someone else with a different filename in #2270.

takluyver commented 7 years ago

In general, you can't call your modules the same thing as modules that IPython relies on. In this case, you're clashing with the standard library profile module.

IPykernel 4.6, when it is released, should include a workaround that allows the kernel to start in that case (see ipython/ipykernel#209). But then you won't be able to import your module with import profile, so it's still not a good name.

kuanb commented 7 years ago

Has anyone encountered this? I am dealing with it right now, and getting a similar traceback:

root@ad9085cdd07d:/code# jupyter notebook
Traceback (most recent call last):
  File "/usr/local/bin/jupyter-notebook", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/site-packages/jupyter_core/application.py", line 266, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/traitlets/config/application.py", line 657, in launch_instance
    app.initialize(argv)
  File "<decorator-gen-7>", line 2, in initialize
  File "/usr/local/lib/python3.6/site-packages/traitlets/config/application.py", line 87, in catch_config_error
    return method(app, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/notebook/notebookapp.py", line 1368, in initialize
    self.init_webapp()
  File "/usr/local/lib/python3.6/site-packages/notebook/notebookapp.py", line 1161, in init_webapp
    self.jinja_environment_options
  File "/usr/local/lib/python3.6/site-packages/notebook/notebookapp.py", line 154, in __init__
    base_url, default_url, settings_overrides, jinja_env_options)
  File "/usr/local/lib/python3.6/site-packages/notebook/notebookapp.py", line 263, in init_settings
    nbextensions_path=jupyter_app.nbextensions_path,
  File "/usr/local/lib/python3.6/site-packages/notebook/notebookapp.py", line 874, in nbextensions_path
    from IPython.paths import get_ipython_dir
  File "/usr/local/lib/python3.6/site-packages/IPython/__init__.py", line 55, in <module>
    from .terminal.embed import embed
  File "/usr/local/lib/python3.6/site-packages/IPython/terminal/embed.py", line 17, in <module>
    from IPython.terminal.ipapp import load_default_config
  File "/usr/local/lib/python3.6/site-packages/IPython/terminal/ipapp.py", line 28, in <module>
    from IPython.core.magics import (
  File "/usr/local/lib/python3.6/site-packages/IPython/core/magics/__init__.py", line 21, in <module>
    from .execution import ExecutionMagics
  File "/usr/local/lib/python3.6/site-packages/IPython/core/magics/execution.py", line 23, in <module>
    import cProfile as profile
  File "/usr/local/lib/python3.6/cProfile.py", line 22, in <module>
    run.__doc__ = _pyprofile.run.__doc__
AttributeError: module 'profile' has no attribute 'run'
takluyver commented 7 years ago

Do you have the PYTHONPATH environment variable set? That issue shouldn't usually affect launching the notebook.

ThibTrip commented 5 years ago

Has anyone encountered this? I am dealing with it right now, and getting a similar traceback:

root@ad9085cdd07d:/code# jupyter notebook
Traceback (most recent call last):
  File "/usr/local/bin/jupyter-notebook", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/site-packages/jupyter_core/application.py", line 266, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/traitlets/config/application.py", line 657, in launch_instance
    app.initialize(argv)
  File "<decorator-gen-7>", line 2, in initialize
  File "/usr/local/lib/python3.6/site-packages/traitlets/config/application.py", line 87, in catch_config_error
    return method(app, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/notebook/notebookapp.py", line 1368, in initialize
    self.init_webapp()
  File "/usr/local/lib/python3.6/site-packages/notebook/notebookapp.py", line 1161, in init_webapp
    self.jinja_environment_options
  File "/usr/local/lib/python3.6/site-packages/notebook/notebookapp.py", line 154, in __init__
    base_url, default_url, settings_overrides, jinja_env_options)
  File "/usr/local/lib/python3.6/site-packages/notebook/notebookapp.py", line 263, in init_settings
    nbextensions_path=jupyter_app.nbextensions_path,
  File "/usr/local/lib/python3.6/site-packages/notebook/notebookapp.py", line 874, in nbextensions_path
    from IPython.paths import get_ipython_dir
  File "/usr/local/lib/python3.6/site-packages/IPython/__init__.py", line 55, in <module>
    from .terminal.embed import embed
  File "/usr/local/lib/python3.6/site-packages/IPython/terminal/embed.py", line 17, in <module>
    from IPython.terminal.ipapp import load_default_config
  File "/usr/local/lib/python3.6/site-packages/IPython/terminal/ipapp.py", line 28, in <module>
    from IPython.core.magics import (
  File "/usr/local/lib/python3.6/site-packages/IPython/core/magics/__init__.py", line 21, in <module>
    from .execution import ExecutionMagics
  File "/usr/local/lib/python3.6/site-packages/IPython/core/magics/execution.py", line 23, in <module>
    import cProfile as profile
  File "/usr/local/lib/python3.6/cProfile.py", line 22, in <module>
    run.__doc__ = _pyprofile.run.__doc__
AttributeError: module 'profile' has no attribute 'run'

Hi, I can confirm the problem still exists and it affects Jupyter Lab too. In my case I created a notebook called "profile.ipynb" and since I am using a post save hook a python file "profile.py" is created when the notebook is saved (via auto and manual save).

Desktop

Additional context

Command Line Output
Traceback (most recent call last):
  File "C:\Users\thib\AppData\Local\Continuum\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\thib\AppData\Local\Continuum\anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\thib\AppData\Local\Continuum\anaconda3\lib\site-packages\ipykernel_launcher.py", line 15, in 
    from ipykernel import kernelapp as app
  File "C:\Users\thib\AppData\Local\Continuum\anaconda3\lib\site-packages\ipykernel\__init__.py", line 2, in 
    from .connect import *
  File "C:\Users\thib\AppData\Local\Continuum\anaconda3\lib\site-packages\ipykernel\connect.py", line 13, in 
    from IPython.core.profiledir import ProfileDir
  File "C:\Users\thib\AppData\Local\Continuum\anaconda3\lib\site-packages\IPython\__init__.py", line 55, in 
    from .terminal.embed import embed
  File "C:\Users\thib\AppData\Local\Continuum\anaconda3\lib\site-packages\IPython\terminal\embed.py", line 17, in 
    from IPython.terminal.ipapp import load_default_config
  File "C:\Users\thib\AppData\Local\Continuum\anaconda3\lib\site-packages\IPython\terminal\ipapp.py", line 28, in 
    from IPython.core.magics import (
  File "C:\Users\thib\AppData\Local\Continuum\anaconda3\lib\site-packages\IPython\core\magics\__init__.py", line 21, in 
    from .execution import ExecutionMagics
  File "C:\Users\thib\AppData\Local\Continuum\anaconda3\lib\site-packages\IPython\core\magics\execution.py", line 24, in 
    import cProfile as profile
  File "C:\Users\thib\AppData\Local\Continuum\anaconda3\lib\cProfile.py", line 22, in 
    run.__doc__ = _pyprofile.run.__doc__
AttributeError: module 'profile' has no attribute 'run'
PATH
C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
C:\Windows\System32\WindowsPowerShell\v1.0\
C:\Windows\System32\OpenSSH\
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL
C:\Program Files\Intel\Intel(R) Management Engine Components\DAL
C:\Program Files\Git LFS
C:\Program Files\Git\cmd
C:\Program Files\PuTTY\
C:\Program Files (x86)\Microsoft SQL Server\80\Tools\Binn\
C:\Program Files\nodejs\
C:\Program Files\Amazon\AWSCLI\bin\
C:\Users\thib\.cargo\bin
C:\Users\thib\AppData\Local\Microsoft\WindowsApps
C:\Users\thib\AppData\Local\GitHubDesktop\bin
C:\Users\thib\AppData\Local\atom\bin
C:\Users\thib\AppData\Local\Continuum\anaconda3\
C:\Users\thib\AppData\Local\Continuum\anaconda3\Library\bin\
C:\Users\thib\AppData\Local\Continuum\anaconda3\Scripts\
C:\Users\thib\AppData\Local\Continuum\anaconda3\condabin\
C:\Users\thib\AppData\Roaming\npm