【问题标题】:can't open jupyter notebook in new conda environment on windows无法在 Windows 的新 conda 环境中打开 jupyter notebook
【发布时间】:2019-03-04 23:16:29
【问题描述】:

编辑:这似乎是一个 conda-forge 问题。 conda install jupyter 工作正常。在 GitHub 上打开的问题:https://github.com/conda-forge/jupyter-feedstock/issues/6

长期 python Mac 用户。第一次使用 python windows 用户(windows 7 企业版)。

通过 Anaconda (https://repo.anaconda.com/archive/Anaconda3-5.2.0-Windows-x86_64.exe) 安装 python

Jupyter notebook 在基础环境中运行良好。

当我创建一个新环境时,我无法打开 jupyter notebook。

打开 Anaconda 提示:

conda create -n test_env2 python=3.6
conda activate test_env2
conda install -c conda-forge jupyter
jupyter notebook

当我打开 Ipython 笔记本时,它显示“内核错误”:

明显的错误是:

[E 18:53:32.420 NotebookApp] Failed to run command:
['C:/Users/131416/AppData/Local/Continuum/anaconda3/envs/test_env2/bin/python', '-m', 'ipykernel_launcher', '-f', 'C:\\Users\\131416\\AppData\\Roaming\\jupyter\\runtime\\kernel-99e95812-0a80-4772-94fc-e35563ce58e1.json']

  File "C:\Users\131416\AppData\Local\Continuum\anaconda3\envs\test_env2\lib\subprocess.py", 
line 997, in _execute_child
   startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

[E 18:53:32.498 NotebookApp] 500 POST /api/sessions (::1) 135.50ms referer=http://localhost:8888/notebooks/Untitled.ipynb?kernel_name=python3

也许这与它在基础环境中拾取jupyter.exe 以及在新环境中拾取jupyter.exe 有关:

https://github.com/jupyter/notebook/issues/2130 也有一些讨论,但解决方案并不明显。

完整的 Traceback 是(为布局道歉。从 cmd 复制):

(test_env2) C:\Users\131416>jupyter notebook [I 18:53:24.082 NotebookApp] 从本地目录提供笔记本:C:\Users\13 1416 [I 18:53:24.084 NotebookApp] Jupyter Notebook 运行于:[I 18:53:24.085 NotebookApp] http://localhost:8888/?token=2ecb94399a83d9dc1f8f11 6e0f28a46e297033c1fd796e23 [I 18:53:24.086 NotebookApp] 使用 Control-C 停止此服务器并关闭所有内核(两次跳过 确认)。 [C 18:53:24.089 NotebookApp]

Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
    http://localhost:8888/?token=2ecb94399a83d9dc1f8f116e0f28a46e297033c1fd7

96e23 [I 18:53:24.384 NotebookApp] 接受 来自 ::1 的一次性令牌认证连接 [W 18:53:31.615 NotebookApp] 404 GET /undefined (::1) 12.00ms referer=None [I 18:53:31.631 NotebookApp] 在 [E 18:53:32.420] 中创建新笔记本 NotebookApp] 无法运行命令: ['C:/Users/131416/AppData/Local/Continuum/anaconda3/envs/test_env2/bin/pytho n','-m','ipykernel_launcher','-f', 'C:\Users\131416\AppData\Roaming\jupy 三\运行时\内核-99e95812-0a80-4772-94fc-e35563ce58e1.json'] PATH='C:\Users\131416\AppData\Local\Continuum\anaconda3\envs\tes t_env2;C:\Users\131416\AppData\Local\Continuum\anaconda3\envs\test_env2\ \Library\mingw-w64\bin;C:\Users\131416\AppData\Local\Continuum\anaconda3 \envs\test_env2\Library\usr\bin;C:\Users\131416\AppData\Local\Continuu m\anaconda3\envs\test_env2\Library\bin;C:\Users\131416\AppData\Local\C ontinuum\anaconda3\envs\test_env2\Scripts;C:\Users\131416\AppData\Local\ \Continuum\anaconda3\envs\test_env2\bin;C:\Users\131416\AppData\Local\C ontinuum\anaconda3;C:\Users\131416\AppData\Local\Continuum\anaconda3\Lib rary\mingw-w64\bin;C:\Users\131416\AppData\Local\Continuum\anaconda3\Li brary\usr\bin;C:\Users\131416\AppData\Local\Continuum\anaconda3\Library \bin;C:\Users\131416\AppData\Local\Continuum\anaconda3\Scripts;C:\Users \131416\AppData\Local\Continuum\anaconda3\bin;c:\Program Files (x86)\ca\ \sc\CAWIN\;C:\ProgramData\Oracle\Java\javapath;C:\windows\system32;C:\w indows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1. 0\;C:\Program Files (x86)\Symantec\VIP Access Client\;C:\Program 文件 (x8 6)\IBM\Client Access\Emulator;C:\Program Files (x86)\IBM\Client Access\Shared;C:\Program Files (x86)\IBM\Client Access\;C:\Program Files (x86)\WebE x\生产力工具;c:\程序文件 (x86)\CA\SC\Csam\SockAdapter\bin;c:\Program Files (x86)\CA\SC\Csam\SockAdapter\bin64;c:\Program Files (x86)\ \ca\sc\CBB\;c:\Program 文件 (x86)\ca\DSM\bin;c:\PROGRA~2\ca\sc\CAM\bin;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel \WirelessCommon\;C:\Program Files\Microsoft VS Code\bin' 与 kwargs: {'stdin':-1,'stdout':无,'stderr':无,'cwd':'C:\Users\131416'}

[E 18:53:32.441 NotebookApp] 未捕获的异常 POST /api/sessions (::1) HTTPServerRequest(protocol='http', host='localhost:8888', method='POST', uri ='/api/sessions', 版本='HTTP/1.1', remote_ip='::1') 回溯(最近一次通话最后): 文件“C:\Users\131416\AppData\Local\Continuum\anaconda3\envs\test_env2\lib \site-packages\tornado\web.py",第 1592 行,在 _execute 中 结果 = 产出结果 文件“C:\Users\131416\AppData\Local\Continuum\anaconda3\envs\test_env2\lib \site-packages\tornado\gen.py",第 1133 行,运行中 价值 = 未来。结果() 文件“C:\Users\131416\AppData\Local\Continuum\anaconda3\envs\test_env2\lib \site-packages\tornado\gen.py",第 1141 行,正在运行 产生 = self.gen.throw(*exc_info) 文件“C:\Users\131416\AppData\Local\Continuum\anaconda3\envs\test_env2\lib \site-packages\notebook\services\sessions\handlers.py",第 73 行,在 邮政 类型=mtype)) 文件“C:\Users\131416\AppData\Local\Continuum\anaconda3\envs\test_env2\lib \site-packages\tornado\gen.py",第 1133 行,运行中 价值 = 未来。结果() 文件“C:\Users\131416\AppData\Local\Continuum\anaconda3\envs\test_env2\lib \site-packages\tornado\gen.py",第 1141 行,正在运行 产生 = self.gen.throw(*exc_info) 文件“C:\Users\131416\AppData\Local\Continuum\anaconda3\envs\test_env2\lib \site-packages\notebook\services\sessions\sessionmanager.py",第 79 行, 在创建 _会议 kernel_id = yield self.start_kernel_for_session(session_id, path, name, type, kernel_name) 文件“C:\Users\131416\AppData\Local\Continuum\anaconda3\envs\test_env2\lib \site-packages\tornado\gen.py",第 1133 行,运行中 价值 = 未来。结果() 文件“C:\Users\131416\AppData\Local\Continuum\anaconda3\envs\test_env2\lib \site-packages\tornado\gen.py",第 1141 行,正在运行 产生 = self.gen.throw(*exc_info) 文件“C:\Users\131416\AppData\Local\Continuum\anaconda3\envs\test_env2\lib \site-packages\notebook\services\sessions\sessionmanager.py",第 92 行, 在 start_kernel_for_session self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name) 文件“C:\Users\131416\AppData\Local\Continuum\anaconda3\envs\test_env2\lib \site-packages\tornado\gen.py",第 1133 行,运行中 价值 = 未来。结果() 文件“C:\Users\131416\AppData\Local\Continuum\anaconda3\envs\test_env2\lib \site-packages\tornado\gen.py",第 326 行,在包装中 产生 = 下一个(结果) 文件“C:\Users\131416\AppData\Local\Continuum\anaconda3\envs\test_env2\lib \site-packages\notebook\services\kernels\kernelmanager.py”,第 160 行, 在 start_kernel 中 super(MappingKernelManager, self).start_kernel(**kwargs) 文件“C:\Users\131416\AppData\Local\Continuum\anaconda3\envs\test_env2\lib \site-packages\jupyter_client\multikernelmanager.py",第 110 行,在 启动内核 km.start_kernel(**kwargs) 文件“C:\Users\131416\AppData\Local\Continuum\anaconda3\envs\test_env2\lib \site-packages\jupyter_client\manager.py",第 259 行,在 start_kernel 中 **千瓦) 文件“C:\Users\131416\AppData\Local\Continuum\anaconda3\envs\test_env2\lib \site-packages\jupyter_client\manager.py",第 204 行,在 _launch_kernel 中 返回launch_kernel(kernel_cmd, **kw) 文件“C:\Users\131416\AppData\Local\Continuum\anaconda3\envs\test_env2\lib \site-packages\jupyter_client\launcher.py",第 128 行,在 launch_kernel proc = Popen(cmd, **kwargs) 文件“C:\Users\131416\AppData\Local\Continuum\anaconda3\envs\test_env2\lib \subprocess.py",第 709 行,在 init 中 恢复信号,开始新会话) 文件“C:\Users\131416\AppData\Local\Continuum\anaconda3\envs\test_env2\lib \subprocess.py”,第 997 行,在 _execute_child 中 启动信息) FileNotFoundError: [WinError 2] 系统找不到指定的文件 [W 18:53:32.480 NotebookApp] 未处理错误 [E 18:53:32.482 笔记本应用程序] { "接受": "application/json, text/javascript, /; q=0.01", “内容类型”:“应用程序/json”, "X-Xsrftoken": "2|d69ec7c3|9a70043f110f803ee6ab3273dd14309a|1538153699", "X-Requested-With": "XMLHttpRequest", "推荐人": "http://localhost:8888/notebooks/Untitled.ipynb?kernel_name=python3", "Accept-Language": "en-US", “接受编码”:“gzip,放气”, "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) 就像 Gecko", “主机”:“本地主机:8888”, “内容长度”:“91”, “连接”:“保持活动”, “缓存控制”:“无缓存”, "Cookie": "用户名-localhost-8888=\"2|1:0|10:1538175204|23:用户名-本地 主机 8888|44:Y2MwOTgzODhmZDZhNGE4NzhmM2Q2NWJjMDI2MjVjZjc=|a3c49f08f13669a523498b 9125cf42ce7eaab53181c1441544fcf533a94545da\"; _xsrf=2|d69ec7c3|9a70043f110f803ee 6ab3273dd14309a|1538153699;用户名-localhost-8889=\"2|1:0|10:1538162170|23:使用 rname-localhost-8889|44:NWQzZWQwZDY3ZmMzNDAzM2I5NDI4ZWI5OTA5NTkwZDc=|d515096d015 d24b1e06638fa64fc2c7b145a17c411203fd4141733f0a7815b9a\"; 用户名-localhost-8890 =\"2|1:0|10:1538162261|23:用户名-localhost-8890|44:YTU3NmY5MDczNzNmNGNjMTg1MzU yYjkyODU3ZDE5Y2I=|342bc9d819999a050780d4dbef1f9ade1e69fe3f52914132a9b897a0f3023a f2\"" } [E 18:53:32.498 NotebookApp] 500 POST /api/sessions (::1) 135.50ms referer=http://localhost:8888/notebooks/Untitled.ipynb?kernel_name=python3 [I 18:55:32.687 NotebookApp] 将文件保存在 /Untitled.ipynb

【问题讨论】:

    标签: python windows anaconda jupyter-notebook


    【解决方案1】:

    激活环境后,请安装ipykernel

    conda install ipykernel
    

    然后运行

    jupyter notebook
    

    【讨论】:

    • 感谢您的反馈。这似乎是一个 conda-forge 问题,而不是一个 conda 问题(问题已编辑)
    【解决方案2】:
    conda activate new_env_name
    

    在 MacOS 下激活

    source activate new_ene_name
    

    Windows 下

    【讨论】:

      【解决方案3】:

      对于 Windows 7 不能说,但对于 Windows 10,启动命令提示符,导航到选择的目录,然后激活您的环境,例如:

      activate my_env
      

      从这里启动你的笔记本:

      jupyter notebook
      

      注意,我无法从 powershell 执行此操作,因此我使用命令提示符。

      或者,在 windows 10 中,可以使用原生 linux 探索启动终端,可通过 windows 商店获得。

      【讨论】:

        【解决方案4】:

        不确定这是否对您有很大帮助,但如果您使用 Docker,您可以执行以下操作:

        1. 创建包含以下内容的 Dockerfile
        FROM jupyter/datascience-notebook
        
        RUN pip install -U pip
        
        ENV JUPYTER_ENABLE_LAB=yes
        
        COPY --chown=${NB_UID}:${NB_GID} . /home/vishesh/work
        WORKDIR /home/vishesh/work
        
        CMD ["jupyter", "lab", "--ip=0.0.0.0", "--port=8888", "--no-browser", "--notebook-dir=/home/vishesh/work", "--allow-root"]
        
        1. 创建 docker-compose.yml
        version: '3.7'
        
        services:
          jupyterlab:
            build:
              context: .
              dockerfile: Dockerfile
            ports:
              - "8888:8888"
            volumes:
              - ./notebooks:/home/vishesh/work
         
        
        1. 这两个文件应该在同一个文件夹中
        2. 在当前目录下依次打开PowerShell及以下命令 docker-compose build docker-compose up
        3. 一旦所有服务开始出现在 PowerShell 窗口中运行。 转到您的浏览器并打开 http://localhost:8888

        这只是为了证明直接使用虚拟化选项而不是自己安装所有东西是多么容易。

        【讨论】:

          【解决方案5】:

          激活新环境,然后安装jupyter

          conda install ipykernel
          pip3 install jupyter
          

          然后使用 conda 和 pip 安装所需的库以处理您的项目

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2023-03-16
            • 1970-01-01
            • 2020-04-03
            • 2017-01-28
            • 2019-06-06
            相关资源
            最近更新 更多