【问题标题】:Pip doesn't work anymore in jupyter notebookPip 在 jupyter notebook 中不再起作用
【发布时间】:2019-10-14 12:12:52
【问题描述】:

我曾经能够从 jupyter notebook 启动 pip 命令。但现在即使我连基本的! pip -V 也能得到:

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-17-29b4bf94a9cf> in <module>
----> 1 get_ipython().system(' pip -V')

C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py in system_piped(self, cmd)
   2450         # a non-None value would trigger :func:`sys.displayhook` calls.
   2451         # Instead, we store the exit_code in user_ns.
-> 2452         self.user_ns['_exit_code'] = system(self.var_expand(cmd, depth=1))
   2453 
   2454     def system_raw(self, cmd):

C:\ProgramData\Anaconda3\lib\site-packages\IPython\utils\_process_win32.py in system(cmd)
    129         if path is not None:
    130             cmd = '"pushd %s &&"%s' % (path, cmd)
--> 131         return process_handler(cmd, _system_body)
    132 
    133 def getoutput(cmd):

C:\ProgramData\Anaconda3\lib\site-packages\IPython\utils\_process_common.py in process_handler(cmd, callback, stderr)
     82                          stdout=subprocess.PIPE,
     83                          stderr=stderr,
---> 84                          close_fds=close_fds)
     85 
     86     try:

C:\ProgramData\Anaconda3\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
    773                                 c2pread, c2pwrite,
    774                                 errread, errwrite,
--> 775                                 restore_signals, start_new_session)
    776         except:
    777             # Cleanup if the child failed starting.

C:\ProgramData\Anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
   1176                                          env,
   1177                                          os.fspath(cwd) if cwd is not None else None,
-> 1178                                          startupinfo)
   1179             finally:
   1180                 # Child is launched. Close the parent's copy of those pipe

FileNotFoundError: [WinError 2] The system cannot find the file specified

Blockquote

原因可能是我尝试从没有 pip 的 Microsoft Store 安装 Python 并且我在 this tutorial 之后下载了 pip

我尝试从 sys 安装它:

import sys
!{sys.executable} -m pip install facebook_sdk]

但是得到了以下一个:

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-20-378e12e263ed> in <module>
      1 import sys
----> 2 get_ipython().system('{sys.executable} -m pip install facebook_sdk')
      3 

C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py in system_piped(self, cmd)
   2450         # a non-None value would trigger :func:`sys.displayhook` calls.
   2451         # Instead, we store the exit_code in user_ns.
-> 2452         self.user_ns['_exit_code'] = system(self.var_expand(cmd, depth=1))
   2453 
   2454     def system_raw(self, cmd):

C:\ProgramData\Anaconda3\lib\site-packages\IPython\utils\_process_win32.py in system(cmd)
    129         if path is not None:
    130             cmd = '"pushd %s &&"%s' % (path, cmd)
--> 131         return process_handler(cmd, _system_body)
    132 
    133 def getoutput(cmd):

C:\ProgramData\Anaconda3\lib\site-packages\IPython\utils\_process_common.py in process_handler(cmd, callback, stderr)
     82                          stdout=subprocess.PIPE,
     83                          stderr=stderr,
---> 84                          close_fds=close_fds)
     85 
     86     try:

C:\ProgramData\Anaconda3\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
    773                                 c2pread, c2pwrite,
    774                                 errread, errwrite,
--> 775                                 restore_signals, start_new_session)
    776         except:
    777             # Cleanup if the child failed starting.

C:\ProgramData\Anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
   1176                                          env,
   1177                                          os.fspath(cwd) if cwd is not None else None,
-> 1178                                          startupinfo)
   1179             finally:
   1180                 # Child is launched. Close the parent's copy of those pipe

FileNotFoundError: [WinError 2] The system cannot find the file specified

来自您的 cmets 和答案:

在 jupyter notebook 中使用 conda 安装

我尝试使用conda install pip 安装它(和一个随机包),但得到了几乎相同的错误

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-6-6460b4216065> in <module>
----> 1 get_ipython().run_line_magic('conda', 'install pip')

C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
   2311                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2312             with self.builtin_trap:
-> 2313                 result = fn(*args, **kwargs)
   2314             return result
   2315 

<C:\ProgramData\Anaconda3\lib\site-packages\decorator.py:decorator-gen-108> in conda(self, line)

C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\magic.py in <lambda>(f, *a, **k)
    185     # but it's overkill for just that one bit of state.
    186     def magic_deco(arg):
--> 187         call = lambda f, *a, **k: f(*a, **k)
    188 
    189         if callable(arg):

C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\magics\packaging.py in conda(self, line)
    101             extra_args.extend(["--prefix", sys.prefix])
    102 
--> 103         self.shell.system(' '.join([conda, command] + extra_args + args))
    104         print("\nNote: you may need to restart the kernel to use updated packages.")

C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py in system_piped(self, cmd)
   2450         # a non-None value would trigger :func:`sys.displayhook` calls.
   2451         # Instead, we store the exit_code in user_ns.
-> 2452         self.user_ns['_exit_code'] = system(self.var_expand(cmd, depth=1))
   2453 
   2454     def system_raw(self, cmd):

C:\ProgramData\Anaconda3\lib\site-packages\IPython\utils\_process_win32.py in system(cmd)
    129         if path is not None:
    130             cmd = '"pushd %s &&"%s' % (path, cmd)
--> 131         return process_handler(cmd, _system_body)
    132 
    133 def getoutput(cmd):

C:\ProgramData\Anaconda3\lib\site-packages\IPython\utils\_process_common.py in process_handler(cmd, callback, stderr)
     82                          stdout=subprocess.PIPE,
     83                          stderr=stderr,
---> 84                          close_fds=close_fds)
     85 
     86     try:

C:\ProgramData\Anaconda3\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
    773                                 c2pread, c2pwrite,
    774                                 errread, errwrite,
--> 775                                 restore_signals, start_new_session)
    776         except:
    777             # Cleanup if the child failed starting.

C:\ProgramData\Anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
   1176                                          env,
   1177                                          os.fspath(cwd) if cwd is not None else None,
-> 1178                                          startupinfo)
   1179             finally:
   1180                 # Child is launched. Close the parent's copy of those pipe

FileNotFoundError: [WinError 2] The system cannot find the file specified

在 Anaconda 提示中升级 pip

(base) C:\Users\antoi>python -m pip install --upgrade pip
Collecting pip
  Using cached https://files.pythonhosted.org/packages/30/db/9e38760b32e3e7f40cce46dd5fb107b8c73840df38f0046d8e6514e675a1/pip-19.2.3-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 19.1.1
    Uninstalling pip-19.1.1:
ERROR: Could not install packages due to an EnvironmentError: [WinError 5] Access is denied: 'c:\\programdata\\anaconda3\\lib\\site-packages\\pip\\_internal\\build_env.py'
Consider using the `--user` option or check the permissions.


(base) C:\Users\antoi>
(base) C:\Users\antoi>python -m pip install --upgrade pip --user
Collecting pip
  Using cached https://files.pythonhosted.org/packages/30/db/9e38760b32e3e7f40cce46dd5fb107b8c73840df38f0046d8e6514e675a1/pip-19.2.3-py2.py3-none-any.whl
Installing collected packages: pip
Successfully installed pip-19.2.3

但是关闭内核,关闭jupyter窗口终端后仍然有错误。

【问题讨论】:

  • 你尝试升级 pip 了吗?
  • @KavithaKarunakaran 刚刚做了,但仍然有这个错误
  • 这表明没有足够的文件权限来修改pip on upgrade using conda pip install。我想知道它是否与conda environment setup有关

标签: python python-3.x pip jupyter-notebook


【解决方案1】:

所以你正在使用 conda 和 Pip...你为什么不尝试从 Conda 安装 pip??

对不起,我没有发表评论,但我没有足够的声誉。

conda install pip

【讨论】:

    猜你喜欢
    • 2016-11-17
    • 1970-01-01
    • 2017-06-12
    • 1970-01-01
    • 1970-01-01
    • 2018-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多