Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
145 views
in Technique[技术] by (71.8m points)

python - creating an alias for python3

I have python2.6.6 installed in my system. Now I am trying to use python3 while keeping all the python2.6.6 untouched in /usr/bin/. I am able to install python3 in /opt/python35/bin/. By adding export PATH=/opt/python35/bin/:$PATH to the ~/.bashrc file, I am able to access python3 anywhere in my console.

My question is: how could I set an alias (python) for python3 so that, whenever I issue command "python", python3 in /opt/python35/bin/ could be used? I simply couldn't remove python2.6.6 in my system due to some already installed programs in my system.

My current approach is to add a line in the ~/.bashrc file, alias python = "/opt/python35/bin/python3" or simply alias python = "python3". However, when I reload this ~/.bashrc file, I got the following error:

$ source ~/.bash_profile
bash: alias: python: not found
bash: alias: =: not found
bash: alias: /opt/python35/bin/python3: not found

Does anybody know where my problem is? Thanks in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Spaces are not allowed next to the equal sign when declaring aliases.

Use

alias python=python3

and it should work.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...