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/. 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. I'd love that when I type "python" this command point to the /new_version/ which I've installed. It would be also better if I can call 开发者_开发知识库this "new version" with another command, i.e. python2.
I tried changing the PYTHONPATH in the .bashrc but it didn't work.
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
.
Add the line
export PATH=/new_version/:$PATH
to your ~/.bashrc
(or ~/.bash_profile
) file. Then, whenever you run python
, it will find the new version first in your PATH
. Note this is PATH
, not PYTHONPATH
. See the comment by @Aaron.
Edit: Only do it this way if you want python
to point to the new version. Use an alias
as @cularis suggested if you want to call it something different, or make a symlink with:
ln -s /new_version/python /path/to/a/dir/you/add/to/your/path/newpython
Install virtualenv. With this you can easily set up different Python versions like that:
virtualenv -p /new_version/bin/python
Also, virtualenv enables you to easily install other Python packages via pip install
.
And finally, there's a package called tox which can automate testing with different Python versions...
精彩评论