How do I include library from github in python project without pip? - python

I'm not sure what's the python way to include another library getting from github.
I'm planning to use this library https://github.com/nim901/gfycat which right now I just downloaded the zip and extract it and put that in lib folder. I have to checkin this library into the repo to work in Heroku. Is there a way to install the lib automatically from github?

Heroku has support for git-backed python dependencies via pip: https://devcenter.heroku.com/articles/python-pip#git-backed-distributions
I believe this fits your requirements better than checking the actual libraries into git. From the link above:
Anything that works with a standard pip requirements file will work as expected on Heroku.
Thanks to pip’s Git support, you can install a Python package that is hosted on a remote Git repository.
For example:
git+git://github.com/kennethreitz/requests.git

You can add the library as a submodule of your project. This will allow you to update it like any other git repository.
Is git clone https://github.com/nim901/gfycat.git and then git pull automatic enough? If this solution fits you and you need additional instructions, I will add them.

From how I'm reading your question, it sounds like you're trying to install the module to your system in order to be able to import it into projects and such.
Download the zip, extract it to wherever, and open up a terminal window to the same directory. Then just run python setup.py install from within the directory, and it should install into your system-wide site-packages directory for python.
I would have to recommend that you install it into it's own environment managed by virtualenv (https://virtualenv.pypa.io/en/latest/), but it's not necessary.

Related

Python 3.6: Import subdirectorys not working in Pycharm

I have a Pycharm project where I have copied two github projects (download zip and copy paste into project). My problem is that I cannot access the from main, which is located at root.
For some unknown reason from . syntax only shows me files/folders I have created myself.
I'm trying to access build module where there is a class TFNET which I want to import
from darkflow-master.darkflow.net.build import TFNET
Downloading directories like this isn't how you'd typically include external dependencies in a python project.
A more conventional approaches would be ot install the project using pip, it looks like darkflow gives information on how to do this.
Alternatively, just ensure the libraries are in your PYTHONPATH, it looks like pycharm has a way to do this: PyCharm and PYTHONPATH
Reading between the lines, it sounds like you have downloaded two libraries from github, and copied them into your project.
Python needs to know where to find source files.
If you want do it this way, you need to tell your python environment where to find the new sources. Pycharm looks after python environments while you are in python.
Please see https://www.jetbrains.com/help/pycharm/configuring-folders-within-a-content-root.html
but this won't tell python outside of Pycharm where to find your library source.
pip is most likely the answer. pip can install globally or inside python virtual environments, in either case, it puts the library code in a location python is expecting to find it.
On this point, please learn about python virtual environments. These are self-contained python mini-worlds. In a venv, you can run a specific version of python with specific packages. Pycharm works well with them, it is easy to set up virtual envs with pycharm. When you are 'inside' a venv, pip will install into the venv, therefore not touching your system python or the python of any other projects.
Also, pip normally installs from an official repository (pypi) but you can tell it to use a git repository as the source of your install. Normally people who write libraries send their mature versions to pypi so it is unusual to fetch from a git repository, but if you want the very latest version, or if the author has not published the library, it's an option.
Note that pip doesn't work with any arbitrary python code. It must be set up to be seen by pip as a python package.

Can I send others the third-party Python packages I installed?

I have code on an offline computer, so I needed to install dependency packages offline (which I myself figured out how to only yesterday). Now, I want to send my work to my teammates (it's a school project and half of them are first-time programmers), whether directly or through Github. I want to send them the packages I was using too, just in case they needed to do offline installation.
Is it possible to just zip up the dependency packages as-is and send it to them to unzip to the relevant directory? Where are these packages installed to? Are there other files that need to be sent? Or is there no other way than to run the python/pip install on the wheels/tar.gz I downloaded from PyPi (the solution I'm trying to avoid)?
You can make use of virtualenv for this purpose: https://virtualenv.pypa.io/en/latest/index.html
It will install dependencies inside a folder, so you can zip or share in many ways.
The folder you are looking for is 'site-packages' or 'dist-packages', you can put packages in here for use in python on a machine without a package manager.
The default directory for packages on windows is:
C:\Python\Lib\site-packages\
The default directory for packages on linux is:
/usr/lib/python2.7/dist-packages

django installing dependencies from git

Is there any way to tell django to install some dependencies through external repositories? For example, I'd not like to keep twitter-bootstrap code downloaded into my repository, I'd like to define a github link and fetch it automatically through a shell command. Something silimiar to collectstatic. I know I can write my own, but maybe there's something built-in or already implemented?
Python modules you can install directly from git. For example: pip install -e git+git://github.com/jschrewe/django-genericadmin.git
For frontend modules you can use tools like bower. For installing Twitter Bootstrap: bower install bootstrap
Both tools has config files, which can be used to track dependencies.

external Libs pack to python project

I'm trying to use SVN to manage my python project.
I installed many external Libs (the path is like:"C:\Python27\Lib\site-packages")on Computer A,then I upload the project to the SVN Server.
and then I use Computer B which just has python(v2.7) been installed.I checkout from the SVN server
:here comes the problem..there is no external Libs in computer B.Is there any solution to solve this problem,I don't want to install the external Libs on Computer B again!
Thanks advance!
The normal Python way to deal with this is to use pip and requirements files. virtualenv, which lets you have multiple sets of installed packages, is also commonly used.
For example, if you have a project which depends on any version of itsdangerous and any version of Werkzeug over 0.9, you could have this requirements file:
Werkzeug>=0.9
itsdangerous
You would usually store that in a file named requirements.txt. You would then install the packages like this:
pip install -r requirements.txt
pip will find all of the packages needed not already installed and install them.
You could actually copy the package source code from site-packages to your project folder, and your project folder normally has a higher prority than site-packages.
Then you just need check-in library to your svn.

PIP install a Python Package without a setup.py file?

I'm trying to figure out how I can install a python package that doesn't have a setup.py file with pip. (package in question is http://code.google.com/p/django-google-analytics/)
Normally I would just checkout the code from the repo and symlink into my site-packages, but I'm trying to get my whole environment frozen into a pip requirements file for easy deployment and testing.
Any ideas?
Fork the repo and add a working setup.py. Then send a pull request to the author.
Oh, it's on Google Code. Well then, file a bug and post a patch.
If the author refuses to make their code into an installable Python distribution (never happened to me), just host your fork somewhere and put that in your requirements file.
You can't. PIP installs Python packages. That's not a Python package. I've heard that the Django community in general doesn't make much packages, which makes things like what you are trying to do tricky. But that could be wrong.
If you want to freeze your environment you might want to look into Buildout. Other options in this case is to use an svn:external.

Categories

Resources