简体   繁体   English

Pip 在 jupyter 笔记本中不再工作

[英]Pip doesn't work anymore in jupyter notebook

I used to be able to launch pip command from the jupyter notebook.我曾经能够从 jupyter notebook 启动 pip 命令。 But now even if I luanch even the basic ! pip -V但是现在即使我连基本的都吃不消了! pip -V ! pip -V I get: ! 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

The reason might be that I tried to install Python from Microsoft Store, which didn't had pip and that I downloaded pip following this tutorial原因可能是我尝试从 Microsoft Store 安装 Python,它没有 pip 并且我按照本教程下载了 pip

I tried to install it from sys:我尝试从 sys 安装它:

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

But got the following one:但是得到了以下一个:

---------------------------------------------------------------------------
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

From your comments and answers:从您的评论和回答中:

Install with conda in jupyter notebook在 jupyter notebook 中使用 conda 安装

I tried to install it (and a random package) with conda install pip but got almost the same error我尝试使用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

upgrade pip in Anaconda prompt在 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

But still had the error after shutting down the kernel, closing the jupyter window terminal.但是关闭kernel,关闭jupyter window终端后仍然有错误。

So you are using conda and Pip... why dont you try installing pip from Conda??所以你正在使用 conda 和 Pip ......你为什么不尝试从 Conda 安装 pip ?

Sorry for not comment instead but I have not enough reputation.很抱歉没有发表评论,但我没有足够的声誉。

conda install pip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM