雑多な技術系メモ

自分用のメモ。内容は保証しません。よろしくお願いします。

python

firebaseでデプロイする際のエラーと対処

エラー === Deploying to 'test'... i deploying functions, hosting i functions: ensuring necessary APIs are enabled... ✔ functions: all necessary APIs are enabled i functions: preparing functions directory for uploading... Error: Error parsi…

ipythonの初期読み込みファイル

ipythonを起動したら自動的に読み込んでくれるファイルの場所は ~/.ipython/profile_default/startup/00-test.pyといった形で書く。 辞書順に読み込むため、番号で管理するとわかりやすい 例えば、test.py import sys, os import readline import json impor…

matplotlibで凡例をグラフ外の右上に出す

サンプルコード 省略 plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left', borderaxespad=0) # 右上に出す plt.subplots_adjust(left = 0.1, right = 0.7) # ここで、図がキャンバス内に収まるように調整する

pythonのElementTree(xmlファイル)で編集して、きれいに(改行をうまくして)保存する方法

サンプルコード from xml.dom import minidom 省略 xmlstr = minidom.parseString(ET.tostring(root)).toprettyxml(indent=" ") with open("xml.xml", "w") as f: f.write(xmlstr) 参考 https://stackoverflow.com/questions/28813876/how-do-i-get-pythons-…

【keras】keras のモデルの保存と読み込み

モデルの保存 # モデルの保存 json_model = model.to_json() with open("model.json", "w") as f json.dump(text, f) # パラメータの保存 model.save_weights("param.hdf5") 保存したモデルの読み込み from keras.models import model_from_json # モデルの…

【python】【xml】すでにあるxmlに要素を追加

サンプルコード import xml.etree.ElementTree as ET tree = ET.ElementTree(file="file.xml") # xmlを読み込む root = tree.getroot() element = ET.Element("vType") # 要素の作成 element.set("A", "a") # 属性の追加 root.insert(0, element) # 作成した…

oandpyのインストール

oandpyをpipでインストールする方法 pip install git+https://github.com/oanda/oandapy.git

【python】範囲を指定して、ランダムの整数を生成する

import random random.randint(a,b) # a以上b未満のランダムな整数を返す

ubuntuで、kivyインストール

環境 ubuntu16.04 python 3.4で動作 インストール方法 pip install Cython==0.26 pip install kivy

【python】範囲を指定して、ランダムの整数を生成する

import random random.randint(a,b) # a以上b未満のランダムな整数を返す

【python】dictオブジェクトをkeysでソート

以下コード例 import collections dct = {2:3, 1:89, 4:5, 3:0} new_dict = collections.OrderedDict(sorted(dct.items())) new_dict # => OrderedDict([(1, 89), (2, 3), (3, 0), (4, 5)]) new_dict.keys() # => odict_keys([1, 2, 3, 4]) new_dict.values(…

【python】matplotlibで軸をlogスケールにするとき

例:x軸と底が2の対数軸にしたい時には以下を追加する plt.xscale("log", basex=2)

【pyhton】指定したディレクトリにあるディレクトリ名一覧取得

import os paths = os.listdir(root_path)

エラー sqlite3.DatabaseError: database disk image is malformed

問題 実験を回して 次の日に確認したら、 以下のようなエラー文をはいてpythonが落ちていた。。。。 sqlite3.DatabaseError: database disk image is malformed 解決策(暫定) 暫定の解決法としては、 ~/.ipython/profile_default/history.sqlite を削除し、…

【python】【pytest】pytest のインストール

pip install pytest pip install pytest-cov

【python】【pytest】pytestでのエラーの対処

エラー usage: pytest [options] [file_or_dir] [file_or_dir] [...] pytest: error: unrecognized arguments: --cov=app --cov-report=html --cov-report=html 対処 以下のpytest-covをインストールしたら、エラーが解消された pip install pytest-cov

【python】カレントディレクトリのpathの追加

import os, sys print(os.getcwd()) sys.path.append(os.getcwd())

マルチエージェント深層強化学習のベンチマーク用のStarcraftをインストールして、サンプルを実行するまで

https://github.com/deepmind/pysc2/ のREADMEを参考に READMEにあるようにStarcraftをインストールする。 READMEにリンクされているBattle.netからStarcraftをインストールする この時にはログインが必要 デフォルトでc:/Program File(x86)/StarCraft Ⅱにイ…

ubuntu16.04でmongodにアクセス関連のメモ

下記のリンクに書いてあるように、mongod.serviceを作成する https://qiita.com/pelican/items/bb9b5290bb73acedc282 mongodbの起動 sudo mongodb 後は以下のコマンドでmongodbにアクセス mongo

pymongo.errors.OperationFailure: Authentication failed.

課題 pymongoから、mlabで作成したデータベースにアクセスしようとした際に 以下のようなエラー pymongo.errors.OperationFailure: Authentication failed. 対処 1. ユーザーを作成 以下を参考に、アカウントを自分で作ってみた http://sh-yoshida.hatenablo…

Failed building wheel for mpi4py

課題 mpi4pyをインストールしようとしたら、 pip install mpi4py <省略> Failed building wheel for mpi4py <省略> 上記のようなエラーが発生し、インストールできなかった。 対処 以下のようにlibopenmpi-devをインストールしたあとに、mpi4pyを再度インス…

Could not find a version that satisfies the requirement pkg-resources==0.0.0

エラー内容 pythonのwebアプリをherokuにデプロイしようとした際に以下のようなエラー. Could not find a version that satisfies the requirement pkg-resources==0.0.0 対処法 requirement.txtから pkg-resources==0.0.0 を削除した後に,もう一度push 参考…

Flask入門用サイトいつくか

Flask使ってWebアプリ作りたいと思って, 少し調べて,有用だと思ったサイト一覧 Flask入門 https://qiita.com/zaburo/items/5091041a5afb2a7dffc8 Flaskアプリをherokuにデプロイ https://qiita.com/sqrtxx/items/2ae41d5685e07c16eda5 https://qiita.com/msr…

ubuntuでEnegyPlusをインストールして、pythonで動かすまで

EnegyPlusのインストール方法 https://energyplus.net/downloads のLinuxのボタンをクリックし、シェルスクリプトをダウンロード 端末から sudo sh ダウンロードしたファイル pythonからEnegyPlusを操作できる「eppy」をインストール pip install eppy Enegy…

“SyntaxError: unexpected EOF while parsing” while iterating a dictionary in PDB

ipdbを用いて、複数行に渡るコードを実行しようと した時に起きたエラー。 対処 そもそも複数行で記述できないのかもしれない。。 結局以下のように一行で書くしかないかも for d in dir(request): print d 参考 https://stackoverflow.com/questions/977780…

エラー django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.

エラー内容 python manage.py shell >>> from blog.models import Post >>> Post.objects.all() 省略 django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documen…

pythonでslackbotを作成する際に参考になったサイト

以下の二つのサイトが参考になった。 PythonでSlackbotを作る(1) – ビットログ qiita.com

【pycharm】【jupyter】pycharmでjupyter notebookを使用する際に必要なurlとauthentication tokenの調べ方

pycharm上でjupyterを実行する時に、 urlとauthentication tokenを求められた。 そのurlとauthentication tokenは、端末で以下のコマンドを打つことで 調べることができる jupyter notebook list

【pandas】pandasで単純移動平均を求める

pandasで単純移動平均を求めるやり方のメモ サンプルコード import pandas as pd sample_list = [0,1,2,3,4,5] sample_series = pd.Series(sample_list) average = sample_series.rolling(window=2).mean() print(average) 出力結果 0 NaN 1 0.5 2 1.5 3 2.5…

【matplotlib】グラフのx軸、y軸を消す

以下の図のx軸、y軸を消してみる コードと軸を削除したい図 %matplotlib inline from pylab import * import matplotlib.pyplot as plt fig,ax = plt.subplots() x_list = [0,1,2] y_list = [0,0,0] ax.scatter(x_list,y_list) 以下のコードで各軸を削除する…