简体   繁体   English

如何正确地将Python库导入Django项目(托管在Heroku中)?

[英]How to correctly import a Python library into a Django project (hosted on Heroku)?

I need to include the Recurly API library into a Django project. 我需要将Recurly API库包含在Django项目中。 The library is on GitHub, and the project is deployed to Heroku. 该库位于GitHub上,该项目已部署到Heroku。 Currently, I have the following added to requirements.txt: 目前,我已将以下内容添加到requirements.txt:

-e git://github.com/recurly/recurly-client-python.git#egg=recurly-client-python

This may work once the app is on heroku (?) but it's not getting picked up when developing locally (running local server via foreman). 一旦应用程序在heroku(?)上,这可能会起作用,但是在本地开发(通过工头运行本地服务器)时不会被拾取。 In my test app's views.py, I have: 在测试应用程序的views.py中,我有:

import recurly

I get: 我得到:

Exception Type: ImportError
Exception Value:    
No module named recurly
Exception Location: /Users/pete/Documents/code/django/simpleblog/subscriptions/views.py in <module>, line 7
Python Executable:  /Users/pete/.virtualenvs/django/bin/python 

I'm pretty new to Django/Python, as well as working with APIs in this environment. 我是Django / Python的新手,并且在此环境中使用API​​。 How should I install & include it, so it works both locally and once deployed? 我应该如何安装和包含它,以便它既可以在本地使用又可以在部署后使用? I tried searching online to no avail. 我尝试在线搜索无济于事。

First method: 第一种方法:

What you can do is clone the code on your desktop : 您可以在桌面上克隆代码:

git clone https://github.com/recurly/recurly-client-python.git git clone https://github.com/recurly/recurly-client-python.git

and then from this new directory run 然后从这个新目录运行

python setup.py install python setup.py安装

(This is how you can install any reusable python app into your environment) (这是您可以在环境中安装任何可重复使用的python应用程序的方式)

EDIT1: EDIT1:

Second method: simply change requirement.txt 第二种方法:只需更改require.txt

"-e git://github.com/recurly/recurly-client-python.git#egg=recurly-client-python" to "recurly" “ -e git://github.com/recurly/recurly-client-python.git#egg=recurly-client-python”改为“ recurly”

If you are new to python and want easy and fast implementation use second one. 如果您是python的新手,并且想要简单快速地实现,请使用第二个。 If you are new to python and want to learn how things work in python use first one, it will help. 如果您是python的新手,并且想学习python的工作原理,请使用第一个,它会有所帮助。

EDIT2: EDIT2:

Wanna learn more? 想了解更多? Check which version you got installed by these two different methods. 检查通过这两种不同方法安装的版本。 ("pip list|grep recurly") (“递归清单| grep”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM