运行多个Python版本
我想在我的机器上运行多个 Python 版本。有没有 Python 版本管理器,我可以在多个 Python 版本之间切换,而无需调用 Python 二进制文件的完整路径?我尝试过 virtualenv,它似乎只涵盖运行多个 Python 库版本的问题。
感谢您的帮助。
I want to run multiple Python versions in my box. Is there any version manager for Python where I can switch between multiple Python versions without having to call the full path of the Python binary? I have tried virtualenv
and it seems to only cover problems running multiple Python library versions.
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
从 bash 调用 python 时,您可以尝试使用别名。
假设您有一个名为 script.py 的脚本,其中包含以下内容:
因此,使用不同版本的 python 启动脚本如下所示:
When calling python from bash you could try an alias.
Let's say you have a script called script.py with following content:
So, launching a script with a different version of python looks like:
我使用 virtualenv 来跟踪项目所需的不同环境。我可以在一个环境中设置 django 1.0,或者在另一个环境中设置 django 1.2。您也可以使用它来设置您想在特定环境中使用哪个版本的 python。以下是该网站的链接,该网站提供了有关如何运行的出色示例和教程: http://pypi.python .org/pypi/virtualenv
I use virtualenv to keep track of different environments I need for my projects. I may setup django 1.0 in one environment or django 1.2 for another. You can use it to set which version of python you'd like to use in a particular environment as well. Here's the link to the site which has great samples and tutorials for how to get running: http://pypi.python.org/pypi/virtualenv
您不必使用完整路径。
这能回答你的问题吗?
You don't have to use the full path.
Does that answer your question?
安装多个解释器版本
node-build
是安装多个 Node 版本的常用工具。node-build
安装:node-build
用法:python-build
是安装多个Python版本的常用工具。python-build
安装:python-build
用法:管理多个解释器版本
rvm
、rbenv
和chruby
是管理多个 Ruby 版本的常用工具。他们启发了nvm
、nodenv
和chnode
,它们是管理多个 Node 版本的等效工具。他们还启发了pyenv
和chpython
,它们是用于管理多个 Python 版本的等效工具(没有与rvm
等效的工具)据我所知)。调用 Ruby 命令时(
ruby
、irb
、)自动切换位于已安装 Ruby 版本的
、bin
目录中的目标可执行文件rakegem
、…)根据当前或最近父目录的 .ruby-version 文件中定义的 Ruby 版本,这些工具使用不同的策略(从最重到最轻) ):rvm
通过重新定义cd
命令,在每次调用cd
命令之前更新PATH
环境变量;rbenv
通过执行代理可执行文件 (垫片);chruby
在每次调用命令之前更新PATH
环境变量,方法是执行使用preexec_functions
(对于 Zsh)和PROMPT_COMMAND 挂钩到 shell 的函数
用于 Bash。rvm
策略的缺点是它是侵入性的且缓慢。rbenv
策略的缺点是它很复杂,并且需要在每次安装 Ruby 版本或 Ruby 包(gem< /em>) 提供可执行文件。chruby
策略不存在这些问题,因此chruby
是推荐的工具。chnode
安装:chnode
用法:chpython
安装:chpython
用法:Installing Multiple Interpreter Versions
node-build
is a common tool for installing multiple Node versions.node-build
installation:node-build
usage:python-build
is a common tool for installing multiple Python versions.python-build
installation:python-build
usage:Managing Multiple Interpreter Versions
rvm
,rbenv
, andchruby
are common tools for managing multiple Ruby versions. They inspirednvm
,nodenv
, andchnode
which are equivalent tools for managing multiple Node versions. They also inspiredpyenv
andchpython
which are equivalent tools for managing multiple Python versions (there is norvm
equivalent as far as I know).To automatically switch the targeted executables located in the
bin
directories of the installed Ruby versions when invoking a Ruby command (ruby
,irb
,rake
,gem
, …) based on the Ruby version defined in the .ruby-version file of the current or nearest parent directory, the tools use different strategies (from the heaviest to the lightest):rvm
updates thePATH
environment variable before each invocation of thecd
command by redefining thecd
command;rbenv
invokes the Ruby command in a dedicated environment with an updatedPATH
environment variable by executing a proxy executable (shim);chruby
updates thePATH
environment variable before each invocation of a command by executing a function hooked into the shell withpreexec_functions
for Zsh andPROMPT_COMMAND
for Bash.The drawback of the
rvm
strategy is that it is invasive and slow. The drawback of therbenv
strategy is that it is complex and requires shims to be regenerated (rehashed) at each installation of a Ruby version or Ruby package (gem) that provides an executable. Thechruby
strategy does not have those issues sochruby
is the recommended tool.chnode
installation:chnode
usage:chpython
installation:chpython
usage: