windows 在 web2py 的本地安装中安装 Python 模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8131279/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 18:28:01  来源:igfitidea点击:

Install Python Module in local install of web2py

pythonwindowsmoduleweb2py

提问by Parth

I am running web2py on a Windows machine.

我在 Windows 机器上运行 web2py。

I'm working on an application, but it keeps erroring because it says the module I'm trying to use isn't installed. It is however installed in my local python install.

我正在开发一个应用程序,但它一直出错,因为它说我尝试使用的模块没有安装。然而,它安装在我的本地 python 安装中。

How can I install modules so that web2py can recognize them?

如何安装模块以便 web2py 可以识别它们?

回答by Bruno Rocha - rochacbruno

web2py recognize any module you have in your local Python installation, unless you have a module with the same name under /modules folder of your application.

web2py 可以识别本地 Python 安装中的任何模块,除非您的应用程序的 /modules 文件夹下有同名的模块。

If you are on windows I do not recommend the use of .exe version of web2py (this version is only for studies) and it has a self contained isolated Python interpreter.

如果您使用的是 Windows,我不建议使用 .exe 版本的 web2py(此版本仅用于学习),它有一个独立的 Python 解释器。

Make sure you are using source version of web2pyand Python 2.5+ on your windows.

确保您在 Windows 上使用web2py和 Python 2.5+ 的源版本

web2py should import any module from your Python path, also you can drop modules in app/modules folder ], then web2py will check there first when import something.

web2py 应该从你的 Python 路径导入任何模块,你也可以将模块放在 app/modules 文件夹中],然后 web2py 会在导入时首先检查那里。

回答by Anthony

If you are using the Windows binary version (i.e., web2py.exe), note that it includes its own Python interpreter, which means it will not use your installed version of Python and will therefore not see any of your installed modules. You can put Python modules in the /web2py/site-packages folder (which is created the first time you run the binary version), but the better approach is probably just to run the source code version of web2py. It's just as easy -- simply download and unzip the source code package, and instead of clicking on web2py.exe, you click on web2py.py (or at a command prompt, cdto the web2py directory and enter python web2py.py).

如果您使用的是 Windows 二进制版本(即 web2py.exe),请注意它包含自己的 Python 解释器,这意味着它不会使用您安装的 Python 版本,因此不会看到您安装的任何模块。您可以将 Python 模块放在 /web2py/site-packages 文件夹中(这是您第一次运行二进制版本时创建的),但更好的方法可能只是运行 web2py 的源代码版本。它同样简单——只需下载并解压缩源代码包,而不是单击 web2py.exe,而是单击 web2py.py(或在命令提示符下,cd转到 web2py 目录并输入python web2py.py)。

回答by hzm

What about add your local module path into sys.pathvariable?

将本地模块路径添加到sys.path变量中怎么样?

sys.path.apend('/path/to/your/module/directory')

sys.path.apend('/path/to/your/module/directory')

By the way, which module is not found by web2py

顺便说一下,web2py没有找到哪个模块