Importing modules on portable python

老子叫甜甜 提交于 2019-12-20 06:55:14

问题


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.


回答1:


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).




回答2:


This closed question was actually asked for Portable Python 3.2. I have found a nice way to install modules with Windows :

  • download the zip archive of the distribute module

  • install it by typing

    MyPythonPath\App\python MyDownloadPath\setup.py install

in a DOS commander

  • Now Easy Install is installed in folder MyPythonPath\App\Scripts. So type e.g.

    MyPythonPath\App\Scripts\easy_install-3.2 numpy

to install the numpy module.



来源:https://stackoverflow.com/questions/12160766/install-packages-with-portable-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!