多平台可移植Python

发布于 2024-12-10 13:24:30 字数 86 浏览 0 评论 0原文

我想在虚拟环境中将python安装在闪存驱动器上,这样无论我在哪里都可以开发代码。我可以在 Windows/Mac/Linux 计算机上使用我的闪存驱动器吗?

I want to install python on a flash drive in a virtual environment so that I can develop code wherever I am. Is this possible to do in such a way that I can use my flash drive on windows/mac/linux computers?

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

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

发布评论

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

评论(3

月竹挽风 2024-12-17 13:24:31

正如 @millimoose 指出的,您可以安装三个不同版本的 Python。

对于您正在处理的每个 Python 包,您可以创建一个 .pth 文件,位于您想要使用该包的每个 Python 版本的 site-packages 目录中。

请注意,如此处所述:

如果将 .pth 文件放入包含路径的 site-packages 目录中,Python 会搜索该路径进行导入。

例如,如果您正在处理一个名为 my_package 的包,该包位于路径 C:\Users\Me\Documents\dev_packages\my_package 中,您可以添加扩展名为 .pth 的文件(请注意,名称并不重要,特别是它不必与包名称有任何关系),其内容为:

C:\Users\Me\Documents\dev_packages

这将添加将 C:\Users\Me\Documents\dev_packages 添加到 Python 导入搜索路径,导致 my_package 包被发现。通过将此 .pth 文件放置在每个 Python 版本的 site-packages 目录中,my_package 将在所有相应的 Python 版本中可用。

As @millimoose pointed out, you could install three different versions of Python.

For each Python package you are working on, you can create a .pth file in the site-packages directory of each Python version that you would like to use the package from.

Note that, as described here:

If you put a .pth file in the site-packages directory containing a path, python searches this path for imports.

For example, if you have a package named my_package that you are working on that resides at the path C:\Users\Me\Documents\dev_packages\my_package, you can add a file with extension .pth (note that the name doesn't matter, specifically it doesn't have to have any relation to the package name), with the contents:

C:\Users\Me\Documents\dev_packages

This will add C:\Users\Me\Documents\dev_packages to the Python import search-path, causing the my_package package to be discovered. By placing this .pth file in the site-packages directory of each Python version, my_package will be available in all corresponding versions of Python.

孤独难免 2024-12-17 13:24:30
  • 对于 Windows,请前往 Portable Python (http://PortablePython.com) 查看您拥有的各种选项,
  • 对于 Linux 和 Mac您不需要将其安装在 USB 驱动器上,因为这些系统通常预装了 Python。如果您需要这些系统的特定软件包,请将它们与命令行脚本一起放在 USB 上,该脚本可以通过在这些系统上的 virtualenv 中进行一次调用来加载它们,然后您就可以开始了!

请注意,这永远不是 100% 防弹的,因为您取决于您​​正在使用/为其带来包的 Python 版本。

  • For windows, head to Portable Python (http://PortablePython.com) to see various options you have,
  • For linux and Mac you don't need to install it on USB drive as those systems usually come with Python pre-installed. If you need specific packages for those systems, bring them on USB together with a command line script that can load them with one call in virtualenv on those systems and you are good to go !

Be aware that this is never 100% bullet proof as you are depending on Python version you are using/bringing packages for.

东北女汉子 2024-12-17 13:24:30

您可以尝试使用一些 VirtualEnv 类型的环境进行设置,并在您的计算机上安装各种 Python 版本。

但不确定如何绕过不同操作系统上的不同路径。

虚拟环境: http://pypi.python.org/pypi/virtualenv

You could try looking at setting up something using some VirtualEnv type environments, with the various Python versions installed on your machines.

Not sure how you'd get round the different paths on the different operating systems though.

Virtualenv: http://pypi.python.org/pypi/virtualenv

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