How to change the pytorch version in Google colab - python

I need to change the pytorch version in google colab,so i install anaconda
%%bash
MINICONDA_INSTALLER_SCRIPT=Miniconda3-4.5.4-Linux-x86_64.sh
MINICONDA_PREFIX=/usr/local
wget https://repo.continuum.io/miniconda/$MINICONDA_INSTALLER_SCRIPT
chmod +x $MINICONDA_INSTALLER_SCRIPT
./$MINICONDA_INSTALLER_SCRIPT -b -f -p $MINICONDA_PREFIX
import sys
_ = (sys.path
.append("/usr/local/lib/python3.6/site-packages"))
and then
!conda install pytorch==1.0.0 torchvision==0.2.1 cuda100 -c pytorch --yes
but when i
import torch
torch.__version__
it's 1.9+cuda120
what's more, when i trying to
pip uninstall torch
colab told me that do you want to uninstall pytorch-1.0.0
how does it happen?

First, you have to run
!pip uninstall torch -y
The -y is for skipping the prompt request. This will uninstall torch, it will take more or less 5 minutes.
Then, you have to
!pip install torch==1.0.0
And finally
import torch
torch.__version__
# '1.0.0'

Related

Is there a torchvision 0.13.0 version available for ubuntu 18.04?

I have used prior versions of torchvision in my docker images in the past however now I am trying to install torchvision version 0.13.0 onto the image (OS = ubuntu 18.04) however anytime my requirements.txt file hits the line
torchvision==0.13.0
I get this error
Could not find a version that satisfies the requirement torchvision==0.13.0
I installed and used the same version on google colabs so I know the it is available, I just need a way to get it onto ubuntu via docker.
I also tried installing the same version directly on a ubuntu 18.04 VM (same error) so I think it is an issue with ubuntu.
I have tried
adding line pip install torchvision==0.13.0 to requirements.txt
Solved by installing torchvision via "RUN" command in dockerfile.
Adding the following lines in the dockerfile fixed the issue:
RUN apt-get update && apt-get install -y build-essential && apt-get install -y wget && apt-get clean
# Install miniconda
ENV CONDA_DIR /opt/conda
RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh && /bin/bash ~/miniconda.sh -b -p /opt/conda
# Put conda in path so we can use conda activate
ENV PATH=$CONDA_DIR/bin:$PATH
# Install torchvision
RUN conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch

Error when importing cv2 on anaconda prompt but it is working on jupyter notebook

I am importing libraries that I installed using pip install to Jupyter Notebook using the anaconda distribution, which is working. Next, I am trying to import the same libraries in the anaconda command prompt and running it. I am getting this error message:
ModuleNotFoundError: No module named 'cv2'
try these things:
First check if you are able to see your library by this command:
$ pip list or conda list
if not available install this module:
$ pip install opencv-python or conda install opencv-python
But before that, try to check numpy module is available or not. If numpy is not available, then install this first.
$ pip install numpy
If all of them exist then, Uninstall opencv-python and numpy first and upgrade your pip using the below command.
$ pip install --upgrade pip
Two options to install cv2 with the latest conda & python3:
Open the Anaconda Prompt and switch to your environment:
$ conda activate myenv
Then install opencv from the menpo channel:
$ conda install -c menpo opencv
Open the Anaconda Prompt with admin permission and make sure you're in the base environment:
$ conda activate base
Then install opencv from the menpo channel:
$ conda install -c menpo opencv
Reconnect your notebook to the kernel to import cv2.

Python Name Error ('XLMProphetNetTokenizer' is not defined)

I'm working on a cheminformatics project that requires quite a few packages to complete. I'm working in Google Colab.
TLDR
Google Colab throws error NameError: name 'XLMProphetNetTokenizer' is not defined even though I explicitly load the relevant package with !pip install transformers.
Long Explanation
To complete my project, I require packages such as RDKit, Moleculekit from Acellera, and the NLP tool allennlp. Google Colab seemed to have issues loading the cheminformatics package RDKit so I had to install using conda. I used !pip install for the rest of the packages. Code as follows:
# Installing RDKit
!wget -c https://repo.continuum.io/miniconda/Miniconda3-py37_4.8.3-Linux-x86_64.sh
!chmod +x Miniconda3-py37_4.8.3-Linux-x86_64.sh
!time bash ./Miniconda3-py37_4.8.3-Linux-x86_64.sh -b -f -p /usr/local
!time conda install -q -y -c conda-forge rdkit
import sys
sys.path.append('/usr/local/lib/python3.7/site-packages/')
!apt-get install python-rdkit librdkit1 rdkit-data -qq
# Installing ProphetNet Packages (Needed for ElmoEmbedder)
!pip install transformers
# Installing Moleculekit
!pip install moleculekit
# Installing AllenNLP
!pip install allennlp
However, when I call from allennlp.commands.elmo import ElmoEmbedder, Google Colab throws the following error: NameError: name 'XLMProphetNetTokenizer' is not defined
Looking on the following link, https://huggingface.co/transformers/master/model_doc/xlmprophetnet.html, it seems that I should be able to load the relavent XLMProphetNetTokenizer by using !pip install transformers. I'm not sure why it still throws the error. Regardless, would appreciate any help.

Installing RDKit in Google Colab

I cannot figure out how to fix the following issue. Up until today I was using the following code snippet for installing RDKit in Google Colab:
!wget -c https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
!chmod +x Miniconda3-latest-Linux-x86_64.sh
!time bash ./Miniconda3-latest-Linux-x86_64.sh -b -f -p /usr/local
!time conda install -q -y -c conda-forge rdkit
import sys
sys.path.append('/usr/local/lib/python3.7/site-packages/')
However, today I started to get the following error:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-d24c24e2d1f9> in <module>()
----> 1 from rdkit import Chem
2 import networkx as nx
ModuleNotFoundError: No module named 'rdkit'
I've tried using the full Anaconda distribution instead of Miniconda, as well as changing the python version to 3.6 and 3.8 but nothing seems to work.
I created a Python package to simplify the setup. You can find it here.
It will install Miniconda (or any other flavour) and patch a couple things that make Colab tricky.
Use it like this (first cell in your notebook):
!pip install -q condacolab
import condacolab
condacolab.install()
The kernel will restart and then you will be able to run conda or mamba with the !shell syntax:
!mamba install -c conda-forge rdkit
Check the repository for more details!
I think you need to specify python 3.7 when you install Miniconda (the current rdkit build supports python 3.7), the latest Miniconda version is py3.8:
!wget -c https://repo.continuum.io/miniconda/Miniconda3-py37_4.8.3-Linux-x86_64.sh
!chmod +x Miniconda3-py37_4.8.3-Linux-x86_64.sh
!time bash ./Miniconda3-py37_4.8.3-Linux-x86_64.sh -b -f -p /usr/local
!time conda install -q -y -c conda-forge rdkit
import sys
sys.path.append('/usr/local/lib/python3.7/site-packages/')
https://colab.research.google.com/drive/1MAZyv3O4-TrI8c1MD4JVmwExDquaprRT?usp=sharing
If you want to avoid installing Conda, you can just extract the anaconda package
# version 2018 is quite easy
# download & extract
url = 'https://anaconda.org/rdkit/rdkit/2018.09.1.0/download/linux-64/rdkit-2018.09.1.0-py36h71b666b_1.tar.bz2'
!curl -L $url | tar xj lib
# move to python packages directory
!mv lib/python3.6/site-packages/rdkit /usr/local/lib/python3.6/dist-packages/
x86 = '/usr/lib/x86_64-linux-gnu'
!mv lib/*.so.* $x86/
# rdkit need libboost_python3.so.1.65.1
!ln -s $x86/libboost_python3-py36.so.1.65.1 $x86/libboost_python3.so.1.65.1
For the latest version, it's a bit more complicate due to libboost 1.67. So, I put it in my kora library.
!pip install kora -q
import kora.install.rdkit
You'll get version 2020.09.1
First, you can install condacolab in Colab like below.
!pip install -q condacolab
import condacolab
condacolab.install()
Then you can install rdkit by using conda syntax.
!conda install -c rdkit rdkit
If you follow these steps it will work completely properly

How to install mayavi on google Colab?

I tried installing mayavi on Colab using pip:
!pip install mayavi
This threw the following error:
Running setup.py bdist_wheel for mayavi ... error
The rest of the error output is available at the Colab document.
Solution: Work in Progress
Following the response from #Bob-Smith, I found that his solution needed a slight change for installing the dependencies:
!apt-get install vtk6
!apt-get install libvtk6-dev python-vtk6
Problems Faced and Workaround Found (PFWF)
PFWF-001 !apt-get install python-vtk throws the following error:
Package 'python-vtk' has no installation candidate
I found a command-reference for this:
!apt-get install libvtk5-dev python-vtk
However, this command also did not work. The package name had changed from libvtk5-dev to libvtk6-dev and the python binding for VTK has changed from python-vtk to python-vtk6. Clearly this kind of change will continue to happen in future and you may need to check the package name and the python binding for VTK before running the following statement:
!apt-get install libvtk6-dev python-vtk6
Note: If you are here looking to solve VTK installation problems for python and this does not solve that you may want to look here: installing-vtk-for-python
Installing mayavi still throws error:
Although the two steps above install the dependencies, the last line: !pip install mayavi spits out the following error:
Could not connect to any X display.
The latest progress on Mayavi installation can be found here.
https://colab.research.google.com/drive/1K_VIP9izNLKalD_IgBSiTowyNkU7aWcW
You'll first need to install deps. Run
!apt-get install vtk6
!apt-get install python-vtk
!pip install mayavi
If you've attempted to import myavi before installing the deps, you may need to restart you runtime before executing the !pip install myavi command using the Runtime -> Restart runtime menu.
I was trying to do the same thing and I was getting error like this. So I tried install vtk package with conda. You need conda to install vtk of course so:
!wget -c https://repo.anaconda.com/miniconda/Miniconda3-4.5.4-Linux-x86_64.sh
!chmod +x Miniconda3-4.5.4-Linux-x86_64.sh
!bash ./Miniconda3-4.5.4-Linux-x86_64.sh -b -f -p /usr/local
!conda install -q -y --prefix /usr/local python=3.6 ujson
import sys
sys.path.append('/usr/local/lib/python3.6/site-packages')
import ujson
print(ujson.dumps({1:2}))
!conda --version
Then set up vtk package with conda as:
!apt-get install vtk6
!conda install -c anaconda vtk
I was trying to install mayavi for mne package so:
!conda activate mne
!conda install gxx_linux-64=7.3
!pip install https://api.github.com/repos/enthought/mayavi/zipball/226189a6ad3dc3c01d031ef21d0d0cde554ac851
Be careful because you need to mne package to activate so before installing mayavi (I was trying to install mne as I said before):
!pip install mne

Categories

Resources