Transfer code from Colab to Jupyter Notebook - tensorflow

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?

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

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?

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

Related

How to get most recent version of Pandas in Google Colab?

I have successfully downloaded a version of Python 3.10 to Colab, and Colab says I have the most up to date version of pandas. However, whenever I import pandas, the version is 1.3.5, while I need it to be up to date.
I tried restarting the kernel, but this did not fix things. The code and its output are below, excepting the long list I get when I download the newest version of Python.
!wget https://github.com/korakot/kora/releases/download/v0.10/py310.sh
!bash ./py310.sh -b -f -p /usr/local
!python -m ipykernel install --name "py310" --user
!python --version
Python 3.10.6
!pip3 install pandas --upgrade --no-deps
Requirement already satisfied: pandas in /usr/local/lib/python3.10/site-packages (1.5.2)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
import pandas as pd
print(pd.__version__)
1.3.5
Thank you so much for your time.

Error intsalling tensorflow via pip install

WARNING: Failed to write executable - trying to use .deleteme logic
ERROR: Could not install packages due to an EnvironmentError: [WinError 2] The system cannot find the file specified: 'c:\python38\Scripts\chardetect.exe' -> 'c:\python38\Scripts\chardetect.exe.deleteme'
I was trying to install Tensorflow via command pip install tensorflow. and after downloading everything at the end found this error..can anyone tell me why this happened?
According to https://www.codegrepper.com/ you can use these two:
In Windows
python -m pip install -U pip --user
In Linux
pip install -U pip --user

Where to find the existing package installed in the google Colab

I want to check if some packages are installed in the Colab. What is specific folder for storing the installed packages (e.g., keras)?
You can use the pip tool to list installed Python packages and their locations on the system:
!pip list -v | grep [Kk]eras
# Keras 2.2.5 /usr/local/lib/python3.6/dist-packages pip
# Keras-Applications 1.0.8 /usr/local/lib/python3.6/dist-packages pip
# Keras-Preprocessing 1.1.0 /usr/local/lib/python3.6/dist-packages pip
# keras-vis 0.4.1 /usr/local/lib/python3.6/dist-packages pip
Note that in Colab and other Jupyter notebook frontends, the ! character is used to execute a shell command.
If you are not able to find the package, you might have probably downloaded the package instead of installing it.
Incorrect command:
!pip download transformers
Correct command:
!pip install transformers
Next, in order to find the package run the following command:
!pip show transformers

TensorFlow installation error: Operation not permitted .../_markerlib

Despite using sudo, the pip install command sometimes generates an error similar to the following:
...
Installing collected packages: setuptools, protobuf, wheel, numpy, tensorflow
Found existing installation: setuptools 1.1.6
Uninstalling setuptools-1.1.6:
Exception:
…
[Errno 1] Operation not permitted:
'/tmp/pip-a1DXRT-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib'
Try to install using --ignore-installed option:
sudo pip install --ignore-installed tensorflow
It should work.

Getting permission denied error while installing tensorflow and keras

After following the steps from my previously asked question Can I implement deep learning models in my laptop with intel hd graphics
I am getting a permission denied error while installing tensorflow
What can I do to install tensorflow and keras without getting this error?
pip3 is trying to access /usr/bin/ for which you need superuser rights. Try
sudo pip3 install --upgrade ...
It appears that TensorFlow depends on a newer version of the setuptools package than you have installed. As Maximilian points out, pip needs root access to upgrade setuptools and install TensorFlow and Keras in your machine's Python distribution. You can either use sudo as he suggests, or it may be safer to install TensorFlow into a Virtualenv. For example, to create a Virtualenv in the directory ~/tensorflow, execute the following commands:
$ sudo pip install virtualenv
$ virtualenv --system-site-packages ~/tensorflow
$ cd ~/tensorflow
$ source bin/activate
$ pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.0-cp27-none-linux_x86_64.whl