记录bug:
firefox启动失败;操作:firefox -profilemanager 在出现的界面中删掉已有的错误程序
起因:想一键delete重来,but.... 。pip install Django时显示python3.7版本缺少了很多文件。于是我想卸载了当前的python重新安装一个。
1. 查看python版本(网友总结的):
Mac系统自带python路径为/System/Library/Frameworks/Python.framework/Version
这里可能会有多个python版本,里面Current存放系统当前python版本,进入Current/bin
,在终端输入./python --version
即可查看系统当前python版本(注:若使用python --version
命令是查看用户当前python版本而不是系统python版本)HomeBrew安装python路径为/usr/local/Cellar/python
里面存放HomeBrew所安装版本。进入2.7.13/bin
,在终端输入./python --version
即可查看用户当前使用的python版本。如果使用brew工具正确安装python的情况下,用户当前python版本会是新安装的python系统命令默认路径在/usr/bin
,用户命令默认路径在/usr/local/bin
(brew安装的命令默认在这个路径下)。如果存在相同的命令,则会依据/etc/paths
文件中的环境变量顺序(前面优先于后面)依次查找,查看环境变量也可以在终端输入echo $PATH
查看,遵循左面路径优先于右面路径。
3. 安装Xcode,使用homebrew安装python
一波delete操作,如/Library/Frameworks/Python.framework/Version/python3.7,如PATH,如brew cleanup
---------- install a new python------------
baonanadeMacBook-Pro-2:xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
baonanadeMacBook-Pro-2:xcode-select --update
xcode-select: error: invalid argument '--update'
baonanadeMacBook-Pro-2:xcode-select -v
xcode-select version 2354.
baonanadeMacBook-Pro-2:bin nanabao$ xcode-select -p
/Library/Developer/CommandLineTools
baonanadeMacBook-Pro-2:brew doctor
/usr/local/Homebrew/Library/Homebrew/global.rb:12:in `require': cannot load such file -- active_support/core_ext/object/blank (LoadError)
from /usr/local/Homebrew/Library/Homebrew/global.rb:12:in `<top (required)>'
from /usr/local/Homebrew/Library/Homebrew/brew.rb:23:in `require_relative'
from /usr/local/Homebrew/Library/Homebrew/brew.rb:23:in `<main>'
baonanadeMacBook-Pro-2:bin nanabao$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
“此处略去很多安装提示”
==> Installation successful!
==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
https://docs.brew.sh/Analytics
==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
https://github.com/Homebrew/brew#donations
==> Next steps:
- Run `brew help` to get started
- Further documentation:
https://docs.brew.sh
baonanadeMacBook-Pro-2:bin nanabao$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!
Warning: Your Xcode (10.2.1) is outdated.
Please update to Xcode 11.3 (or delete it).
Xcode can be updated from the App Store.
Warning: Broken symlinks were found. Remove them with `brew cleanup`:
/usr/local/Frameworks/Python.framework/Versions/3.7
Warning: Some installed formulae are missing dependencies.
You should `brew install` the missing dependencies:
brew install python
Run `brew missing` for more details.
"消灭了所有warning"
baonanadeMacBook-Pro-2:/ nanabao$ brew doctor
Your system is ready to brew.
尝试后,我大概知道了是Xcode版本不够新,需要从app store去更新。然鹅,电脑空间不够了,于是删掉了Matlab,QQ,Wechat(心痛)。更新了Xcode和系统,xcode-select version 2373.
python --version
Python 2.7.16
baonanadeMacBook-Pro-2:/ nanabao$ brew search python3
==> Formulae
boost-python3 python3 ✔ python@3 ✔ python@3.8
If you meant "python3" specifically:
It was migrated from homebrew/cask to homebrew/core.
baonanadeMacBook-Pro-2:/ nanabao$ brew install python3
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/cask).
No changes to formulae.
Warning: python 3.7.6_1 is already installed and up-to-date
To reinstall 3.7.6_1, run `brew reinstall python`
baonanadeMacBook-Pro-2:/ nanabao$ python3
Python 3.7.6 (default, Dec 30 2019, 19:38:28)
[Clang 11.0.0 (clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
baonanadeMacBook-Pro-2:/ nanabao$ which python3
/usr/local/bin/python3
baonanadeMacBook-Pro-2:/ nanabao$ python --version
Python 2.7.16
baonanadeMacBook-Pro-2:/ nanabao$ ls /usr/local/Frameworks/
Python.framework
baonanadeMacBook-Pro-2:/ nanabao$ brew info python3
python: stable 3.7.6 (bottled), HEAD
Interpreted, interactive, object-oriented programming language
https://www.python.org/
/usr/local/Cellar/python/3.7.6_1 (3,978 files, 60.8MB) *
Poured from bottle on 2020-02-12 at 09:11:11
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/python.rb
==> Dependencies
Build: pkg-config ✔
Required: gdbm ✔, openssl@1.1 ✔, readline ✔, sqlite ✔, xz ✔
==> Options
--HEAD
Install HEAD version
==> Caveats
Python has been installed as
/usr/local/bin/python3
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/usr/local/opt/python/libexec/bin
You can install Python packages with
pip3 install <package>
They will install into the site-package directory
/usr/local/lib/python3.7/site-packages
See: https://docs.brew.sh/Homebrew-and-Python
==> Analytics
install: 437,475 (30 days), 1,438,863 (90 days), 5,649,427 (365 days)
install-on-request: 229,616 (30 days), 726,920 (90 days), 2,824,192 (365 days)
build-error: 0 (30 days)
baonanadeMacBook-Pro-2:/ nanabao$ vim ~/.bash_profile
baonanadeMacBook-Pro-2:/ nanabao$ source ~/.bash_profile
baonanadeMacBook-Pro-2:/ nanabao$ python -v
import _frozen_importlib # frozen
import _imp # builtin
import '_thread' # <class '_frozen_importlib.BuiltinImporter'>
import '_warnings' # <class '_frozen_importlib.BuiltinImporter'>
import '_weakref' # <class '_frozen_importlib.BuiltinImporter'>
# installing zipimport hook
import 'zipimport' # <class '_frozen_importlib.BuiltinImporter'>
# installed zipimport hook
”此处省去很多提示,竟然进入了python环境“
>>>exit()
环境变量的修改如下:
# The original version is saved in .bash_profile.pysave
PATH=/usr/local/Cellar/python/3.7.6_1/bin:${PATH}
export PATH
alias python="/usr/local/bin/python3"
python --version
Python 3.7.6
“OK"
接下来安装Django
baonanadeMacBook-Pro-2:/ nanabao$ pip3 install django
Collecting django
Downloading https://files.pythonhosted.org/packages/c6/b7/63d23df1e311ca0d90f41352a9efe7389ba353df95deea5676652e615420/Django-3.0.3-py3-none-any.whl (7.5MB)
|█▌ | 358kB 2.6kB/s eta 0:45:09ERROR: Exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py", line 425, in _error_catcher
yield
File "/usr/local/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py", line 507, in read
data = self._fp.read(amt) if not fp_closed else b""
File "/usr/local/lib/python3.7/site-packages/pip/_vendor/cachecontrol/filewrapper.py", line 62, in read
data = self.__fp.read(amt)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 457, in read
n = self.readinto(b)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 501, in readinto
n = self.fp.readinto(b)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 589, in readinto
return self._sock.recv_into(b)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1071, in recv_into
return self.read(nbytes, buffer)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 929, in read
return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/pip/_internal/cli/base_command.py", line 153, in _main
status = self.run(options, args)
File "/usr/local/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 382, in run
resolver.resolve(requirement_set)
File "/usr/local/lib/python3.7/site-packages/pip/_internal/legacy_resolve.py", line 201, in resolve
self._resolve_one(requirement_set, req)
File "/usr/local/lib/python3.7/site-packages/pip/_internal/legacy_resolve.py", line 365, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install)
File "/usr/local/lib/python3.7/site-packages/pip/_internal/legacy_resolve.py", line 313, in _get_abstract_dist_for
req, self.session, self.finder, self.require_hashes
File "/usr/local/lib/python3.7/site-packages/pip/_internal/operations/prepare.py", line 194, in prepare_linked_requirement
progress_bar=self.progress_bar
File "/usr/local/lib/python3.7/site-packages/pip/_internal/download.py", line 465, in unpack_url
progress_bar=progress_bar
File "/usr/local/lib/python3.7/site-packages/pip/_internal/download.py", line 316, in unpack_http_url
progress_bar)
File "/usr/local/lib/python3.7/site-packages/pip/_internal/download.py", line 551, in _download_http_url
_download_url(resp, link, content_file, hashes, progress_bar)
File "/usr/local/lib/python3.7/site-packages/pip/_internal/download.py", line 253, in _download_url
hashes.check_against_chunks(downloaded_chunks)
File "/usr/local/lib/python3.7/site-packages/pip/_internal/utils/hashes.py", line 80, in check_against_chunks
for chunk in chunks:
File "/usr/local/lib/python3.7/site-packages/pip/_internal/download.py", line 223, in written_chunks
for chunk in chunks:
File "/usr/local/lib/python3.7/site-packages/pip/_internal/utils/ui.py", line 160, in iter
for x in it:
File "/usr/local/lib/python3.7/site-packages/pip/_internal/download.py", line 212, in resp_read
decode_content=False):
File "/usr/local/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py", line 564, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "/usr/local/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py", line 529, in read
raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/local/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py", line 430, in _error_catcher
raise ReadTimeoutError(self._pool, None, "Read timed out.")
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
查找错误,修改错误
baonanadeMacBook-Pro-2:/ nanabao$ pip3 -V
pip 19.3.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
baonanadeMacBook-Pro-2:/ nanabao$ pip -V
-bash: pip: command not found
[Mac 下 PostgreSQL 的安装与使用]
修改 "/usr/local/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py"
在文件首加入
#!/usr/bin/env python3
仍然存在这个报错,使用下面的,
pip3 --default-timeout=100 install -U Django
根据进度条,我已经确定这是个网络不好的问题
baonanadeMacBook-Pro-2:urllib3 nanabao$ pip3 --default-timeout=100 install -U django
Collecting django
Downloading https://files.pythonhosted.org/packages/c6/b7/63d23df1e311ca0d90f41352a9efe7389ba353df95deea5676652e615420/Django-3.0.3-py3-none-any.whl (7.5MB)
|███ | 716kB 794bytes/s eta 2:21:28ERROR: Exception:
Traceback (most recent call last):
"省略“
于是使用源码安装方法 下载源码包:
Download Django | Djangowww.djangoproject.com![5a112e29692fa57cc278a2689d8f290e.png](https://i-blog.csdnimg.cn/blog_migrate/36692ebc929649b48ae4e625e2f8c2a2.png)
输入以下命令并安装:
tar xzvf Django-X.Y.tar.gz # 解压下载包
cd Django-X.Y # 进入 Django 目录
python setup.py install # 执行安装命令
等啊等啊等!一下午都没成功,卡在了
Installed /usr/local/lib/python3.7/site-packages/Django-3.1-py3.7.egg
Processing dependencies for Django==3.1
Searching for sqlparse>=0.2.2
Reading https://pypi.org/simple/sqlparse/
^Cinterrupted
baonanadeMacBook-Pro-2:django-master nanabao$
然后清了一下系统残留文件,删掉了一些替身文件(在磁盘上0字节),如idle3,python3,pip3,pydoc3,pyenv,pythob3-config。
然后将上一步命令换成python3.7 setup.py install
Using /usr/local/lib/python3.7/site-packages
Finished processing dependencies for Django==3.1
baonanadeMacBook-Pro-2:django-master nanabao$ python3.7
Python 3.7.6 (default, Dec 30 2019, 19:38:28)
[Clang 11.0.0 (clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.VERSION
(3, 1, 0, 'alpha', 0)
>>> django.get_version()
'3.1'