如何创建一个完全自治的Python环境?

发布于 2024-10-14 21:04:54 字数 156 浏览 2 评论 0原文

我想在 USB 笔驱动器上创建一个完全自主的 Python 环境,可以在 Windows 和 GNU/Linux 上运行......

我该怎么做?

我尝试使用“./”作为前缀构建Python,但它不起作用......有人有其他想法吗?

提前致谢...

I want to create a completely autonomous Python environment on an USB pen drive that can run both on Windows and GNU/Linux....

How can I do that ?

I've tried to build Python with `./' as prefix, but it doesn't works... anyone has another idea ?

Thanks in advance...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盛装女皇 2024-10-21 21:04:54

好的,我看过 http://svn.python.org/projects /python/branches/release31-maint/ 我发现了一个有趣的 «自述文件» 谈论 «pyconfig.h» 文件。

http://svn.python.org/projects/ python/branches/release31-maint/PC/pyconfig.h 在第82-83行,有我的问题的解决方案:

#ifndef PYTHONPATH
#   define PYTHONPATH L".\\DLLs;.\\lib;.\\lib\\plat-win"

我想如果我更改“PYTHONPATH”定义的值,我会得到一个python 解释器在相对目录中寻找他的文件,所以我只需要为 GNU/Linux 和 Window 构建它,并将这两个可执行文件放在笔式驱动器上,然后我将获得一个便携式 Python 环境!

我正在尝试这个,我会随时通知您...


编辑:终于,它起作用了!
我已经像这样构建了Python:

make PYTHONPATH=../lib:../Lib:./lib:./Lib

...现在Python在`../lib'中寻找模块!

我将为 GNU/Linux 和 Windows 构建它,并将其放在 USB 笔式驱动器上,如下所示:

/mnt/key/
├── AUTORUN.INF 
├── Lib
│   ├── os.py
│   ├── sys.py
│   ├── ...
│   └── (Here i'll put the Python Standard Library)
├── Linux
│   └── python
└── Windows
    ├── python.exe
    └── pythonw.exe

谢谢大家

Ok, i've looked at http://svn.python.org/projects/python/branches/release31-maint/ and i found an interesting «readme» talking about a «pyconfig.h» file.

In http://svn.python.org/projects/python/branches/release31-maint/PC/pyconfig.h at line 82-83, there is the solution of my problem:

#ifndef PYTHONPATH
#   define PYTHONPATH L".\\DLLs;.\\lib;.\\lib\\plat-win"

I think if i change the value of the «PYTHONPATH» define, i'll get a python interpreter seeking his files in a relative directory, so I'll just have to build it both for GNU/Linux and Window, and to put the both executables on a pen-drive, then i'll get a portable Python environment !

I'm trying this, and I'll keep you posted ...


EDIT: Finally, it works !
I've built Python like this:

make PYTHONPATH=../lib:../Lib:./lib:./Lib

... and now Python seeks the modules in `../lib' !

I will build it both for GNU/Linux and Windows, and i'll put it on an USB pen-drive, like this:

/mnt/key/
├── AUTORUN.INF 
├── Lib
│   ├── os.py
│   ├── sys.py
│   ├── ...
│   └── (Here i'll put the Python Standard Library)
├── Linux
│   └── python
└── Windows
    ├── python.exe
    └── pythonw.exe

Thanks all

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文