Using custom packages on Google-Colaboratory - python

I'm trying to install a custom python package on Google Colaboratory, that is not available on pip. And I'm facing some weird errors while doing that.
For example, here is a boiler-plate python package: https://github.com/mtchavez/python-package-boilerplate.
Then I tried to install it from the source.
%%bash
git clone https://github.com/mtchavez/python-package-boilerplate
cd rohan
pip install -e .
This time, however, I had experienced errors while importing submodules
ImportError: cannot import name ..
This package installs perfectly on my local computer/s. So I'm not sure why I'm not able to use it on Colaboratory.

A much simpler way to install custom packages on colab:
pip install git+https://github.com/mtchavez/python-package-boilerplate

Related

issue with the installation of the pyeeg library

I had used a pip install to install the pyeeg library, the code to which is as follows(installing the package in the jupyter notebook environment using ! before the pip install statement):
pip install pyeeg
The package and its other associated dependencies get installed, but when trying to import the library, the code to which is as follows:
import pyeeg
The following error is displayed:
ModuleNotFoundError: No module named 'pyeeg'
I've tried installing the library in user mode too, but the same error gets displayed
I've also tried downloading the respective source code file and placing it in my directory path, but the file seems to be having an issue.
Looking for some help in this regard.
Thank you,
Installation can be done as specified in the main repo. The steps are as follows:
git clone https://github.com/forrestbao/pyeeg.git
cd pyeeg
python setup.py install
python setup.py install --user

How to pip freeze source package

I am learning how to use venv here: https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/#installing-from-source
And it says I can install a source package by:
python3 -m pip install .
Which works, but now if I do pip freeze then I see:
my-package # file:///Users/joesmith/my-package
The problem is if I export this to a requirements.txt and try to install this environment on another machine then it won't work cause the path to source changed obviously.
What is the proper way to use a source package locally like i did but also export it afterwards so that another person can recreate the environment/run the code on another machine?
Pip has support for VCS like git. You can upload your code to git (e.g. Github, Gitlab, ..) for example and then use the requirements.txt. like this:
git+http://git.example.com/MyProject#egg=MyProject
https://pip.pypa.io/en/stable/cli/pip_install/#vcs-support
You would install package from PyPI rather than from source.
i.e. pip install requests
In this way other developers will also easily run your project.

How to install spoonacular python package

I'm trying to use the spoonacular python API found here https://github.com/ddsky/spoonacular-api-clients/tree/master/python
However, I can't seem to figure out how to install it in a virtualenv. I'm used to installing packages using pip. So when the instructions say to install like this:
pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git
do I need to save this directory (https://github.com/ddsky/spoonacular-api-clients/tree/master/python) to my own GitHub repo?
Any help would be greatly appreciated!
You're right something is strange, I tried a more direct approach:
First activate your virtual environment
Clone repo : git clone https://github.com/ddsky/spoonacular-api-clients.git
Install the package manually:
$ cd spoonacular-api-clients/python
$ python setup.py install
It should work:

Installing a standalone python module

I am extremely new in python so i cant figure out a way to install a standalone python module hosted by a third party. Ex https://github.com/cvangysel/gitexd-drupalorg/tree/master/drupalorg
How to install this specific python module DrupalHash . Should i use pip ? I tried to read the documentation Installing Python Modules but i could not quite get it.
Any help ?
Seeing as the linked repo doesn't contain a setup.py, which would be required to install it with pip or easy_install, and the last commit was over 4 years ago, I'd just copy the drupalpass.py file into your local project and use it with a simple from drupalpass import DrupalHash.
The module you are linking doesn't seem to be available on PyPI, you will need to clone the repository to use the library.
For packages that may be available on PyPI, you can install pip:
easy_install pip
Then, you will be able to install your packages:
pip install *package name*

Import a Python library from Github

I'm new to Python so this may sound silly.
I want to use a Python library I've found on Github, lets say on https://github.com/praw-dev/praw, and I want to be able to do git pull in the future to pull the latest commits.
Question: Should I git clone <git url> in the project directory and delete everything except the praw directory, then in my python script do a import praw?
In iPython,
import praw
gives the error ImportError: No module named praw
Directory Structure
~\myProject\
praw\
myNotebook.ipynb
Actually, if given package is not on PyPI (or you want a specific branch) you can still install it through pip from GitHub with:
pip install git+https://github.com/[repo owner]/[repo]#[branch name]
And for your problem it would be (although #pandita's answer is correct for normal usage case):
pip install git+https://github.com/praw-dev/praw.git
For more information check this answer.
Experimental Python module finder/loader from github, like in golang.
So, in golang we can import like:
import "github.com/parnurzeal/gorequest"
But in python we should install package by our hands:
pip install requests
And import it like:
import requests
But with this magic package and power of PEP-0302 we can do it automatically:
from github_com.kennethreitz import requests
assert requests.get('https://github.com/nvbn/import_from_github_com').status_code == 200
Installation
You should have git, Python 3.2+ and pip:
pip install import_from_github_com
Reference: https://github.com/nvbn/import_from_github_com
Just clone the files in any dir on your python path and then build the lib typically with python setup.py install from the command line.
I typically clone a libray form git in my site_libraries folder ( the folder that holds all of your pip installed packages ). From there you can pull and then build the libraries from git just like any other git repo. Having the files there is nice because all of your libs are in once place on your python path.
You might want to consider using pip instead of git to install and upgrade the package (that is unless you have a pressing reason to use git).
pip install praw
to update the package you can do
pip install --upgrade praw
Also have a look here for further information on how to use pip.

Categories