Mysticbinary

macOS命令行切换Python版本


brew安装anaconda3

brew cask install anaconda3

安装之后打开路径查看:/usr/local/anaconda3/bin

anaconda3环境变量设置

vim ~/.zshrc

export PATH=/usr/local/anaconda3/bin:$PATH

source ~/.zshrc

验证

conda --version
# 看到版本好就成功了

安装双版本

conda create --name python2 python=2.7

conda create --name python3 python=3.7

查看目录 /usr/local/anaconda3/envs/

命令后切换python环境

# 查看本地的py环境
➜  ~ conda info -e
# conda environments:
#
base                  *  /usr/local/anaconda3
python2                  /usr/local/anaconda3/envs/python2
python27                 /usr/local/anaconda3/envs/python27
python3                  /usr/local/anaconda3/envs/python3

# 进入py版本
➜  ~ source activate python27
(python27) ➜  ~

# 退出py版本
conda deactivate

pip

进入py版本之后,有时候不知道pip把安装包安装到哪里了,用这个方法很好使:

(python27) ➜  ~ python
Python 2.7.18 |Anaconda, Inc.| (default, Apr 23 2020, 17:44:47)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> import requests
>>> requests
<module 'requests' from '/usr/local/anaconda3/envs/python27/lib/python2.7/site-packages/requests/__init__.pyc'>


/usr/local/anaconda3/envs/python27/lib/python2.7/site-packages/requests/ 就是了。

ide vscode set

参考

https://www.cnblogs.com/zhoulin1234/p/9893055.html
https://blog.csdn.net/ninnyyan/article/details/80485507

posted on 2020-05-05 09:54  Mysticbinary  阅读(942)  评论(0编辑  收藏  举报

导航