mac上通过brew包管理器安装pyth

2023-01-31 01:01:54 安装 管理器 Mac

Mac上通过brew包管理器安装python3.6

缘由:

最近在学习pythonTDD(测试驱动开发时)遇到了一个问题,根据指导需要使用Django1.12版本,但是在跑服务启动命令

Python manage.py runserver

的时候,出现了如下的报错:

 File "<frozen importlib._bootstrap>", line 1006, in _GCd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/robot/.virtualenvs/superlists/lib/python3.7/site-packages/djanGo/contrib/admin/__init__.py", line 4, in <module>
    from django.contrib.admin.filters import (
  File "/Users/robot/.virtualenvs/superlists/lib/python3.7/site-packages/django/contrib/admin/filters.py", line 10, in <module>
    from django.contrib.admin.options import IncorrectLookupParameters
  File "/Users/robot/.virtualenvs/superlists/lib/python3.7/site-packages/django/contrib/admin/options.py", line 13, in <module>
    from django.contrib.admin import helpers, widgets
  File "/Users/robot/.virtualenvs/superlists/lib/python3.7/site-packages/django/contrib/admin/widgets.py", line 152
    '%s=%s' % (k, v) for k, v in params.items(),
    ^
SyntaxError: Generator expression must be parenthesized

后来搜索后发现了时python(3.7)和Django(1.12)版本之间的兼容问题,网络上给出的解决方案是安装python3.6。
由于之前使用brew进行包管理和软件安装的,所以想偷个懒。继续使用brew安装python3.6,通过搜索网络获得如下解决方案,原解决方案是:Homebrew: Rollback from Python 3.7 to Python 3.6.5.x? - Ask Different

解决方案

具体的操作步骤是:

brew unlink python
brew install https://raw.GitHubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/FORMula/python.rb

感悟:

因为之前没有安装python3.6所以在使用一些help的brew switch时并不生效,
根据观察,使用 brew switch命令时,brew回去cell目录中去找,但是由于之前就没安装过,所以自然会失败。

相关文章