【问题标题】:Transfer code from Colab to Jupyter Notebook将代码从 Colab 转移到 Jupyter Notebook
【发布时间】:2020-04-02 21:52:22
【问题描述】:

我尝试将一些代码从 Colab 传输到 Jupyter 笔记本。

Colab中的代码是:

# Use some functions from tensorflow_docs
!pip install -q git+https://github.com/tensorflow/docs

我得到错误:

ERROR: Could not detect requirement name for 'git+https://github.com/tensorflow/docs', please specify one with #egg=your_package_name"

如果它尝试不带“!”一开始:

 pip install -q git+https://github.com/tensorflow/docs

我得到一个错误:

File "<ipython-input-11-8fda094c7d6e>", line 5
pip install -q git+https://github.com/tensorflow/docs
          ^
SyntaxError: invalid syntax

有人可以帮帮我吗?

【问题讨论】:

  • 你用的是什么 Python 版本和什么 Jupyter 版本?
  • Python:3.7.5 // Jupyter Notebook:6.0.2 // Tensorflow:2.0.0
  • 你能用 pip3 试试吗?还有什么是 pip3 版本?
  • 如果我尝试使用 !pip3 install -q git+github.com/tensorflow/docs 我得到错误:Der Befehl "pip3" ist entweder falsch geschrieben oder konnte nicht gefunden werden。

标签: tensorflow jupyter-notebook google-colaboratory


【解决方案1】:

为了找到问题,我使用 Anaconda 提示创建了一个新环境,其中包含以下几行:

conda create -n regression=3.7
conda activate regression
pip install ipykernel
python -m ipykernel install --user --name regression --display-name "regression"
conda install tensorflow-gpu
pip install keras

比我激活环境“回归”并启动jupyter notebook

我将使用的代码来自这里:here

我又试了一次:

# Use seaborn for pairplot
!pip install -q seaborn

这行得通。但是当我执行时:

# Use some functions from tensorflow_docs
!pip install -q git+https://github.com/tensorflow/docs

我现在得到错误:

" 错误:错误 [WinError 2] Das System kann die angegebene Datei nicht finden while execution command git clone -q https://github.com/tensorflow/docs 'C:\Users\MASTER~1\AppData\Local\Temp\pip-req-build -n2je0pjv' 错误:找不到命令 'git' - 您是否在 PATH 中安装了 'git'? "

附上代码:

!pip3 install -q git+https://github.com/tensorflow/docs

我得到错误: "Der Befehl "pip3" ist entweder falsch geschrieben oder konnte nicht gefunden werden。”

【讨论】:

  • 如错误所说,您是否安装了 git?如果您尝试克隆回购协议,它会起作用吗?示例:!git clone github.com/GoogleCloudPlatform/ai-platform-samples.git
  • 不起作用:错误:“Der Befehl "git" ist entweder falsch geschrieben oder konnte nicht gefunden werden。"翻译:"命令 "git" 拼写错误或找不到。"如何安装 git?
  • 哦不,我正在通过 anaconda 搜索 git 安装:|我现在已经从这个站点git-scm.com/downloads 安装了它,并且在重新激活环境后它现在可以工作了!谢谢你,让我感到羞耻
【解决方案2】:

如果它尝试不带“!”一开始:

你需要!如果您尝试运行 bash 命令,则在开始时。否则,Jupyter 将尝试将其作为 python 运行,这将不起作用。

您的笔记本中还有其他代码吗?当我在最新版本的 Colab 和 python3 中尝试以下代码时,它对我有用:

!pip install git+https://github.com/tensorflow/docs     

制作:

Collecting git+https://github.com/tensorflow/docs
Cloning https://github.com/tensorflow/docs to /tmp/pip-req-build-mrqr1fk8
  Running command git clone -q https://github.com/tensorflow/docs /tmp/pip-req-build-mrqr1fk8
Requirement already satisfied (use --upgrade to upgrade): tensorflow-docs==0.0.0 from git+https://github.com/tensorflow/docs in /usr/local/lib/python3.6/dist-packages
Requirement already satisfied: astor in /usr/local/lib/python3.6/dist-packages (from tensorflow-docs==0.0.0) (0.8.0)
Requirement already satisfied: absl-py in /usr/local/lib/python3.6/dist-packages (from tensorflow-docs==0.0.0) (0.8.1)
Requirement already satisfied: six in /usr/local/lib/python3.6/dist-packages (from tensorflow-docs==0.0.0) (1.12.0)
Requirement already satisfied: pathlib2 in /usr/local/lib/python3.6/dist-packages (from tensorflow-docs==0.0.0) (2.3.5)
Requirement already satisfied: pyyaml in /usr/local/lib/python3.6/dist-packages (from tensorflow-docs==0.0.0) (3.13)
Building wheels for collected packages: tensorflow-docs
  Building wheel for tensorflow-docs (setup.py) ... done
  Created wheel for tensorflow-docs: filename=tensorflow_docs-0.0.0-cp36-none-any.whl size=80507 sha256=bb4cb3656cd0f5954db502b9812d3ddd49cd1186042a300813874cf1ad84fd3f
  Stored in directory: /tmp/pip-ephem-wheel-cache-yl2quvxi/wheels/eb/1b/35/fce87697be00d2fc63e0b4b395b0d9c7e391a10e98d9a0d97f
Successfully built tensorflow-docs

您是否尝试过重置运行时并再次运行代码?你的笔记本里还有别的吗?

【讨论】:

    【解决方案3】:

    没有 !不作为!用于在 Jupyter iPython 环境中调用 bash shell。

    我在 Google Cloud Platform Notebook(Jupyter Lab 版本 1.1.4)中尝试了使用 Python 版本(Python 3.5.3)的命令:

    !pip3 install -q git+https://github.com/tensorflow/docs --user
    

    并且工作得很好。

    !pip3 freeze | grep tensorflow
    
    tensorflow==1.15.0
    tensorflow-datasets==1.2.0
    tensorflow-docs==0.0.0
    tensorflow-estimator==1.15.1
    tensorflow-hub==0.6.0
    tensorflow-io==0.8.0
    tensorflow-metadata==0.15.0
    tensorflow-probability==0.8.0
    tensorflow-serving-api==1.14.0
    

    【讨论】:

      猜你喜欢
      • 2020-09-05
      • 2020-09-07
      • 2022-01-25
      • 1970-01-01
      • 1970-01-01
      • 2020-03-20
      • 1970-01-01
      • 1970-01-01
      • 2019-01-14
      相关资源
      最近更新 更多