为python3创建别名 [英] creating an alias for python3

查看:243
本文介绍了为python3创建别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的系统中安装了python2.6.6.现在,我尝试使用python3,同时保持/usr/bin/中所有python2.6.6不变.我可以在/opt/python35/bin/中安装python3.通过将export PATH=/opt/python35/bin/:$PATH添加到〜/.bashrc文件,我可以在控制台的任何位置访问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.

我的问题是:如何为python3设置别名(python),以便每当发出命令"python"时,都可以使用/opt/python35/bin/中的python3?由于系统中已经安装了某些程序,因此我无法删除python2.6.6.

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.

我当前的方法是在〜/.bashrc文件中添加一行,alias python = "/opt/python35/bin/python3"或只是alias python = "python3".但是,当我重新加载〜/.bashrc文件时,出现以下错误:

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!

推荐答案

声明别名时,等号旁边不允许有空格.

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

使用

alias python=python3

它应该可以工作.

这篇关于为python3创建别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆