mac matplotlib 入らない

そのままです。
結構長い時間、mac matplotlib 入らない で悩んでいました。ググってもなかなか見つからず
ちなみに私の環境は

そんな時に出会った記事の追記
qiita.com

ということで実行
でもうまくいかず。

しかし、時間をおいたらできました。なぜだろう。

zsh: command not found: condaへの対応

環境はMac Big Sur

% sw_vers
ProductName:	macOS
ProductVersion:	11.0.1
BuildVersion:	20B29
% echo "source /opt/anaconda3/etc/profile.d/conda.sh" >> ~/.zshrc

そして、一回ターミナルを閉じてもう一回開くと

% conda -V
conda 4.9.2

無事できた!
anacondaは、デフォルトで/opt/anaconda3/にインストールされるようです。

pyenv install でエラーが出た時の対処法

Pythonの開発環境を用意しよう!(Mac) | プログラミングの入門なら基礎から学べるProgate[プロゲート]

これを見ながら進めていましたが、エラーが出てしましました。

% pyenv install 3.6.5

python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-3.6.5.tar.xz...
-> https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz
Installing Python-3.6.5...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk

BUILD FAILED (OS X 11.0.1 using python-build 20180424)

Inspect or clean up the working tree at /var/folders/fz/v6d_5ykj1x1b8w9c9l6dmysm0000gn/T/python-build.20201116203917.79838
Results logged to /var/folders/fz/v6d_5ykj1x1b8w9c9l6dmysm0000gn/T/python-build.20201116203917.79838.log

Last 10 log lines:
./Modules/posixmodule.c:8210:15: error: implicit declaration of function 'sendfile' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        ret = sendfile(in, out, offset, &sbytes, &sf, flags);
              ^
./Modules/posixmodule.c:10432:5: warning: code will never be executed [-Wunreachable-code]
    Py_FatalError("abort() called from Python code didn't abort!");
    ^~~~~~~~~~~~~
1 warning and 1 error generated.
make: *** [Modules/posixmodule.o] Error 1
make: *** Waiting for unfinished jobs....
1 warning generated.

対処法

% CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" \
pyenv install --patch 3.6.5 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)

とすることでした。3.6.5は、入れたいpythonのバージョンに変えてください。

% CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" \
pyenv install --patch 3.6.5 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)

python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-3.6.5.tar.xz...
-> https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz
Installing Python-3.6.5...
patching file Misc/NEWS.d/next/macOS/2020-06-24-13-51-57.bpo-41100.mcHdc5.rst
patching file configure
Hunk #1 succeeded at 3369 (offset -57 lines).
patching file configure.ac
Hunk #1 succeeded at 495 (offset -15 lines).
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.6.5 to /Users/haruka/.pyenv/versions/3.6.5

参考:
Unable to build Python on macOS Big Sur with Xcode 12 beta · Issue #1643 · pyenv/pyenv · GitHub

大きめのデータをインポートする場合は、pythonプログラム書いて入れたほうが安定する。

表題の件、プログラム書いたほうが安定します。
ということで書いておきます。

'''
Created on Nov 15, 2020

@author: haruka
'''
#DB
import mysql.connector
import pandas as pd
import math
import datetime

dt_now = datetime.datetime.now()
nowdatetime = dt_now.strftime('%Y/%m/%d %H:%M:%S')
print(nowdatetime)

dbh = mysql.connector.connect(
    host='■■■ホスト■■■',
    port='3306',
    db='■■■DB名■■■',
    user='■■■ユーザ名■■■',
    password='■■■パスワード■■■',
    charset='utf8'
)
cur = dbh.cursor()

dfs = pd.read_csv('■■■csvファイルpath■■■')
print(dfs)

for index, row in dfs.iterrows():
    sql = "■■■INSERT INTO `receipts`(`id`, ~, `created`, `modified`) VALUES (null,■■■"#sqlのVALUES あたりまで記入
    for df in dfs:
        #print(df + ":" +str(row[df]))
        #print(str(row[df]) == 'nan')
        if str(row[df]) == 'nan':
            sql = sql + "null, "
        else:
            #print(isinstance(row[df], int) or isinstance(row[df], float))
            if isinstance(row[df], int) or isinstance(row[df], float):
                sql = sql + str(row[df]) + ", "
            else:
                sql = sql + "'" +str(row[df]) + "', "
    sql = sql + "'" + nowdatetime + "', '" + nowdatetime + "')"#createdとmodified用
    #print(sql)

    try :
        cur.execute(sql)
        dbh.commit()
    except :
        print(sql)

pyOCRで画像データ認識

macで環境準備

$ sudo pip install pyocr
$ brew install tesseract
$ ls /usr/local/Cellar/tesseract/4.1.1/share/tessdata/
$ wget https://github.com/tesseract-ocr/tessdata/raw/4.00/jpn.traineddata
$ mv jpn.traineddata /usr/local/Cellar/tesseract/4.1.1/share/tessdata/


参考
Mac環境でpyOCRで画像データをテキスト化する - Qiita