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

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

问题描述

我正在USB记忆棒上运行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.

推荐答案

import sys; print sys.path说什么?它应该是Python(便携式或其他)寻找要导入模块的目录和zipfile的列表.只需将模块复制到其中一个目录或zipfile中,或者如果您将模块保存在/whatever/dir中并希望将其保留在其中,则将其复制到sys.path.append('/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天全站免登陆