多平台可移植Python
我想在虚拟环境中将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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如 @millimoose 指出的,您可以安装三个不同版本的 Python。
对于您正在处理的每个 Python 包,您可以创建一个
.pth
文件,位于您想要使用该包的每个 Python 版本的site-packages
目录中。请注意,如此处所述:
例如,如果您正在处理一个名为
my_package
的包,该包位于路径C:\Users\Me\Documents\dev_packages\my_package
中,您可以添加扩展名为.pth
的文件(请注意,名称并不重要,特别是它不必与包名称有任何关系),其内容为:这将添加将
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 thesite-packages
directory of each Python version that you would like to use the package from.Note that, as described here:
For example, if you have a package named
my_package
that you are working on that resides at the pathC:\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:This will add
C:\Users\Me\Documents\dev_packages
to the Python import search-path, causing themy_package
package to be discovered. By placing this.pth
file in thesite-packages
directory of each Python version,my_package
will be available in all corresponding versions of Python.请注意,这永远不是 100% 防弹的,因为您取决于您正在使用/为其带来包的 Python 版本。
Be aware that this is never 100% bullet proof as you are depending on Python version you are using/bringing packages for.
您可以尝试使用一些 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