I try to import a Python package from github. I am working in Google Colab.
The repository is at the following url https://github.com/microsoft/nlp-recipes/tree/master/utils_nlp.
So I use the following code
!pip install --upgrade
!pip install -q git+git://github.com/microsoft/nlp-recipes/tree/master/utils_nlp
from utils_nlp import *
I tried as well
!pip install -q git+https://github.com/microsoft/nlp-recipes/tree/master/utils_nlp
I saw other (working) examples where the url ends in .git :
!pip install -q git+https://github.com/huggingface/transformers.git
so I tried in turn
!pip install -q git+https://github.com/microsoft/nlp-recipes/tree/master/utils_nlp.git
But I also noticed that https://github.com/microsoft/nlp-recipes/tree/master/utils_nlp.git loads to an error page while https://github.com/huggingface/transformers.git load to https://github.com/huggingface/transformers which surprises me.
How do we load the Python package here ?
EDIT
I am using as suggested
pip install git+https://github.com/microsoft/nlp-recipes.git
then
from utils_nlp import *
works but it doesn't successfully import subfolders, it fails when I do
from utils_nlp.models.transformers.abstractive_summarization_bertsum \
import BertSumAbs, BertSumAbsProcessor
whereas utils_nlp does contain a folder models which in turn contains transformers
The error stack is then the following
/usr/local/lib/python3.7/dist-packages/utils_nlp/models/transformers/abstractive_summarization_bertsum.py in <module>()
15 from torch.utils.data.distributed import DistributedSampler
16 from tqdm import tqdm
---> 17 from transformers import AutoTokenizer, BertModel
18
19 from utils_nlp.common.pytorch_utils import (
ModuleNotFoundError: No module named 'transformers'
So strangely code in utils_nlp.models.transformers.abstractive_summarization_bertsum doesn't resolve the dependency to transformers
This is the correct way to install it:
pip install git+https://github.com/microsoft/nlp-recipes.git
You can't install a module, only a package can be installed. After the installation you can go on with the rest of your code
from utils_nlp import *
...
As you can read in the setup guide (which you should definitely read when installing a package):
The pip installation does not install any of the necessary package dependencies, it is expected that conda will be used as shown above to setup the environment for the utilities being used.
This explains your error: the transformers package is not installed automatically, you need to install it on your own (simply use pip install transformers). This is also confirmed in the setup.py file: the are no "install_requires" dependencies.
Related
I run a code in Google Colab and get the initial error
/usr/local/lib/python3.7/dist-packages/utils_nlp/eval/rouge/rouge_ext.py in <module>()
23 import collections
24
---> 25 from indicnlp.tokenize import sentence_tokenize, indic_tokenize
26 from ...language_utils.hi.hindi_stemmer import hi_stem
27 from rouge import Rouge
ModuleNotFoundError: No module named 'indicnlp.tokenize'
How to install (for instance) the tokenize package from indicnlp ?
I tried
!pip install indicnlp.tokenize
which apprently doesn't crack it. How to specify from which package to pip install from ?
I also tried
!pip install indicnlp
from indicnlp import tokenize
which doesn't do it either. I then get the error
---> 30 from indicnlp import tokenize
31 from utils_nlp import eval
32 from utils_nlp.eval import rouge
ImportError: cannot import name 'tokenize' from 'indicnlp' (/usr/local/lib/python3.7/dist-packages/indicnlp/__init__.py)
Of course if I just do
!pip install tokenize
it does't know which tokenize to install
It looks like you just pip installed the wrong library. On pypi I found another project called indic_nlp_library (github repo) that seems to have the packages you're looking for. I can get
!pip install indic_nlp_library
from indicnlp.tokenize import sentence_tokenize, indic_tokenize
to work.
Looks like the indicnlp name was taken on pip by another project.
I am installing google cloud datastore to build a conversational chatbot, using the command
!pip install google-cloud-datastore
This gives me following error:
google-cloud-bigquery 1.9.0 has requirement google-cloud-core<0.30dev,>=0.29.0, but you'll have google-cloud-core 1.4.3 which is incompatible.
goes on to installing google-cloud-core-1.4.3 google-cloud-datastore-1.15.3.
Execute further
from google.cloud import datastore
gives following error:
/usr/local/envs/py3env/lib/python3.5/site-packages/google/cloud/_http.py in ()
20 import warnings
21
---> 22 from six.moves import collections_abc
23 from six.moves.urllib.parse import urlencode
ImportError: cannot import name 'collections_abc'
Package google-cloud-bigquery=1.9.0 seems to be old, I have google-cloud-bigquery=1.28.0. You can try to update first your Cloud SDK components and then install google-cloud-datastore again. You can update the components with:
gcloud components update
It is possible that you will be required to execute equivalent apt-get update command.
The second error with collections_abc seems to be a compatibility issue, python2 is being deprecated, please use Python3 (pip3). If the issue with six persists, try installing different version for instance; pip3 install six==1.15.0 as recommended in this github thread.
I'm trying to learn PyCaret but having a problem when trying to import it in Jupyter Lab.
I'm working in a virtualenv and installed pycaret via pip:
pip install pycaret
I can confirm its installed via pip list:
prompt-toolkit 3.0.7
protobuf 3.13.0
py 1.9.0
pycaret 2.1.2
pycparser 2.20
The very first line in the notebook is:
from pycaret.nlp import *
however this results in:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-3-7c206b4a9ead> in <module>
----> 1 from pycaret.nlp import *
2 import psycopg2
3 import sys, os
4 import numpy as np
5 import pandas as pd
ModuleNotFoundError: No module named 'pycaret'
I'm pulling my hair out trying to figure this out and can't find anyone else with something similar.
I've tried to import via the python shell as well and that works perfectly.
You should create a seperate environment for installing time series alpha module
after creating a new environment and switching into
pip install pycaret-ts-alpha
and then you will be able to access
https://towardsdatascience.com/announcing-pycarets-new-time-series-module-b6e724d4636c
I forgot that you had to install modules via Jupyter.
Following this guide: http://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/index.html
Installing like so:
# Install a pip package in the current Jupyter kernel
import sys
!{sys.executable} -m pip install numpy
Got it working
First Create a new environment conda documentation
Second Download the Pycaret with this instruction
Third check your sklearn version is greater thansklearn>=0.23.2.
Because if it's greater PyCaret is not compatible with that.
Nothing works for you? Download directly from github with this command
pip install git+https://github.com/pycaret/pycaret.git#egg=pycaret
I read on the tutorial page of pycaret that to install it through a Jupyter-notebook you should add an exclamation mark in front of the python command in the Jupyter-cell:
!pip install pycaret
I'm getting this error:
ImportError: cannot import name 'SUTime' from partially initialized module 'sutime' (most likely due to a circular import)
when importing the sutime module as:
from sutime import SUTime
as suggested in the sutime GitHub example: https://github.com/FraBle/python-sutime
Context: sutime is a Python library for parsing date/time from a natural language input, developed by the amazing team over at Stanford CoreNLP.
Note: I've already run the pre-req installs as well:
>> pip install setuptools_scm jpype1 # install pre-reqs
>> pip install sutime
>> # use package pom.xml to install all Java dependencies via Maven into ./jars
>> mvn dependency:copy-dependencies -DoutputDirectory=./jars
It's not true that a circular import is the most likely cause of your error. A failed, incomplete, or in some way strange installation is more likely. Try this:
pip uninstall sutime
pip uninstall jpype1
pip uninstall setuptools_scm
pip3 install setuptools_scm jpype1 # note: pip3
pip3 install sutime
Then, in the python-sutime directory, enter this command:
./test.sh
It should output lots of log lines, and the last line but one should be similar to this:
======================== 5 passed, 2 warnings in 13.06s ========================
In the same directory you can enter and run the Python script from the Example section of the README. It should output many log lines before the reported output. There may be a way to avoid that, but anyway it happens only once, when the script starts.
Clone the git repo. -
!git clone https://github.com/FraBle/python-sutime.git
Go to the python-sutime/sutime in the cloned repo. There is a pom.xml file. Open the terminal and issue the following command.
mvn dependency:copy-dependencies -DoutputDirectory=./jars -P english
Now you can simply import the sutime from the sutime.py script in the cloned repo folder.
If you want to use sutime from anywhere, install sutime using...
pip install sutime
and replace the /usr/local/lib/python3.6/dist-packages/sutime folder with the sutime folder you get after step 2.
I am trying to use this package ssd.pytorch in google colab but it is not working. I have added image of the code in the last line of the post. Here's my code-
import torch
from torch.autograd import Variable
import cv2
!git clone https://github.com/amdegroot/ssd.pytorch.git #cloning the package in colab first
!pip install -q BaseTransform
from data import BaseTransform, VOC_CLASSES as labelmap
whenever I try to install BaseTransform this message shows up.
Could not find a version that satisfies the requirement BaseTransform (from versions: )
No matching distribution found for BaseTransform
So I can't import anything. Should I install what I cloned first? But when I try to install ssd.pytorch the same message shows up.
!pip install -q ssd.pytorch
Could not find a version that satisfies the requirement ssd.pytorch (from versions: )
No matching distribution found for ssd.pytorch
As I am importing from the folder data should I install using that folder name?
!pip install -q data
For some reason this works and I don't know why. But still can't import anything when I use this line.
from data import BaseTransform, VOC_CLASSES as labelmap
ImportError Traceback (most recent call last)
in ()
----> 1 from data import BaseTransform, VOC_CLASSES as labelmap. ImportError: cannot import name 'BaseTransform'
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt. To view examples of installing some common dependencies, click the
"Open Examples" button below.
What should I do to import the package properly?
This is what the code looks like in colab:
the problem you got, is because you haven't change directory before import package.
just run the code below before you import
import os
os.chdir('ssd.pytorch')
besides, BaseTransform is a class defined in ssd.pytorch/data. You cannot install it.