[英]Install a different version of Python
this might be a very simple question but I need your help.这可能是一个非常简单的问题,但我需要你的帮助。 I work in a network and I cannot install the programs I want.我在网络中工作,无法安装我想要的程序。 Anyway, I need to use another version of python, which is installed in the directory /new_version/.无论如何,我需要使用另一个版本的 python,它安装在目录 /new_version/ 中。 Now, when I type "python" in a shell (I use bash) the command point to the version of python installed in the machine I'm working with.现在,当我在 shell(我使用 bash)中键入“python”时,命令指向我正在使用的机器中安装的 python 的版本。 I'd love that when I type "python" this command point to the /new_version/ which I've installed.当我输入“python”时,我希望这个命令指向我已经安装的 /new_version/。 It would be also better if I can call this "new version" with another command, ie python2.如果我可以用另一个命令(即python2)调用这个“新版本”也会更好。
I tried changing the PYTHONPATH in the.bashrc but it didn't work.我尝试更改 .bashrc 中的 PYTHONPATH,但没有成功。
Add the line添加行
export PATH=/new_version/:$PATH
to your ~/.bashrc
(or ~/.bash_profile
) file.到您的~/.bashrc
(或~/.bash_profile
)文件。 Then, whenever you run python
, it will find the new version first in your PATH
.然后,每当您运行python
时,它都会首先在您的PATH
中找到新版本。 Note this is PATH
, not PYTHONPATH
.请注意,这是PATH
,而不是PYTHONPATH
。 See the comment by @Aaron.请参阅@Aaron 的评论。
Edit: Only do it this way if you want python
to point to the new version.编辑:只有在您希望python
指向新版本时才这样做。 Use an alias
as @cularis suggested if you want to call it something different, or make a symlink with:如果您想将其命名为不同的名称,请使用 @cularis 建议的alias
,或者使用以下符号链接:
ln -s /new_version/python /path/to/a/dir/you/add/to/your/path/newpython
alias newpython="/path/to/your/new_version/python"
Add this to your .bashrc
, you can then start the new python with newpython
and the standard one with python
.将此添加到您的.bashrc
,然后您可以使用 newpython 启动新的python
并使用newpython
启动标准的。
Install virtualenv .安装virtualenv 。 With this you can easily set up different Python versions like that:有了这个,您可以轻松地设置不同的 Python 版本,如下所示:
virtualenv -p /new_version/bin/python
Also, virtualenv enables you to easily install other Python packages via pip install
.此外,virtualenv 使您能够通过pip install
轻松安装其他 Python 包。
And finally, there's a package called tox which can automate testing with different Python versions...最后,还有一个名为tox的 package 可以自动使用不同的 Python 版本进行测试......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.