如何使用git安装pip不仅仅是克隆存储库?

时间:2021-09-21 15:50:57

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

我是Django的初学者,我在使用pip安装django-basic-apps时遇到了麻烦。

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.

我最终得到了没有模板目录的lib / python2.6 / site-packages / basic / blog。

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.

我怀疑django-basic-apps或pip使得它无法通过pip安装。我想也许阅读django-basic-apps的setup.py会引导我找到答案,但我看不到它。

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

(我应该补充一点,如果我不使用pip安装,我就能让django-basic-apps工作得很好。)

1 个解决方案

#1


25  

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.

当您使用“pip”安装某些东西时,软件包的setup.py用于确定要安装的软件包。这个项目的setup.py,如果我正确地读它,说“只需在基本目录中安装这些Python包” - setup.py绝对没有提到它想要包含在安装中的任何非Python文件。

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.)

这可能是开发人员的一部分,因为Django软件包不包含模板是一种传统 - 众所周知,即使是内置的django.contrib.auth也没有任何模板这样基本的东西,让你构建它的一点点每次从头开始形成! (或者,从网上其他地方的示例中剪切和粘贴。)

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:

但是如果您自己希望使用此Python发行版安装模板,无论作者如何设置,那么只需在setup.py中列出模板即可!首先,在setup.py文件中添加以下内容:

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

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

然后,将最后一个变量添加到setup()调用中,使其结束如下:

...
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.

这向setup()函数断言,每个包都应该附带通过在每个包的模板目录下搜索HTML文件而找到的数据文件。

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

尝试一下,让我知道这是否适用于您的机器!

#1


25  

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.

当您使用“pip”安装某些东西时,软件包的setup.py用于确定要安装的软件包。这个项目的setup.py,如果我正确地读它,说“只需在基本目录中安装这些Python包” - setup.py绝对没有提到它想要包含在安装中的任何非Python文件。

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.)

这可能是开发人员的一部分,因为Django软件包不包含模板是一种传统 - 众所周知,即使是内置的django.contrib.auth也没有任何模板这样基本的东西,让你构建它的一点点每次从头开始形成! (或者,从网上其他地方的示例中剪切和粘贴。)

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:

但是如果您自己希望使用此Python发行版安装模板,无论作者如何设置,那么只需在setup.py中列出模板即可!首先,在setup.py文件中添加以下内容:

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

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

然后,将最后一个变量添加到setup()调用中,使其结束如下:

...
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.

这向setup()函数断言,每个包都应该附带通过在每个包的模板目录下搜索HTML文件而找到的数据文件。

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

尝试一下,让我知道这是否适用于您的机器!