首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安装python后的.bash_profile设置

安装python后的.bash_profile设置
EN

Stack Overflow用户
提问于 2020-04-06 00:54:01
回答 1查看 592关注 0票数 0

我正在Mac (Catalina)上设置python环境。我已经安装了python3,并想通过输入"python“从终端启动它。

代码语言:javascript
复制
epipko@Eugenes-Mac ~ % python
Python 2.7.16 (default, Dec 13 2019, 18:00:32) 
[GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.32.4) (-macos10.15-objc-s on darwin
Type "help", "copyright", "credits" or "license" for more information.

epipko@Eugenes-Mac ~ % python3
Python 3.8.2 (v3.8.2:7b3ab5921f, Feb 24 2020, 17:52:18) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

我想为“.bash_profile”设置一个别名来打开python3,但是python不在那里。我已经创建了它并添加了别名,但我的别名不起作用

代码语言:javascript
复制
epipko@Eugenes-Mac ~ % ls -altr .bash_profile    
ls: .bash_profile: No such file or directory

epipko@Eugenes-Mac ~ % touch .bash_profile

epipko@Eugenes-Mac ~ % chmod 700 .bash_profile

epipko@Eugenes-Mac ~ % ls -altr .bash_profile 
-rwx------   1 epipko  staff     21 Apr  5 09:44 .bash_profile 

epipko@Eugenes-Mac ~ % cat .bash_profile
alias python=python3

另外,由于.bash_profile是在创建.bash_profile之前安装的,所以在python中是否缺少python特定的内容?我需要重新安装python吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-06 01:10:42

在单引号内设置别名,如下所示:

代码语言:javascript
复制
epipko@Eugenes-Mac ~ % cat .bash_profile
alias python='python3'

编辑-1:在文件中添加上述内容后,运行source ~/.bash_profilesource ~/.bash_aliasessource ~/.bashrc

例如:

代码语言:javascript
复制
$ python --version
Python 2.7.6
$ python3 --version
Python 3.8.2
$ alias python='python3'
$ python --version
Python 3.8.2

$ python
Python 3.8.2 (v3.8.2:7b3ab5921f, Feb 24 2020, 17:52:18)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61046131

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档