Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is pip install using git different than just cloning a repository?

Tags:

python

pip

django

I'm a beginner with Django and I'm having trouble installing django-basic-apps using pip.

If I do this...

$ cat requirements.txt 
git+git://github.com/nathanborror/django-basic-apps.git

$ pip install -r requirements.txt

I end up with lib/python2.6/site-packages/basic/blog that does NOT have a templates directory.

If I do this...

git clone http://github.com/nathanborror/django-basic-apps.git

I end up with a copy of basic/blog that DOES have a templates directory.

I suspect something about django-basic-apps or pip makes it not able to be installed via pip. I thought maybe reading django-basic-apps's setup.py would lead me to the answer, but I couldn't see it.

(I should add that if I install without using pip, I'm able to get django-basic-apps working just fine.)

like image 468
golliher Avatar asked Sep 11 '10 03:09

golliher


People also ask

What is the difference between git clone and download?

When you download the repo it just gives you all the source files with no . git so you dont have the repo. When you clone you get a copy of the history and it is a functional git repo.

What is the difference between pip install and Python pip install?

They do exactly the same thing. In fact, the docs for distributing Python modules were just updated to suggest using python -m pip instead of the pip executable, because it's easier to tell which version of python is going to be used to actually run pip that way.

Can you install git using pip?

You can use pip to install directly from a git repository. To install flask the shortest version of the command is pip install git+https://github.com/pallets/flask.git .


1 Answers

When you use "pip" to install something, the package's setup.py is used to determine what packages to install. And this project's setup.py, if I'm reading it correctly, says "just install these Python packages inside the basic directory" — the setup.py makes absolutely no mention of any non-Python files it wants included in the install.

This might be deliberate on the developer's part, since it is something of a tradition for Django packages to not include templates — notoriously, even something so basic as the built-in django.contrib.auth comes without any templates and makes you build its little forms from the ground up each time! (Or, to cut and paste from examples elsewhere on the web.)

But if you yourself want the templates to be installed with this Python distribution, regardless of how the author has set things up, then just list the templates in the setup.py! First, add something like this to the setup.py file:

template_patterns = [
    'templates/*.html',
    'templates/*/*.html',
    'templates/*/*/*.html',
    ]

Then, add one last variable to the setup() call so that it ends like this:

...
packages=packages,
package_data=dict( (package_name, template_patterns)
                   for package_name in packages ))

This asserts to the setup() function that every package should be accompanied by data files that are found by searching for HTML files beneath each package's templates directory.

Try it out, and let me know if this works on your machine too!

like image 119
Brandon Rhodes Avatar answered Oct 02 '22 13:10

Brandon Rhodes