如何在特定的目录下安装python包 [英] How to install python package in a specific directory
问题描述
我正在Google Appengine上开发一个twitter应用程序 - 因为我想使用Twython库。我试着使用pip来安装它 - 但它要么将它安装在主python目录中,要么不会导入所有依赖项。
我可以简单地复制Twython的所有文件到appengine根目录,还手动导入所有的依赖库,但这似乎是非常错误的。
谢谢
external_modules /
,然后使用 sys.path.insert(0 ,'external_modules')
您可以包含该模块,因为它将是一个内部模块。 您必须调用 sys.path.insert
在模块的第一次导入之前。
示例:如果您在 external_modules /
中放置了一个module.pyd,并希望将它包含在导入模块
,然后放置 sys.path.insert
。
code> sys.path.insert()是一个应用程序范围内的调用,因此您只需调用它一次。在任何其他导入之前(当然,除了 import sys
)之外,最好将它放在主文件中。
I'm developing a twitter app on google appengine - for that I want to use the Twython library. I tried installing it using pip - but it either installs it in the main python dir, or doesn't import all dependencies.
I can simply copy all the files of Twython to the appengine root dir, and also import manually all the dependency libraries, but that seems awfully wrong. How do I install a package in a specific folder including all it's dependencies?
Thanks
If you put the module files in a directory, for example external_modules/
, and then use sys.path.insert(0, 'external_modules')
you can include the module as it would be an internal module.
You would have to call sys.path.insert
before the first import of the module.
Example: If you placed a "module.pyd" in external_modules/
and want to include it with import module
, then place the sys.path.insert
before.
The sys.path.insert()
is an app-wide call, so you have to call it only once. It would be the best to place it in the main file, before any other imports (except import sys
of course).
这篇关于如何在特定的目录下安装python包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!