简体   繁体   English

如何在特定目录中安装python包

[英]How to install python package in a specific directory

I'm developing a twitter app on google appengine - for that I want to use the Twython library. 我正在谷歌appengine开发一个Twitter应用程序 - 因为我想使用Twython库。 I tried installing it using pip - but it either installs it in the main python dir, or doesn't import all dependencies. 我尝试使用pip安装它 - 但它要么安装在主python目录中,要么不导入所有依赖项。

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. 我可以简单地将Twython的所有文件复制到appengine根目录,并手动导入所有依赖库,但这看起来非常错误。 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. 如果将模块文件放在一个目录中,例如external_modules/ ,然后使用sys.path.insert(0, 'external_modules') ,则可以包含该模块,因为它将是一个内部模块。

You would have to call sys.path.insert before the first import of the module. 在第一次导入模块之前,您必须调用sys.path.insert 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. 示例:如果在external_modules/放置了“module.pyd”并希望将其包含在import module ,则将sys.path.insert放在之前。

The sys.path.insert() is an app-wide call, so you have to call it only once. sys.path.insert()是一个应用程序范围的调用,因此您只需调用一次。 It would be the best to place it in the main file, before any other imports (except import sys of course). 在任何其他导入(当然除了import sys )之前,最好将它放在主文件中。

Use virtual environment and virtual environment wrapper , you dont have to use the wrapper but use it for simplicity.. 使用虚拟环境和虚拟环境包装器,您不必使用包装器,但为简单起见使用它。

https://pypi.python.org/pypi/virtualenv https://pypi.python.org/pypi/virtualenv

If you're installing a package using pip, try this: 如果您使用pip安装软件包,请尝试以下方法:

Install a Python package into a different directory using pip? 使用pip将Python包安装到不同的目录中?

I personally needed libraries that I was just using out of git repos. 我个人需要我刚刚使用git repos的库。 I just symlinked those libraries instead of installing them. 我只是对这些库进行符号链接而不是安装它们。 But in that case, I had to manually symlink all the dependencies too. 但在这种情况下,我不得不手动符号链接所有依赖项。

You could use gaenv (package manager I built for app engine). 你可以使用gaenv(我为app引擎构建的包管理器)。 It only creates symlinks and follows the pip requirements.txt format. 它只创建符号链接并遵循pip requirements.txt格式。 You can install & use like: 您可以安装和使用:

pip install gaenv
# create requirements.txt -> twython
pip install -r requirements.txt
gaenv

This creates symlinks to gaenv_lib/ of all required libraries. 这会为所有必需库的gaenv_lib /创建符号链接。 Then will ask to add the import statement. 然后会要求添加import语句。

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

相关问题 如何使用pip使用vcs将Python包可编辑安装到特定目录中? - How to make editable install of Python package from vcs into specific directory using pip? 如何为特定的python版本安装软件包 - How to install a package for specific python version 如何安装特定 python package 的零件? - How to install parts of specific python package? 如何使用 pip -t 从 git 将 package 安装到特定目录中 - How to install a package from git into a specific directory using pip -t 在当前目录安装python包 - install python package at current directory 如何从特定的 package 安装/导入 Python package? - How to install / import a Python package from a specific package? pip 将 python 包安装到默认安装位置以外的特定目录中 - Pip install python package into a specific directory other than the default install location 如何配置 python setuptools 将模块作为单个包安装在根目录中? - How to configure python setuptools to install modules in the root directory as a single package? 如何将python包的data_files安装到主目录中 - How to install data_files of python package into home directory 多个版本的python,如何在特定版本上安装python包? - multiple versions of python, how to install python package on a specific version?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM