简体   繁体   English

我应该安装我的Python模块吗?

[英]Should I be installing my Python modules?

I generally don't bother to install Python modules. 我通常不会打扰安装Python模块。 I use web2py, and just dump them in the modules folder and let it take care of the local imports. 我使用web2py,只是将它们转储到modules文件夹中,并使其处理本地导入。 It just always seemed like the most straightforward way of doing things- never felt right about handling dependencies at a system-wide level, and never felt like messing with virtual envs. 这似乎始终是最简单的处理方式-从来没有在系统级处理依赖项的感觉,也从来没有感觉到像虚拟环境那样混乱。

On one of my other questions , the answerer said 关于我的其他问题之一 ,回答者说

Generally, the best practice for 3rd party modules is to install them via pip or easy_install (preferably in a virtualenv), if they're available on PyPI, rather than copying them somewhere onto your PYTHONPATH. 通常,如果第三方模块在PyPI上可用,则最佳做法是通过pip或easy_install(最好在virtualenv中)安装它们,而不是将其复制到PYTHONPATH上。 ... [because that] runs the install scripts hooks necessary to install executable scripts, build C extensions, etc., that isn't done by just copying in a module. ... [因为这样]运行安装脚本钩子,这些钩子是安装可执行脚本,构建C扩展等所必需的,而不仅仅是通过复制模块来完成。

I don't fully understand this. 我不完全明白这一点。 I always thought it was more of a preference, but is it true that it's better practice to install 3rd party modules, and am I potentially causing problems by not doing that? 我一直以为这是更可取的选择,但是安装第三者模块是更好的做法,这是真的吗?如果不这样做,是否可能引起问题? Does using a framework like web2py make a difference? 使用像web2py这样的框架会有所不同吗?

It depends on the module and what you want to use it for. 这取决于模块以及要使用的模块。 Some packages come with useful command line tools, which may only be available to you if you install them appropriately. 某些软件包附带有用的命令行工具,只有在正确安装它们后才能使用。

Conversely, if you're writing code which is to be distributed to environments you don't have much control over, you often have to keep a copy of the code locally within your project, as the target environment may not have the package... web projects often fall into this category, depending on your serving environment, of course. 相反,如果要编写要分发给您没有太多控制权的环境的代码,则通常必须在项目中本地保留代码的副本,因为目标环境可能没有软件包。当然,根据您的服务环境,.web项目通常属于此类。

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

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