masterkey
masterkey

Reputation: 75

Transfer code from Colab to Jupyter Notebook

I try to transfer some code from Colab to Jupyter notebook.

The code in Colab is:

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

I get the Error:

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

Also if it try it without "!" in the beginning:

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

I get an Error:

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

Could someone please help me?

Upvotes: 3

Views: 2347

Answers (3)

masterkey
masterkey

Reputation: 75

To find the problem I made a new environment with Anaconda prompt with the following lines:

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

Than I activated the environment "regression" and started jupyter notebook

The code I will use is from here: here

I tried it again:

# Use seaborn for pairplot
!pip install -q seaborn

That works. But when I execute:

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

I get now the Error:

" ERROR: Error [WinError 2] Das System kann die angegebene Datei nicht finden while executing command git clone -q https://github.com/tensorflow/docs 'C:\Users\MASTER~1\AppData\Local\Temp\pip-req-build-n2je0pjv' ERROR: Cannot find command 'git' - do you have 'git' installed and in your PATH? "

With the code:

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

I get the error: "Der Befehl "pip3" ist entweder falsch geschrieben oder konnte nicht gefunden werden."

Upvotes: 0

ambitiousdonut
ambitiousdonut

Reputation: 394

Also if it try it without "!" in the beginning:

You need to ! in the beginning if you're trying to run a bash command. Otherwise, Jupyter will try to run it as python, which won't work.

Do you have any other code in your notebook? When I tried the code below in the most recent version of Colab and python3, it worked for me:

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

produced:

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

Have you tried resetting your runtime and running the code again? Do you have anything else in your notebook?

Upvotes: 0

gogasca
gogasca

Reputation: 10058

Makes sense that pip without the ! does not work as ! is used to invoke the bash shell within the Jupyter iPython environment.

I tried in a Google Cloud Platform Notebook (Jupyter Lab Version 1.1.4) the command using a Python version (Python 3.5.3):

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

and worked perfectly.

!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

Upvotes: 2

Related Questions