解决pip指向问题
因为python2和python3版本不兼容的原因,所以很多系统上避免不了转python2 和python3. pip 很容易指向同一个。在我的电脑上,pip和pip3 都指向了python3. 为了让pip指向python2, pip3 指向python3.需要做一些简单的修改;
查看pip 目录
which pip
一般情况下会显示:
/usr/local/bin/pip
编辑修改pip文件
vim /usr/local/bin/pip
我们可以看到如下:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from pip import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
```
将第一行 #!/usr/bin/python3 修改为
```
#!/usr/bin/python2
```
然后pip 就指向python2了
### 如果电脑上,pip和pip3 都指向了python2. 为了让pip指向python2, pip3 指向python3.需要做一些简单的修改;
#### 1、查看python3 pip3路径
```
which python3
which pip3
```
修改pip3文件
```
sudo vim /usr/local/bin/pip3
```
![image.png](https://upload-images.jianshu.io/upload_images/5110710-58143544d4638a59.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
```
#!/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
# EASY-INSTALL-ENTRY-SCRIPT: 'pip==20.3.3','console_scripts','pip3'
__requires__ = 'pip==20.3.3'
import re
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(
load_entry_point('pip==20.3.3', 'console_scripts', 'pip3')()
)
改成:
#!/usr/local/bin/python3
# EASY-INSTALL-ENTRY-SCRIPT: 'pip==20.3.3','console_scripts','pip3'
__requires__ = 'pip==20.3.3'
import re
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(
load_entry_point('pip==20.3.3', 'console_scripts', 'pip3')()
)