【virtualenv】记录Mac上一次令人无语的python virtual environment安装
首先用sudo /usr/bin/easy_install virtualenv时,报了错:
File "build/bdist.macosx-10.15-x86_64/egg/zipp.py", line 240
def open(self, mode='r', *args, pwd=None, **kwargs):
^
SyntaxError: invalid syntax
zip_safe flag not set; analyzing archive contents...
Removing /Library/Python/2.7/site-packages/zipp-0.0.0-py2.7.egg
Copying zipp-0.0.0-py2.7.egg to /Library/Python/2.7/site-packages
zipp 0.0.0 is already the active version in easy-install.pth
Installed /Library/Python/2.7/site-packages/zipp-0.0.0-py2.7.egg
error: The 'zipp>=0.4' distribution was not found and is required by importlib-resources
pkg_resources.DistributionNotFound: The 'zipp>=0.4' distribution was not found and is required by importlib-resources
(以及不死心的试了一下virtualenv命令果然获得了-bash: vritualenv: command not found)
然后就开始艰辛的查资料改错过程……
先试了sudo pip3 install virtualenv,结果报了错,说是有个东西已经安装了,而且更tm坑的是没法覆盖安装
Installing collected packages: filelock, virtualenv
Attempting uninstall: filelock
Found existing installation: filelock 2.0.12
ERROR: Cannot uninstall 'filelock'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
行吧,那就……新老共存……
sudo pip3 install virtualenv --ignore-installed
当看到:
Successfully installed appdirs-1.4.4 distlib-0.3.1 filelock-3.0.12 importlib-metadata-2.0.0 importlib-resources-3.0.0 six-1.15.0 virtualenv-20.0.33 zipp-3.3.0
留下了感动的泪水
结果试了试virtualenv命令,又报错:
pkg_resources.DistributionNotFound: The 'zipp>=0.4' distribution was not found and is required by importlib-resources
那那那……全部推倒重来安装一下python算了……
--------------------------------------------------------
先升级一下hombrew:brew update && brew upgrade
得到了错误:
git: 'credential-osxkeychain' is not a git command. See 'git --help'.
fatal: could not read Username for 'https://github.com': terminal prompts disabled
我:???
所幸用了:git config --global --d url."[email protected]:".insteadOf "https://github.com/"解决了这个问题
然后再运行一次:
brew update && brew upgrade
显示:
Warning: Permanently added the RSA host key for IP address '马赛克一下我的ip' to the list of known hosts.
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Error: Fetching /usr/local/Homebrew failed!
Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core failed!
homebrew/homebrew-science does not exist! Run `brew untap homebrew/homebrew-science` to remove it.
那他既然提示妖untap那就跟着他来呗:brew untap homebrew/homebrew-science
再接着:
sudo chown -R 这里填我的用户名:staff *
(如果你不知道谁在用的话就用whoami命令看看是谁)
(啧啧,连自己是谁都不记得了,你这台破电脑是想造反吗?!)
接着:
brew doctor
(哎,病入膏肓)
发现git过时了,那就brew upgrade git一下
最后搞完homebrew事项之后,大扫除一下:brew cleanup
------------------------------------------------------------
ok,终于可以安装一下python了!
brew install python
然后link一下安装的python:brew link [email protected]
妹想到居然报错:Error: Could not symlink
行吧,根据提示
To force the link and overwrite all conflicting files:
brew link --overwrite [email protected]
To list all files that would be deleted:
brew link --overwrite --dry-run [email protected]
就试试前面那个吧: brew link --overwrite [email protected]
结果报了新的错:Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks
这是什么鬼畜的错误?!!!
我不信我sudo一下你还得瑟!!
sudo brew link --overwrite [email protected]
得到:
Error: Running Homebrew as root is extremely dangerous and no longer supported.
其实是因为没有找到usr/local/Frameworks,那就自创然后修改它的权限:
sudo mkdir /usr/local/Frameworks
以及:
sudo chown $(whoami):admin /usr/local/Frameworks
然后再试试:brew link --overwrite [email protected]
显示:Linking /usr/local/Cellar/[email protected]/3.8.5... 5 symlinks created
这个问题解决了!
export PATH="/usr/local/opt/python/libexec/bin:$PATH"
pip install virtualenv
pip install virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Git
source /usr/local/bin/virtualenvwrapper.sh
一路顺风顺水直到最后一个source /usr/local/bin/virtualenvwrapper.sh时又出现了错误:
-bash: /usr/local/bin/virtualenvwrapper.sh: No such file or directory
这台电脑八百年没用过python了,先切换到管理员模式,
sudo su
(接下来它会让你输入密码,乖乖输入就是了)
然后
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
再:pip install virtualenv
pip install virtualenvwrapper
这时候试试virtualenv命令已经ok了,查一下version:
virtualenv --version
能够正确显示。
退出管理员模式:ctrl+d
输入命令:mkvirtualenv test
又又又报错……
/usr/local/bin/python3: Error while finding module specification for 'virtualenvwrapper.hook_loader' (ModuleNotFoundError: No module named 'virtualenvwrapper')
先看看python和python3在哪里:
which python
which python3
然后输入这个
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
或者
export VIRTUALENVWRAPPER_PYTHON=$(which python3)
再看看virtualenvwrapper.sh到底在哪里:
which virtualenvwrapper.sh
会返回一个位置。记住!很重要!(苦笑)
source 这里写文件所在的位置/virtualenvwrapper.sh
好了,现在再试试mkvirtualenv吧!
mkvirtualenv test
显示:created virtual environment CPython3.6.3.final.0-64 in 479ms
不错,再activate一下:
activate
并且查看一下:
pip list
显示:
Package Version
---------- -------
pip 20.2.3
setuptools 50.3.0
wheel 0.35.1
到此为止所有问题都解决了!