为python3创建别名

编程入门 行业动态 更新时间:2024-10-27 02:21:45
本文介绍了为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创建别名

本文发布于:2023-06-08 14:30:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/583099.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:别名

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!