我开始学习Django框架,所以我需要在我的Mac上安装最新的Python、pip、virtualenv和Django包。我尝试使用brew安装,但是遇到一些奇怪的问题。
首先,Python3安装在/Library/Frameworks/Python.framework目录下而不是/usr/bin/。
但是当我尝试创建虚拟环境时,出现了以下错误:
为什么要使用 /Library/Frameworks/Python.framework/?为什么在 /usr/local/bin/virtualenv 中搜索 virtualenv?在 MacOS 上编码总是那么痛苦吗?
首先,Python3安装在/Library/Frameworks/Python.framework目录下而不是/usr/bin/。
$ which python
/usr/bin/python
$ which python3
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
对我来说很奇怪,因为每个教程都只提到了 /usr/bin/python37,而没有提到 /Library/Frameworks/Python.framework。这样可以吗?
之后我执行了 sudo pip3 install virtualenv
命令,得到了以下回答:
The directory '/Users/user/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/user/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
好的,我使用-H sudo标志进行了卸载和安装:
Installing collected packages: virtualenv
Successfully installed virtualenv-16.4.3
但是当我尝试创建虚拟环境时,出现了以下错误:
$ virtualenv venv
-bash: /usr/local/bin/virtualenv: No such file or directory
检查 virtualenv 位置:
$ which virtualenv
/Library/Frameworks/Python.framework/Versions/3.7/bin/virtualenv
为什么要使用 /Library/Frameworks/Python.framework/?为什么在 /usr/local/bin/virtualenv 中搜索 virtualenv?在 MacOS 上编码总是那么痛苦吗?
VIRTUALENVWRAPPER_PYTHON=/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
。 - Max