pyenvのPATHをFish shellで通す
~/.config/fish/config.fishに以下を記載する set -Ux PYENV_ROOT $HOME/.pyenv set -U fish_user_paths $PYENV_ROOT/bin $fish_user_paths status is-login; and pyenv init --path | source status is-interactive; and pyenv init - | source
~/.config/fish/config.fishに以下を記載する set -Ux PYENV_ROOT $HOME/.pyenv set -U fish_user_paths $PYENV_ROOT/bin $fish_user_paths status is-login; and pyenv init --path | source status is-interactive; and pyenv init - | source
とあるPythonパッケージが依存しているパッケージを表示するには、pipdeptreeが便利。 オプションの指定なしで実行すると、全パッケージの依存リストが表示される。 -p package_nameオプションで特定のパッケージに絞ることができる。 tensorflowの依存一覧を表示する例 $ pipdeptree -p tensorflow 実行結果 tensorflow==2.1.0 - absl-py [required: >=0.7.0, installed: 0.9.0] - six [required: Any, installed: 1.13.0] - astor [required: >=0.6.0, installed: 0.8.1] - gast [required: ==0.2.2, installed: 0.2.2] - google-pasta [required: >=0.1.6, installed: 0.1.8] - six [required: Any, installed: 1.13.0] - grpcio [required: >=1.8.6, installed: 1.26.0] - six [required: >=1.5.2, installed: 1.13.0] - keras-applications [required: >=1.0.8, installed: 1.0.8] - h5py [required: Any, installed: 2....
pyenvとpyenv-virtualenvを導入する手順メモ。 環境 Ubuntu 20.04 LTS 手順 sudo apt install -y build-essential libffi-dev libssl-dev zlib1g-dev liblzma-dev libbz2-dev libreadline-dev libsqlite3-dev git git clone https://github.com/pyenv/pyenv.git ~/.pyenv git clone https://github.com/pyenv/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc echo 'eval "$(pyenv init -)"' >> ~/.bashrc echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc source ~/.bashrc Pythonインストール --enable-sharedオプションを付けて共有ライブラリをビルドする。 env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.8.5 pyenv virtualenv 3.8.5 env pyenv global env
ONNX MLIRに付属のdebug.pyを動かすで動かしたdebug.pyの中を見る。 debug.pyの処理内容 概要 入力として指定したONNXモデルを、ONNX MLIRでshared libraryとしてビルド、実行し、リファレンスバックエンドで実行した結果と比較する リファレンスバックエンドにはONNX Runtimeを使用 Operatorのoutputごとに比較 モデルの出力だけでなく、Operatorの実行結果単位で比較している PyRuntimeはおそらく、ONNX MLIRでビルドしたshared libraryを、Pythonから実行するためのPythonバインディング shared libraryの実行方法はPyRuntimeの実装を見る必要がありそう 詳細 import onnxruntimeでONNX Runtimeをインポートする。 import os import sys import argparse import onnx import subprocess import numpy as np import tempfile from collections import OrderedDict # Reference backend, use onnxruntime by default import onnxruntime prepare = onnxruntime.InferenceSession ONNX_MLIR_HOMEが設定されているか確認。 if (not os.environ.get('ONNX_MLIR_HOME', None)): raise RuntimeError( "Environment variable ONNX_MLIR_HOME is not set, please set it to the path to " "the HOME directory for onnx-mlir....
Windows/LinuxでプロセスIDをC/Pythonから取得する方法。 Windows/C GetCurrentProcessId()を使う。 #include <stdio.h>#include <windows.h> int main(void) { printf("Process ID = %d\n", GetCurrentProcessId()); return 0; } Linux/C getpid()を使う。 #include <stdio.h>#include <sys/types.h>#include <unistd.h> int main(void) { printf("Process ID = %d\n", getpid()); return 0; } Python os.getpid()を使う。 import os print("Process ID = ", os.getpid())
Python 3にはSQLiteを扱うためのモジュールが付属している。 サンプルコードを書いたのでメモ。 step-by-stepで説明 dbname = "test.db" conn = sqlite3.connect(dbname) データベースへ接続する。 cur = conn.cursor() データベースを操作するカーソルオブジェクトを取得。 cur.execute('DROP TABLE IF EXISTS sample') cur.execute('CREATE TABLE IF NOT EXISTS sample (sensor1 real, sensor2 real, sensor3 real)') カーソルオブジェクトに対して.execute()メソッドでSQL文を実行する。 テーブルsampleが存在していれば、削除する。 新たなテーブルsampleを作成する。 for i in range(24*60*60): sensor1 = np.random.normal() sensor2 = np.random.normal() sensor3 = np.random.normal() cur.execute('INSERT INTO sample VALUES(?, ?, ?)', (sensor1, sensor2, sensor3)) NumPyで3つのランダムな実数を生成し、テーブルへレコードをINSERTする。 conn.commit() データベースへコミットし、変更を反映させる。 cur.execute('SELECT * FROM sample') for i in range(5): print(cur.fetchone()) テーブルsampleからレコードを取得し、5件表示する。...
TensorFlowをソースコードからビルドすると、PythonパッケージとしてTensorFlowのwhlファイルが作成される。このwhlファイルが依存するライブラリ一覧は、whlファイル内のMETADATAに記載されている。TensorFlow 1.12.0を対象に、実際にMETADATAファイルの中身を見てみた。 検証環境 Ubuntu 16.04 x86_64 Python 3.6.6 手順 適当なディレクトリを作成し、TensorFlowのwhlファイルをダウンロード、解凍。 $ mkdir workspace; cd workspace $ pip3 download tensorflow==1.12.0 — no-deps $ unzip tensorflow-1.12.0-cp36-cp36m-manylinux1_x86_64.whl 解凍すると、以下の2つのディレクトリができあがる。 tensorflow-1.12.0.data tensorflow-1.12.0.dist-info tensorflow-1.12.0.dist-info/METADATAの中身は以下のようになっている。 Metadata-Version: 2.1 Name: tensorflow Version: 1.12.0 Summary: TensorFlow is an open source machine learning framework for everyone. Home-page: <https://www.tensorflow.org/> Author: Google Inc. Author-email: [email protected] License: Apache 2.0 Download-URL: <https://github.com/tensorflow/tensorflow/tags> Keywords: tensorflow tensor machine learning Platform: UNKNOWN Classifier: Development Status :: 5 — Production/Stable Classifier: Intended Audience :: Developers Classifier: Intended Audience :: Education Classifier: Intended Audience :: Science/Research Classifier: License :: OSI Approved :: Apache Software License Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2....