我只能在特定版本的Python下导入Stripe Python库

4 投票
2 回答
2873 浏览
提问于 2025-04-17 07:35

我在使用Webfaction,这是共享主机的命令行。

[zallarak@web198 ~]$ python2.6
Python 2.6.5 (r265:79063, Nov 23 2010, 02:02:03) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import stripe
>>>

[zallarak@web198 ~]$ python2.7
Python 2.7.1 (r271:86832, Dec  1 2010, 06:29:57) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import stripe
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named stripe

我知道一定有简单的方法可以让它在所有版本的Python上都能运行。任何关于如何让它工作或者背后的概念的建议,我都非常感激。

我用的Django版本是2.7,所以我的目标是让它在2.7上运行。

2 个回答

3

Brian Cain说得对,你现在用的Python版本里没有安装这个东西。你应该运行下面这个命令,而不是他给你的:

easy_install-2.7 stripe

在运行之前,先确认一下这个目录:/home/username/lib/python2.7/确实存在。如果不存在,你可以用这个命令来创建它:mkdir -p /home/username/lib/python2.7

这样就会把它安装到你的Python2.7里,然后你就可以在Python2.7的Django中使用它了。

注意:如果你看到错误信息:“需要libcurl版本7.19.0或更高版本来编译pycurl。”那你需要按照这里的说明操作:

http://community.webfaction.com/questions/6365/problems-installing-pycurl

来在你的账户上安装自己的curl版本。

4

你的问题是每个 Python 环境里都没有安装 stripe 模块。

我知道一定有简单的方法可以让它在所有版本的 Python 中都能工作。

你必须在每个环境中安装 stripe。根据你的网络主机的说明,你应该可以通过 easy_install 来安装它们。试试这个:

python2.7 `which easy_install` stripe

撰写回答