A memo corresponding to Django's runserver moss in Python 2.7.11 entered with Homebrew

As of December 26, 2015, if you install Python 2.x series with homebrew, 2.7.10 named 2.7.11 will be installed. This 2.7.11 has some bugs and some modules such as Django don't work well.

After installing Django

python manage.py runserver

Then

Traceback (most recent call last):
  File "manage.py", line 8, in <module>
    from django.core.management import execute_from_command_line
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 10, in <module>
    from django.apps import apps
  File "/usr/local/lib/python2.7/site-packages/django/apps/__init__.py", line 1, in <module>
    from .config import AppConfig
  File "/usr/local/lib/python2.7/site-packages/django/apps/config.py", line 5, in <module>
    from django.utils._os import upath
  File "/usr/local/lib/python2.7/site-packages/django/utils/_os.py", line 5, in <module>
    import tempfile
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 32, in <module>
    import io as _io
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in <module>
    import _io
ImportError: dlopen(/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder
  Referenced from: /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
  Expected in: flat namespace
 in /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so

Is that? ?? ?? I get an error. Aside from the details, it seems that it is due to a bug in Python 2.7.11, so I would like to downgrade to 2.7.10. .. ..

Homebrew cannot downgrade the manners version

brew search <package_name>

It seems that you can select the version as long as it can be searched with, but there seems to be no way to install and sort Python 2.7.10 and 2.7.11. Then what should we do?

Edit Formula directly

I thought about various methods, but decided to edit Formula directly. Delete python once.

brew remove python

The Formula remains, so edit it.

brew edit python

Edit the version.

class Python < Formula
  desc "Interpreted, interactive, object-oriented programming language"
  homepage "https://www.python.org"
  head "https://hg.python.org/cpython", :using => :hg, :branch => "2.7"
-  url "https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz"
+  url "https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz"

In brew edit, vi starts, so edit it normally and save it. After saving, try install again.

brew install python

Then, of course, there will be a SHA256 mismatch.

==> Downloading https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz
######################################################################## 100.0%
Error: SHA256 mismatch
Expected: 82929b96fd6afc8da838b149107078c02fa1744b7e60999a8babbc0d3fa86fc6
Actual: eda8ce6eec03e74991abb5384170e7c65fcd7522e409b8e83d7e6372add0f12a
Archive: /Library/Caches/Homebrew/python-2.7.10.tgz
To retry an incomplete download, remove the file above.

Since Actual is the actual code, copy it and set it again as the expected value of the Formula.

class Python < Formula
  desc "Interpreted, interactive, object-oriented programming language"
  homepage "https://www.python.org"
  head "https://hg.python.org/cpython", :using => :hg, :branch => "2.7"
  url "https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz"
+  sha256 "eda8ce6eec03e74991abb5384170e7c65fcd7522e409b8e83d7e6372add0f12a"

Now run install again.

brew install python

It looks like Python 2.7.10 has been successfully installed.

try runserver

Now let's try to start the test server.

python manage.py runserver

It seems to have started successfully.

Recommended Posts

A memo corresponding to Django's runserver moss in Python 2.7.11 entered with Homebrew
A memo connected to HiveServer2 of EMR with python
I want to work with a robot in python.
[Python] A memo to write CSV vertically with Pandas
How to develop in a virtual environment of Python [Memo]
Create a message corresponding to localization with python translation string
[Python] A memo that I tried to get started with asyncio
[Python] A memo to operate ROM created by GBDK with PyBoy
How to create a heatmap with an arbitrary domain in Python
Spiral book in Python! Python with a spiral book! (Chapter 14 ~)
Try logging in to qiita with Python
Convert memo at once with Python 2to3
Memo to ask for KPI with python
A memo with Python2.7 and Python3 on CentOS
How to work with BigQuery in Python
How to get a stacktrace in python
To work with timestamp stations in Python
A memo organized by renaming the file names in the folder with python
A memo that allows you to change Pineapple's Python environment with pyenv
How to read a CSV file with Python 2/3
Send a message to LINE with Python (LINE Notify)
[Python] Get the files in a folder with Python
Try to calculate a statistical problem in Python
[REAPER] How to play with Reascript in Python
How to clear tuples in a list (Python)
A memo that I wrote a quicksort in Python
To execute a Python enumerate function in JavaScript
How to embed a variable in a python string
Convert PDFs to images in bulk with Python
[Python] Created a class to play sin waves in the background with pyaudio
I want to create a window in Python
Ported a naive homebrew language compiler to Python
How to create a JSON file in Python
Try to draw a life curve with python
I want to make a game with Python
How to drop Google Docs in one folder in a .txt file with python
Create a virtual environment with conda in Python
I wanted to install Python 3.4.3 with Homebrew + pyenv
A memo about writing merge sort in Python
[Memo] I tried a pivot table in Python
Try to make a "cryptanalysis" cipher with Python
A clever way to time processing in Python
Log in to Yahoo Business with Selenium Python
Decide to assign a laboratory with Python (fiction)
A memo when creating a python environment with miniconda
Steps to create a Twitter bot with python
To add a module to python put in Julialang
How to notify a Discord channel in Python
How to use tkinter with python in pyenv
Work in a virtual environment with Python virtualenv.
Create a new page in confluence with Python
Try to make a dihedral group with Python
Searching for an efficient way to write a Dockerfile in Python with poetry
[Python] How to draw a histogram in Matplotlib
I want to write to a file with Python
A layman wants to get started with Python
How to get a list of files in the same directory with python
Run the output code with tkinter, saying "A, pretending to be B" in python
How to identify the element with the smallest number of characters in a Python list?
A memo when checking whether the specified key exists in the defined dictionary with python
I got stuck when trying to specify a relative path with relative_to () in python