在便携式 python 上导入模块 [英] Importing modules on portable python

查看:22
本文介绍了在便携式 python 上导入模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 U 盘上运行 PortablePython_1.1_py2.6.1.我的代码依赖于一些未预装的模块.有谁知道是否可以将新模块添加到便携式 python 安装中?简单地将文件夹复制到 site-lib 似乎不起作用.

I am running PortablePython_1.1_py2.6.1 on a USB stick. My code relies on some modules that are not preinstalled. Does anyone know whether it is possible to add new modules to a portable python installation? Simply copying in folders into site-lib does not seem to work.

推荐答案

What do import sys;打印 sys.path 怎么说?它应该是 Python(便携式或其他)查​​找要导入的模块的目录和 zip 文件的列表.只需将您的模块复制到这些目录或压缩文件之一,或者 sys.path.append('/whatever/dir') 如果您的模块位于 /whatever/dir并希望将它们保留在那里(后一种方法仅适用于当前会话,无论是交互式会话还是脚本执行).

What does import sys; print sys.path say? It should be the list of directories and zipfiles where Python (portable or otherwise) looks for modules to import. Just copy your modules into one of those directories or zipfiles, or sys.path.append('/whatever/dir') if you have your modules in /whatever/dir and want to keep them there (the latter approach will last only for the current session, be it interactive or a script's execution).

这篇关于在便携式 python 上导入模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆