简体   繁体   English

使用来自 USB 记忆棒的 Python 模块

[英]Using modules for Python, from USB stick

I need to be able to use a module/library for Python from a USB stick.我需要能够从 USB 记忆棒使用 Python 的模块/库。 I don't have root access to the computer (since it's in school) and I have very little disk space.我没有对计算机的 root 访问权限(因为它在学校),而且我的磁盘空间很小。 My idea was to be able to have my Python program (eg for playing songs) and be able to use a library, such as Pyglet , to play those.我的想法是能够拥有我的 Python 程序(例如,用于播放歌曲)并能够使用诸如Pyglet 之类的库来播放这些程序。

How can I import a pure library from a USB stick, into my program?如何将 U 盘中的纯库导入到我的程序中?

In python, to import modules you have to specify the PYTHONPATH if you want other paths to import your modules from.在 python 中,要导入模块,如果您希望其他路径从中导入模块,则必须指定PYTHONPATH

Let's say you have modules in the path path="/path/to/your/usb" and you want to use them.假设您在路径path="/path/to/your/usb"有模块并且您想使用它们。 Then, you should use那么,你应该使用

$ export PYTHONPATH=/path/to/your/usb
$ python file.py

Ie, like Faust mentioned, USB drives are no different from other directories.即,就像 Faust 提到的那样,USB 驱动器与其他目录没有什么不同。

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

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