ホーム » Python

Python」カテゴリーアーカイブ

2024年4月
 123456
78910111213
14151617181920
21222324252627
282930  

カテゴリー

アーカイブ

ブログ統計情報

  • 80,420 アクセス



簡易 Web サーバ

次の様なものをブラウザで表示するために…
http://mish.html.xdomain.jp/Test/WebGL/Sphere.html


「Web Server for Chrome」は以前書いた.
http://test_wp.mish.work/2022/01/chrome-web.html
Win11 環境で同様に実行すると,次の様な表示が…
「Web Server for Chrome」は現在サポートされていません


開発環境には VS 2022 などが入っているので Python を使用した方法
…\Test\Web\WebGL\ に html などをコピー.
コマンドプロンプトで …\Test に移動.
py -m http.server
これで 127.0.0.1:8000 でアクセスできる.
終了は「Ctrl」+「C」.
py -m http.server


ASUSTOR NAS だと,
python -m http.server
python -m http.server
QNAP NAS や Synology NAS でも同様.Raspberry Pi にもあった.


検索すると System.Net.HttpListener.dll と言うのが見つかる.
それを使っていると思われる次の所からコードを拝借.
Windows 標準で Web サーバを起動する
System.Net.HttpListener.dll
勉強を兼ねて,ちょっとやってみるか.


2023/01/17
https://jml.mish.work/index.php/i-tools/web-svr.html
C++/CLI で作成した 簡易 Web サーバ

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

TS-253D 再セットアップ – 3

Entware のインストール.前回 と同様だが少し画像と説明を追加.


「App Center」を開き,右上の「設定(歯車マーク)」をクリック.「アプリリポジトリ」タブを選択.
QNAP NAS  AppCenter 設定
「追加」を押して「OPKG Store」の URL「 https://www.qnapclub.eu/en/repo.xml 」を入力.
ログイン情報は不要.
QNAP NAS  QPKG store の追加
https://www.qnapclub.eu/en/howto/1


左のアイコンに「OPKG Store」が増える.選択して「すべてのアプリ」.検索ボックスに「Entware」と入力.
QPKG store から Entware を検索
「Entware-std」をインストール.
QNAP NAS  Entware のインストール
これで opkg コマンドが使える様になる.
ASUSTOR NAS で作成した .out は,この段階で動作する様になるみたい.


gcc と python3 などのインストール
admin で入ったコンソール で,
opkg install gcc
opkg install python3
他に tree , mc なども.



ASUSTOR NAS
Synology NAS


https://jml.mish.work/various/nas/qnap-nas.html
https://jml.mish.work/various/nas.html


2023/01/11
//qnapclub.eu/ にうまく接続できないので…
https://www.qnapclub.eu/en/repo.xml
https://www.qnapclub.eu/en/howto/1

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Python venv

次の所を参考にして…
VS CodeとFlaskによるWebアプリ開発「最初の一歩」
https://kazuhira-r.hatenablog.com/entry/2019/01/09/231800


cd %TMP% で移動し temp\test\ 以下に作成.
py -m venv temp\test
Win10 環境で py -m venv ...
Linux 環境では,~/Documents/tmp/test/
cd ~/Documents/tmp
python3 -m venv test
Ubuntu 環境で python3 -m venv ...


Win10   .\test\Scripts\activate
Ubuntu  source ./test/bin/activate

Flask の起動は,環境変数 FLASK_APP を設定して flask run らしい.
サンプルにある内容 を python3 sample.py との違いは?


2020/08/24
VS 2017 での仮想環境の作成は「ソリューション エクスプローラー」-「Python 環境」の「右クリック」にある.
VS 2017 Python 仮想環境を追加

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Python から C の呼出し – 3

Win10 環境に入っている Python.h を検索.

C:\Users\Iwao> where /R \ Python.h
C:\CocosCreator\resources\utils\Python27\include\Python.h
C:\Microsoft\AndroidNDK64\android-ndk-r15c\prebuilt\windows-x86_64\include\python2.7\Python.h
C:\Microsoft\AndroidNDK64\android-ndk-r16b\prebuilt\windows-x86_64\include\python2.7\Python.h
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions\Microsoft\Python\Core\Packages\ptvsd\_vendored\pydevd\pydevd_attach_to_process\dll\python.h
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions\Microsoft\Python\Core\Packages\ptvsd\_vendored\pydevd\pydevd_attach_to_process\linux\python.h
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\Extensions\Microsoft\Python\Core\debugpy\_vendored\pydevd\pydevd_attach_to_process\common\python.h
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\Extensions\Microsoft\Python\Miniconda\Miniconda3-x64\include\Python.h
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\include\Python.h
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\pkgs\python-3.6.5-h0c2934d_0\include\Python.h
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\include\Python.h
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_86\include\Python.h
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\include\Python.h
C:\ProgramData\Microsoft\AndroidNDK64\android-ndk-r11c\prebuilt\windows-x86_64\include\python2.7\Python.h
C:\salt\bin\include\Python.h
C:\Users\All Users\Microsoft\AndroidNDK64\android-ndk-r11c\prebuilt\windows-x86_64\include\python2.7\Python.h
C:\Users\Iwao\AppData\Local\Microsoft\Linux\HeaderCache\1.0\-1863842710\usr\include\python2.7\Python.h
C:\Users\Iwao\AppData\Local\Microsoft\Linux\HeaderCache\1.0\-1863842710\usr\include\python3.7\Python.h
C:\Users\Iwao\AppData\Local\Microsoft\Linux\HeaderCache\1.0\-1863842710\usr\include\python3.7m\Python.h
C:\Windows.old\Users\All Users\Microsoft\AndroidNDK64\android-ndk-r11c\prebuilt\windows-x86_64\include\python2.7\Python.h

C:\Users\Iwao>  

Win10 環境の Python.h


https://jml.mish.work/python/call-c-python.html

Is this 投稿 useful? Useful Useless 0 of 1 people say this 投稿 is useful.

Python tkinter インストール

sudo apt install python3-tk
Debian 環境に tkinter インストール
Ubuntu 環境に tkinter インストール


Windows から Raspberry Pi 環境に接続できる様に samba を追加しようと…
検索して次の所を参考に設定.
https://qiita.com/fstyle/items/1670d260f58f77a43144
https://www.raspberrypirulo.net/entry/samba
この中で書かれている nano というエディタ.
CUI で使えるみたいで NAS などの幾つかの環境にインストール.
sudo opkg install nano


他に CUI のファイルマネージャ.
sudo opkg install mc
操作性など異なるが,エコロジーⅡを思い出す.
https://unilab.gbb60166.jp/T98Next/T98Next2.htm

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

TS-253D セットアップ – 7

幾つかの気づいたことをメモ.


SSH 接続 して python3 が動作しない.
python 2.7 は起動する.
App Center で Python3 はインストールしてある.
はっきりわからないが,App Center でインストールしたものと SSH 接続してのものとは異なるみたい.
admin で入って opkg install python3 でインストール.
QNAP NAS に Python 3 インストール
これで SSH 接続でも可能になった.


python3 がインストールできない場合,その前に entware のインストールが必要.
https://dev.mish.work/wordpress/2020/08/29/ts253d-setup-3-opkg/


インストールされている PHP は 7.3.7 .
アップロードできるファイルサイズはデフォルトで十分.


zip , unzip , 7z , convert は入っている.

[Iwao@TS253D prt_text]$ tree /mnt/ext/opt/ImageMagick/usr/local/
/mnt/ext/opt/ImageMagick/usr/local/
└── sbin
    ├── composite
    ├── convert
    └── identify

1 directory, 3 files
[Iwao@TS253D prt_text]$      

iconv コマンドは入ってなさそうだが iconv API は使える.


2020/08/18 pip の追加.

[~] # opkg install python3-pip
Installing python3-pip (19.2.3-4) to root...
Downloading http://bin.entware.net/x64-k3.2/python3-pip_19.2.3-4_x64-3.2.ipk
Installing python3-pkg-resources (41.2.0-3) to root...
Downloading http://bin.entware.net/x64-k3.2/python3-pkg-resources_41.2.0-3_x64-3.2.ipk
Installing python3-setuptools (41.2.0-3) to root...
Downloading http://bin.entware.net/x64-k3.2/python3-setuptools_41.2.0-3_x64-3.2.ipk
Installing python-pip-conf (0.1-1) to root...
Downloading http://bin.entware.net/x64-k3.2/python-pip-conf_0.1-1_x64-3.2.ipk
Configuring python-pip-conf.
Configuring python3-pkg-resources.
Configuring python3-setuptools.
Configuring python3-pip.
[~] #          

QNAP NAS に Flask のインストール


https://jml.mish.work/various/nas/qnap-nas.html
https://jml.mish.work/various/nas.html

Is this 投稿 useful? Useful Useless 1 of 1 people say this 投稿 is useful.

NAS 環境に Flask のインストール

先ず Debian 環境に Flask をインストール.
pip3 install Flask
Debian Flask インストール
サンプルの hello.py を実行,ブラウザで表示.
hello.py を実行して,ブラウザで表示


AS5202T でも同様に Flask をインストール.
pip3 install Flask
AS5202T に Flask のインストール
AS5202T で実行,表示


Synology NAS では pip のインストールから.
suto opkg install python-pip
suto opkg install python3-pip
Synology NAS に pip のインストール
Flask をインストールしてみたが …

Iwao@DS116:~/pyt_test/t_flask$ pip3 install Flask
Collecting Flask
  Using cached https://files.pythonhosted.org/packages/f2/28/2a03252dfb9ebf377f40fba6a7841b47083260bf8bd8e737b0c6952df83f/Flask-1.1.2-py2.py3-none-any.whl
Collecting click>=5.1 (from Flask)
  Using cached https://files.pythonhosted.org/packages/d2/3d/fa76db83bf75c4f8d338c2fd15c8d33fdd7ad23a9b5e57eb6c5de26b430e/click-7.1.2-py2.py3-none-any.whl
Collecting itsdangerous>=0.24 (from Flask)
  Using cached https://files.pythonhosted.org/packages/76/ae/44b03b253d6fade317f32c24d100b3b35c2239807046a4c953c7b89fa49e/itsdangerous-1.1.0-py2.py3-none-any.whl
Collecting Werkzeug>=0.15 (from Flask)
  Using cached https://files.pythonhosted.org/packages/cc/94/5f7079a0e00bd6863ef8f1da638721e9da21e5bacee597595b318f71d62e/Werkzeug-1.0.1-py2.py3-none-any.whl
Collecting Jinja2>=2.10.1 (from Flask)
  Using cached https://files.pythonhosted.org/packages/30/9e/f663a2aa66a09d838042ae1a2c5659828bb9b41ea3a6efa20a20fd92b121/Jinja2-2.11.2-py2.py3-none-any.whl
Collecting MarkupSafe>=0.23 (from Jinja2>=2.10.1->Flask)
  Using cached https://files.pythonhosted.org/packages/b9/2e/64db92e53b86efccfaea71321f597fa2e1b2bd3853d8ce658568f7a13094/MarkupSafe-1.1.1.tar.gz
    Complete output from command python setup.py egg_info:
    /opt/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'project_urls'
    /opt/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'include_package_data'
    /opt/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'python_requires'
    usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
       or: -c --help [cmd1 cmd2 ...]
       or: -c --help-commands
       or: -c cmd --help

    error: invalid command 'egg_info'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-dsqn65uh/MarkupSafe/
Iwao@DS116:~/pyt_test/t_flask$ 

DS116 に Flask インストール ... エラー?


「 Command python setup.py egg_info faild with error code 1 」で検索 をかけると pip などが古いとある.
次の様にして pip などを更新.
sudo pip install –upgrade pip setuptools
Synology NAS の pip の更新と Flask のインストール

Is this 投稿 useful? Useful Useless 1 of 1 people say this 投稿 is useful.

Python から CPP の呼出し – 3

////////////////////////////////////////////////////////////////////
//	test_cpp.hpp
//
#pragma		once

#include	"_s_func.hxx"
#include	"_t_func.hxx"
#include	"_tdefine.hxx"

class	test_class	{
public:
			test_class	(LPCTSTR n)	{	name = n ;	std::tout<< name + _T("\t***") << std::endl ;	}
	virtual		~test_class	()      	{	          	std::tout<< name + _T("\t---") << std::endl ;	}
public:
	tstring		name ;
	} ;

inline	test_class*	get_test_class	(void)
{
	static	test_class	G_tc("G_test") ;
	return	&G_tc ;
	}

////////////////////////////////////////////////////////////////////
//	test_cpp.cpp
//
#include	"test_cpp.hpp"
#include	<clocale>
#include	<iostream>

test_class	tc(_T("global")) ;

int	_tmain	(int argc,TCHAR* argv[])
{
	_tsetlocale(LC_ALL,_T("")) ;
	test_class	tc(_T("local 1")) ;
	{
		test_class	tc(_T("local 2")) ;
		std::tout << _T("hello") << std::endl ;
		}
	{
		test_class*	gt = ::get_test_class() ;
		std::tout << gt->name << std::endl ;
		}
	return	0 ;
	}
////////////////////////////////////////////////////////////////////
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $ g++ test_cpp.cpp -Wall
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $ ./a.out
global  ***
local 1 ***
local 2 ***
hello
local 2 ---
G_test  ***
G_test
local 1 ---
G_test  ---
global  ---
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $
////////////////////////////////////////////////////////////////////
//	t_cpp.cpp
//
#include	<Python.h>

#include	"test_cpp.hpp"
#include	<clocale>
#include	<iostream>

test_class	tc(_T("global")) ;

static	PyObject*	local__	(PyObject* self, PyObject* args)
{
	test_class	tc(_T("local")) ;
	std::tout << tc.name << std::endl ;
	return	Py_None;
	}

static	PyObject*	global_	(PyObject* self, PyObject* args)
{
	test_class*	gt = ::get_test_class() ;
	std::tout << gt->name << std::endl ;
	return	Py_None;
	}

static	PyMethodDef			t_cpp_methods[] = {
	{	"local__",   	local__,	METH_NOARGS,	"local__"	},
	{	"global_",   	global_,	METH_NOARGS,	"global_"	},
	{	NULL								},
	} ;

static	struct	PyModuleDef	t_cpp = {
	PyModuleDef_HEAD_INIT,
	"t_cpp",
	"test cpp module",
	-1,
	t_cpp_methods
	} ;

PyMODINIT_FUNC	PyInit_t_cpp(void)
{
	return	PyModule_Create(&t_cpp) ;
	}
////////////////////////////////////////////////////////////////////
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $ g++ t_cpp.cpp -Wall -fPIC -shared -o t_cpp.so -I /volume1/.@plugins/AppCentral/python3/include/python3.7m/
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $ python3
Python 3.7.0 (default, Aug 23 2018, 17:48:39)
[GCC 4.6.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import t_cpp
global  ***
>>> dir(t_cpp)
['__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'global_', 'local__']
>>> t_cpp.local__()
local   ***
local
local   ---
>>> t_cpp.local__()
local   ***
local
local   ---
>>> t_cpp.global_()
G_test  ***
G_test
>>> t_cpp.global_()
G_test
>>> import t_cpp
>>> t_cpp.local__()
local   ***
local
local   ---
>>> t_cpp.global_()
G_test
>>> exit()
G_test  ---
global  ---
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $ 

Python から C++ 呼び出し時のコンストラクタ,デストラクタ

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Python から C の呼出し – 2

先日 Python から C を呼び出す関係を調べていて Synology NAS に Python.h がなかった.
検索 をかけると DSM「パッケージ センター」-「Python3」では python-dev が入ってないらしい.


次の様な手順で python-dev をインストール.
# sudo -i
# cd /var/services/homes/Iwao/
# source ./set_ds_inc.sh
# opkg install python-dev
# opkg install python3-dev
Synology NAS に python-dev のインストール
コンパイルで必要なファイルは次の所に入った.
/volume1/@entware-ng/opt/include/python3.6/Python.h
/volume1/@entware-ng/opt/include/python2.7/Python.h
Synology NAS で Python から C の呼出し


Iwao@DS116:~/pyt_test/call_c/call_cpp/g3d_to$ g++ g3d_to.cpp -Wall -fPIC -o g3d_to.so -shared
g3d_to.cpp:9:20: fatal error: Python.h: No such file or directory

                    ^
compilation terminated.
Iwao@DS116:~/pyt_test/call_c/call_cpp/g3d_to$ g++ g3d_to.cpp -Wall -fPIC -o g3d_to.so -shared -I /volume1/@entware-ng/opt/include/python3.6/
Iwao@DS116:~/pyt_test/call_c/call_cpp/g3d_to$ ll
total 9568
drwxrwxrwx+ 3 Iwao users    4096 Aug  5 10:29 .
drwxrwxrwx+ 3 Iwao users    4096 Aug  5 09:50 ..
-rwxrwxrwx+ 1 Iwao users 3941375 May  7 18:03 3887.imo
-rwxrwxrwx+ 1 Iwao users 1241865 Jul  7 15:13 7801.imo
drwxrwxrwx+ 2 Iwao users    4096 Aug  5 10:29 bak
-rwxrwxrwx+ 1 Iwao users    1688 Aug  4 15:04 g3d_to.cpp
-rwxrwxrwx  1 Iwao users 2654136 Aug  5 10:29 g3d_to.so
-rwxrwxrwx+ 1 Iwao users    1644 Aug  7  2019 gons_to.cpp
-rwxrwxrwx  1 Iwao users 1931244 Aug  5 10:17 gons_to.out
Iwao@DS116:~/pyt_test/call_c/call_cpp/g3d_to$ python3
Python 3.6.2 (default, Jan 11 2018, 10:32:53)
[GCC 6.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import g3d_to
>>> dir(g3d_to)
['__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'gons_to', 'load', 'save']
>>> g3d_to.load("./7801.imo")
>>> g3d_to.save("./7801.stl")
>>> g3d_to.save("./7801.ac")
>>>
Iwao@DS116:~/pyt_test/call_c/call_cpp/g3d_to$ ll
total 10252
drwxrwxrwx+ 3 Iwao users    4096 Aug  5 10:31 .
drwxrwxrwx+ 3 Iwao users    4096 Aug  5 09:50 ..
-rwxrwxrwx+ 1 Iwao users 3941375 May  7 18:03 3887.imo
-rwxrwxrwx+ 1 Iwao users  438369 Aug  5 10:31 7801.ac
-rwxrwxrwx+ 1 Iwao users 1241865 Jul  7 15:13 7801.imo
-rwxrwxrwx+ 1 Iwao users  254784 Aug  5 10:31 7801.stl
drwxrwxrwx+ 2 Iwao users    4096 Aug  5 10:29 bak
-rwxrwxrwx+ 1 Iwao users    1688 Aug  4 15:04 g3d_to.cpp
-rwxrwxrwx  1 Iwao users 2654136 Aug  5 10:29 g3d_to.so
-rwxrwxrwx+ 1 Iwao users    1644 Aug  7  2019 gons_to.cpp
-rwxrwxrwx  1 Iwao users 1931244 Aug  5 10:17 gons_to.out
Iwao@DS116:~/pyt_test/call_c/call_cpp/g3d_to$ 

DS116 で Python から C++ の呼出し
コンパイル,実行など AS5202T より時間がかかる.


https://jml.mish.work/python/call-c-python.html

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Python から CPP の呼出し – 2


予めデータ(vv_PLF)を作成して,必要に応じてファイルに出力するコード.

vv_PLF*	get_vv_PLF	(void)
{
	static	vv_PLF	G_PLF ;
	return	&G_PLF ;
	}
static	PyObject*	check_rd	(PyObject* self, PyObject* args)
{
	vv_PLF*	gvv_plf = get_vv_PLF() ;
	vv_PLF	vv_plf_ = ::Check_Revise_deg() ;
	*gvv_plf = vv_plf_ ;
	return	Py_None ;
	}
static	PyObject*	dump_svg	(PyObject* self, PyObject* args)
{
	vv_PLF*	gvv_plf = get_vv_PLF() ;
	::Dump_SVG(*gvv_plf) ;
	return	Py_None ;
	}
static	PyObject*	dump_ipl	(PyObject* self, PyObject* args)
{
	vv_PLF*	gvv_plf = get_vv_PLF() ;
	::Dump_ipl(*gvv_plf) ;
	return	Py_None ;
	}

Python から C++ の呼出し 複数のメソッドで共通な領域を使用する
Python 側では
* check_rd でデータを作成.
* dump_svg などでデータを出力.


3D データを読み込んで,指定されたファイル名(拡張子により形式を判断)で出力.

static	PyObject*	load	(PyObject* self, PyObject* args)
{
	const	char*	str_file = NULL ;
	if (!PyArg_ParseTuple(args,"s",&str_file))	{
		return	NULL ;
		}
	tstring	g3_file = str_file ;
	GonsA	gnsa = ::To_GonsA(g3_file.c_str()) ;
	set_GonsA(gnsa) ;
	return	Py_None;
	}
static	PyObject*	save	(PyObject* self, PyObject* args)
{
	const	char*	str_file = NULL ;
	if (!PyArg_ParseTuple(args,"s",&str_file))	{
		return	NULL ;
		}
	tstring	g3_file = str_file ;
	GonsA*	gnsa = ::get_GonsA() ;
	::GonsA_To(*gnsa,g3_file.c_str()) ;
	return	Py_None;
	}
static	PyObject*	gons_to	(PyObject* self, PyObject* args)
{
	const	char*	str_file = NULL ;
	if (!PyArg_ParseTuple(args,"s",&str_file))	{
		return	NULL ;
		}
	tstring	g3_file = str_file ;
	gons_to(g3_file.c_str()) ;
	return	Py_None;
	}

Python から C++ の呼出し 3D データの変換

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Python から CPP の呼出し

雰囲気はつかめてきたので,以前作成した cpp を呼んでみることに…
実際の処理部分は C++ のコードだが,呼び出しは C の関数.
また引数もない状態なので,C 関数の system(“a.out”) と呼んでいるのと同様.

#include	"i_rd_dbg.hxx"
int _tmain(int argc, TCHAR* argv[])
{
	::Test_Revise_deg() ;
	return 0 ;
	}

#include	<Python.h>
#include	"i_rd_dbg.hxx"
#include	"messbar.cxx"

static	PyObject*	call_cpp(PyObject* self, PyObject* args)
{
	::Test_Revise_deg() ;
	return	Py_None ;
	}

static	PyMethodDef 	 	myMethods[] = {
	{	"_call_cpp_",	call_cpp,	METH_NOARGS,	"call cpp"		},
	{	NULL														},
	} ;

static	struct	PyModuleDef	call_mod = {
	PyModuleDef_HEAD_INIT,
	"call_mod",
	"call_cpp module",
	-1,
	myMethods
	} ;

PyMODINIT_FUNC	PyInit_call_mod(void)
{
	return	PyModule_Create(&call_mod) ;
	}

コンパイルして import まではできたが,メソッドをうまく呼び出せない.
>>> call_mod.call_cpp()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module ‘call_mod’ has no attribute ‘call_cpp’
>>>
それで,メソッドを表示できないかと思い検索すると,
python でメソッドの一覧を取得する方法
他に dir(call_mod) もあった.

Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/T_Rvs_sc $ g++ rvs_sc_w.cpp -o call_mod.so  -fPIC -Wall -shared -I /volume1/.@plugins/AppCentral/python3/include/python3.7m/
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/T_Rvs_sc $
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/T_Rvs_sc $ python3
Python 3.7.0 (default, Aug 23 2018, 17:48:39)
[GCC 4.6.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import call_mod
>>> call_mod.call_cpp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'call_mod' has no attribute 'call_cpp'
>>> call_mod.call_cpp()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'call_mod' has no attribute 'call_cpp'
>>> obj = call_mod
>>> import inspect
>>> for m in inspect.getmembers(obj):
...     print(m)
...
('__doc__', 'call_cpp module')
('__file__', '/volume1/home/Iwao/test/test_py/call_c/call_cpp/T_Rvs_sc/call_mod.so')
('__loader__', <_frozen_importlib_external.ExtensionFileLoader object at 0x7f5a1a35ec50>)
('__name__', 'call_mod')
('__package__', '')
('__spec__', ModuleSpec(name='call_mod', loader=<_frozen_importlib_external.ExtensionFileLoader object at 0x7f5a1a35ec50>, origin='/volume1/home/Iwao/test/test_py/call_c/call_cpp/T_Rvs_sc/call_mod.so'))
('_call_cpp_', <built-in function _call_cpp_>)
>>> call_mod._call_cpp_()
>>>

Python から cpp の呼出し メソッドの表示

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Python から C の呼出し

C のコードを Python から呼出せないかと…
Python のドキュメントとしては次の所にある
C や C++ による Python の拡張

Win10      C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\include\Python.h
debian10   /usr/include/python3.7/Python.h
AS5202T    /volume1/.@plugins/AppCentral/python3/include/python3.7m/Python.h

Iwao@AS5202T:/volume1/.@plugins/AppCentral/python3/include/python3.7m $ find / -name Python.h
/volume1/.@plugins/AppCentral/linux-center/containers/debian10/rootfs/usr/include/python2.7/Python.h
/volume1/.@plugins/AppCentral/linux-center/containers/debian10/rootfs/usr/include/python3.7m/Python.h
/volume1/.@plugins/AppCentral/python/include/python2.7/Python.h
/volume1/.@plugins/AppCentral/python3/include/python3.7m/Python.h

検索 して見つけたもの.
https://www.fsi-embedded.jp/kumico/columns/?cat=python
https://qiita.com/donkonishi/items/b7825b34d0711e336c61
https://www.quark.kj.yamagata-u.ac.jp/~hiroki/python/?id=19
http://owa.as.wakwak.ne.jp/zope/docs/Python/BindingC/
https://cpp-learning.com/?s=”Python+C+API”


Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello/bak $ cat hellWrap.c
#include <Python.h>
extern int add(int, int);
extern void out(const char*, const char*);

PyObject* hello_add(PyObject* self, PyObject* args)
{
    int x, y, g;

    if (!PyArg_ParseTuple(args, "ii", &x, &y))
        return NULL;
    g = add(x, y);
    return Py_BuildValue("i", g);
}

PyObject* hello_out(PyObject* self, PyObject* args, PyObject* kw)
{
    const char* adrs = NULL;
    const char* name = NULL;
    static char* argnames[] = {"adrs", "name", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kw, "|ss",
            argnames, &adrs, &name))
        return NULL;
    out(adrs, name);
    return Py_BuildValue("");
}

static PyMethodDef hellomethods[] = {
    {"add", hello_add, METH_VARARGS},
    {"out", hello_out, METH_VARARGS | METH_KEYWORDS},
    {NULL}
};

void initchello(){
  Py_InitModule("hello", hellomethods);
}

Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello/bak $ gcc -fPIC -Wall -c -o hellWrap.o hellWrap.c -I /volume1/.@plugins/AppCentral/python/include/python2.7/
hellWrap.c:30:13: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
     {"out", hello_out, METH_VARARGS | METH_KEYWORDS},
             ^~~~~~~~~
hellWrap.c:30:13: note: (near initialization for 'hellomethods[1].ml_meth')
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello/bak $ gcc -fPIC -Wall -c -o hellWrap.o hellWrap.c -I /volume1/.@plugins/AppCentral/python/include/python2.7/
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello/bak $   

Python から C の呼出し ラッパー
PyMethodDef の所でエラーとなっていていろいろと探すと,型を指定しているものがあり,それを指定.
https://bty.sakura.ne.jp/wp/archives/83

static PyMethodDef hellomethods[] = {
    {"add", (PyCFunction)hello_add, METH_VARARGS},
    {"out", (PyCFunction)hello_out, METH_VARARGS | METH_KEYWORDS},
    {NULL}
};

コンパイルは通る様になった.
Python から試そうとすると …

Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello $ gcc -fPIC -Wall -c -o helloWrap.o helloWrap.c -I /volume1/.@plugins/AppCentral/python/include/python2.7/
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello $ gcc -fPIC -Wall -shared -o hellomodule.so hello.o helloWrap.o
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello $ ll
total 44
drwxrwxrwx    3 Iwao     users       4.0K Jul 29 18:16 ./
drwxrwxrwx    5 Iwao     users       4.0K Jul 29 15:31 ../
drwxrwxrwx    2 Iwao     users       4.0K Jul 29 18:05 bak/
-rwxrwxrwx    1 Iwao     users        188 Jul 29 16:29 hello.c*
-rw-r--r--    1 Iwao     users       1.6K Jul 29 16:33 hello.o
-rwxrwxrwx    1 Iwao     users        910 Jul 29 16:32 helloWrap.BAK*
-rwxrwxrwx    1 Iwao     users        936 Jul 29 16:37 helloWrap.c*
-rw-r--r--    1 Iwao     users       3.1K Jul 29 18:16 helloWrap.o
-rwxr-xr-x    1 Iwao     users       8.3K Jul 29 18:16 hellomodule.so*
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello $ python3
Python 3.7.0 (default, Aug 23 2018, 17:48:39)
[GCC 4.6.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import hello
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'hello'
>>> exit()
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello $ python
Python 2.7.10 (default, Aug 19 2015, 09:18:54)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import hello
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define init function (inithello)
>>> exit()
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello $   

Python から C の呼出し import でエラー
まだ何か違うみたい.
メッセージは inithello がないとなっているので helloWrap.c を見直すと…
void initchello() { … } となっている.
関数名を inithello に変更してビルドすると通った.
Python から C の呼出し


2020/07/30
今日は次の所を参考にさせてもらって…
https://cpp-learning.com/python_c_api_step1/

Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/py_hello $ gcc ph_hello.c -o mymodule.so -fPIC -Wall -shared -I /volume1/.@plugins/AppCentral/python3/include/python3.7m/
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/py_hello $ python3
Python 3.7.0 (default, Aug 23 2018, 17:48:39)
[GCC 4.6.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mymodule
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define module export function (PyInit_mymodule)
>>> import myModule
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'myModule'
>>>
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/py_hello $ cp mymodule.so myModule.so
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/py_hello $ ll
total 44
drwxrwxrwx    3 Iwao     users       4.0K Jul 30 16:49 ./
drwxrwxrwx    6 Iwao     users       4.0K Jul 30 14:59 ../
drwxrwxrwx    2 Iwao     users       4.0K Jul 30 16:48 bak/
-rwxr-xr-x    1 Iwao     users       8.1K Jul 30 16:49 myModule.so*
-rwxr-xr-x    1 Iwao     users       8.1K Jul 30 16:47 mymodule.so*
-rwxrwxrwx    1 Iwao     users        188 Jul 29 16:29 ph_hello.BAK*
-rwxrwxrwx    1 Iwao     users       1.3K Jul 30 16:27 ph_hello.c*
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/py_hello $ python3
Python 3.7.0 (default, Aug 23 2018, 17:48:39)
[GCC 4.6.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import myModule
>>> myModule.helloworld
<built-in function helloworld>
>>> myModule.helloworld()
Hello World
>>>
>>>
>>>
>>>
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/py_hello $

Python から C の呼出し  py_hello
コンパイル時の出力ファイル名 mymodule.so が間違っていた.正しくは myModule.so .


そこ には詳しく書かれているが,自分用にメモ.
PyMethodDef の “メソッド名” は Python 側での (モジュール名).(メソッド名) .
同様に PyModuleDef の “モジュール名” は import 時の名称..so の出力ファイル名も対応している必要がある?
文字列なので,異なっていてもコンパイル時のエラーにはならない.
実行時に見つからないなどのエラーとなる.


2020/07/31
続きの内容をやっていて…
https://cpp-learning.com/python_c_api_step2/
Python から C の呼出しでエラー
Fatal Python error: GC object already tracked
Python から C の呼出し  Py_DECREF をコメントに
c_list は Python 側で確保しているため Py_DECREF はうまくないのではないか?


https://jml.mish.work/python/call-c-python.html

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Python 負のインデックス

次の所を読ませてもらっていて感じたことを…
けいしゅけのブログ薬局 情報館
https://keisyuke-blogyakkyoku.xyz/python-list-index
今私が習得するのにタイミングや更新サイクルが丁度良いので助かっている.


ASUSTOR NAS AS5202T に SSH 接続して Python を操作.

C:\Program Files\Microsoft Office\Office14>cd C:\Users\Iwao\AppData\Local\Temp

C:\Users\Iwao\AppData\Local\Temp>ssh -l Iwao -p 22 192.168.1.75
Password:
Iwao@AS5202T:/volume1/home/Iwao $ python
Python 2.7.10 (default, Aug 19 2015, 09:18:54)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a=[0,1,2,3,4]
>>> print(a[0])
0
>>> print(a[4])
4
>>> print(a[5])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list index out of range
>>> print(a[-1])
4
>>> print(a[-4])
1
>>> print(a[-5])
0
>>> print(a[-6])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list index out of range
>>>  

Python 負のインデックス
似たようなことを C++ でやろうとすると次の様な感じ.
std::cout << a[a.size()-1] ;


この様な記述ができるからか,今まで負のインデックスの必要性は感じたことがなかった.
また配列の検索で該当するものがないと -1 を返す様なコードもよく書く.
インデックスを変数で持つ時は?
いろいろ考えると個人的にはあまり使わないのではないかと思う.
Python などをやればもっと有効な使い方が出てくるのか?

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Debian 環境に pip のインストール

PyOpenGL を使おうとして pip コマンドを打つと,コマンドがない.
どうも pip が入っていないみたいで,次の様に入力してインストール.
sudo apt install python-pip
更に PyOpenGL のインストール.
pip install PyOpenGL
Debian 環境に PyOpenGL のインストール


pip3 のインストールは
sudo apt install python3-pip


C:\WINDOWS\System32>cd C:\Users\Iwao\AppData\Local\Temp

C:\Users\Iwao\AppData\Local\Temp>ssh -l admin -p 22 lxcdebian10
admin@lxcdebian10's password:
Linux lxcdebian10 4.14.x #1 SMP Wed May 13 00:37:48 CST 2020 x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Thu Jul  9 10:51:02 2020 from fe80::ed6f:4991:21c9:1882%eth0
admin@lxcdebian10:~$ cat /usr/bin/pip
#!/usr/bin/python
# GENERATED BY DEBIAN

import sys

# Run the main entry point, similarly to how setuptools does it, but because
# we didn't install the actual entry point from setup.py, don't use the
# pkg_resources API.
from pip._internal import main
if __name__ == '__main__':
    sys.exit(main())
admin@lxcdebian10:~$ cat /usr/bin/pip3
#!/usr/bin/python3
# GENERATED BY DEBIAN

import sys

# Run the main entry point, similarly to how setuptools does it, but because
# we didn't install the actual entry point from setup.py, don't use the
# pkg_resources API.
from pip._internal import main
if __name__ == '__main__':
    sys.exit(main())
admin@lxcdebian10:~$  

Debian  cat pip , pip3

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

弦と矢と半径 – 6

Python のコードを修正して「結果のみ」を出力する様に変更.

import	sys
import	math

def	r_cs	(c , s)	:	return	(        ( c*c )  / ( 8 *s ) +  s/2 )
def	s_rc	(r , c)	:	return	( r-math.sqrt(r*r - (c/2)*(c/2) )   )
def	c_rs	(r , s)	:	return	(   math.sqrt(r*r - (r-s)*(r-s) )*2 )

cmd =       sys.argv[1]
p1  = float(sys.argv[2])
p2  = float(sys.argv[3])

#print	(cmd + " " + str(p1) + " " + str(p2))

if  	cmd == "r_cs"	:	print	(r_cs(p1,p2))
elif	cmd == "s_rc"	:	print	(s_rc(p1,p2))
elif	cmd == "c_rs"	:	print	(c_rs(p1,p2))
#else	            	:	print	("error")

#print	("")

弦と矢と半径 スマートフォンからアクセス
PHP
あまり綺麗なコードでないので,ここには張り付けていません.リンク先を見てください.
PHP から Python の呼び出し
https://mish.myds.me/…/r_cs/6/

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

弦と矢と半径 – 5

PHP から Python の呼び出しで,Python のコマンドライン引数を使用する.

<?php

	echo	("call python\n") ;

	echo	("\n") ;
	system	("python r_cs.py r_cs 6 1") ;
	system	("python r_cs.py s_rc 5 6") ;
	system	("python r_cs.py c_rs 5 1") ;

	echo	("\n") ;
	system	("python r_cs.py r_cs 8 2") ;
	system	("python r_cs.py s_rc 5 8") ;
	system	("python r_cs.py c_rs 5 2") ;

	?>

Python のコードは,

import	sys
import	math

def	r_cs	(c , s)	:	return	(        ( c*c )  / ( 8 *s ) +  s/2 )
def	s_rc	(r , c)	:	return	( r-math.sqrt(r*r - (c/2)*(c/2) )   )
def	c_rs	(r , s)	:	return	(   math.sqrt(r*r - (r-s)*(r-s) )*2 )

cmd =       sys.argv[1]
p1  = float(sys.argv[2])
p2  = float(sys.argv[3])

print	(cmd + " " + str(p1) + " " + str(p2))

if  	cmd == "r_cs"	:	print	(r_cs(p1,p2))
elif	cmd == "s_rc"	:	print	(s_rc(p1,p2))
elif	cmd == "c_rs"	:	print	(c_rs(p1,p2))
else	            	:	print	("error")

print	("")

Python がよくわかっていないので,いろいろなエラーが…
PHP から Python の呼び出し コマンドライン引数
https://mish.myds.me/…/r_cs/5/

弦,矢,半径

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

弦と矢と半径 – 4

先日の Python コードのバグ(整数で計算されてしまうため結果が異なる).
原因はすぐわかるが,対応は悩む所.
コードを分解して動作を確認してみた.

def	r_cs_o	(c , s)	:	return	(        ( c*c )  / ( 8 *s )  +  s/2  )
def	r_cs_n	(c , s)	:	return	(        ( c*c )  / ( 8.*s )  +  s/2. )

print   (6*6)
print   (8*1)

print   (36/8)
print   (36/8.)

print   (1/2)
print   (1/2.)

print	("")
print   (36/8 +1/2 )
print   (36/8.+1/2.)

print	("")
print	(r_cs_o(6,1))
print	(r_cs_n(6,1))

Python での「浮動小数点数」の動作テスト
https://docs.python.org/ja/3/howto/pyporting.html?highlight=除算


Synology NAS DSM では Python 2.7 が標準で入っているみたい.
「パッケージ センター」で Python3 を追加できる.

C:\Program Files\Microsoft Office\Office14>cd C:\Users\Iwao\AppData\Local\Temp

C:\Users\Iwao\AppData\Local\Temp>ssh -l Iwao -p 2200 192.168.1.116
Iwao@192.168.1.116's password:
Iwao@DS116:~$ python3
Python 3.5.1 (default, Jan 29 2018, 14:16:30)
[GCC 4.9.3 20150311 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Iwao@DS116:~$ python2
Python 2.7.12 (default, May 12 2020, 04:48:57)
[GCC 4.9.3 20150311 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Iwao@DS116:~$ python
Python 2.7.12 (default, May 12 2020, 04:48:57)
[GCC 4.9.3 20150311 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Iwao@DS116:~$

Synology NAS DS116  python コマンド
ASUSTOR NAS ADM では入ってない.「App Central」でインストール可能.
ASUSTOR NAS Python


2020/11/20
QNAP NAS での Python3 は,他の NAS と異なるみたい.
opkg install python3 でインストールしなければならなかった.
https://mish.myds.me/wordpress/dev/2020/08/29/ts253d-setup-3-opkg/
https://mish.myds.me/wordpress/dev/2020/08/17/ts-253d-setup-7-python3/

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

弦と矢と半径 – 2

今度は PHP からの呼び出し.

<?php

	echo	("call c++\n") ;
	system	("./a.out") ;

	echo	("call python\n") ;
	system	("python r_cs.py") ;

	?>

実際の動作を試すには,gcc と python が必要です.
cpp のコンパイルは
g++ -Wall r_cs.cpp
これで ./a.out が作成されます.
python の呼び出しは
python r_cs.py
r_cs.cpp のコンパイルと r_cs.py の実行
次の所で,同じ様な結果を表示します.
https://mish.myds.me/…/r_cs/2/

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

弦と矢と半径

次の様な計算を何かに使えないかと…

/*
https://ja.wikipedia.org/wiki/矢_(幾何学)
https://en.wikipedia.org/wiki/Circle#Sagitta
弦 c と 矢 s から 半径 r を求める
r  =	(c*c) / (8*s) + s/2

半径 r と 弦 c から 矢 s を求める
s  =	r - sqrt( r*r - (c/2)*(c/2) )

半径 r と 矢 s から 弦 c を求める
c  =	sqrt( r*r - (r-s)*(r-s) ) * 2

i_func.hxx
https://drive.google.com/file/d/1kHadFbhUi9QfGRovMXKYr2xHgcFJAqdZ/view
*/

double	r_cs	(const double c , const double s)	{	return	(   ( c*c )  / ( 8*s )  +  s/2 ) ;	}
double	s_rc	(const double r , const double c)	{	return	( r-sqrt(r*r - (c/2)*(c/2) )   ) ;	}
double	c_rs	(const double r , const double s)	{	return	(   sqrt(r*r - (r-s)*(r-s) )*2 ) ;	}

弦 矢 半径
動作を確認するために 3,4,5 や 5,12,13 は知っていたが次のキーワードで検索.
三平方の定理 整数 組み合わせ
https://ja.wikipedia.org/wiki/ピタゴラスの定理


先ず C++ で書いたもの.

#include	<cmath>

double	r_cs	(const double c , const double s)	{	return	(   ( c*c )  / ( 8*s )  +  s/2 ) ;	}
double	s_rc	(const double r , const double c)	{	return	( r-sqrt(r*r - (c/2)*(c/2) )   ) ;	}
double	c_rs	(const double r , const double s)	{	return	(   sqrt(r*r - (r-s)*(r-s) )*2 ) ;	}

#include	<iostream>

int main(void){
	std::cout << "6 1 5"   << std::endl ;
	std::cout << r_cs(6,1) << std::endl ;
	std::cout << s_rc(5,6) << std::endl ;
	std::cout << c_rs(5,1) << std::endl ;
	std::cout << std::endl ;

	std::cout << "8 2 5"   << std::endl ;
	std::cout << r_cs(8,2) << std::endl ;
	std::cout << s_rc(5,8) << std::endl ;
	std::cout << c_rs(5,2) << std::endl ;
	std::cout << std::endl ;

	return  0 ;
	}

次の所に貼り付けて動作確認できます.
https://paiza.io/ja/
https://wandbox.org/
https://ideone.com/


次は JavaScript

function	r_cs	(c , s)		{	return	(        ( c*c )  / ( 8*s )  +  s/2 ) ;		}
function	s_rc	(r , c)		{	return	( r-Math.sqrt(r*r - (c/2)*(c/2) )   ) ;		}
function	c_rs	(r , s)		{	return	(   Math.sqrt(r*r - (r-s)*(r-s) )*2 ) ;		}


	console.log	("6 1 5") ;
	console.log	(r_cs(6,1)) ;
	console.log	(s_rc(5,6)) ;
	console.log	(c_rs(5,1)) ;
	console.log	("") ;

	console.log	("8 2 5") ;
	console.log	(r_cs(8,2)) ;
	console.log	(s_rc(5,8)) ;
	console.log	(c_rs(5,2)) ;
	console.log	("") ;

Python

import	math

def	r_cs	(c , s)	:	return	(        ( c*c )  / ( 8.*s ) + s/2. )
def	s_rc	(r , c)	:	return	( r-math.sqrt(r*r - (c/2)*(c/2) )   )
def	c_rs	(r , s)	:	return	(   math.sqrt(r*r - (r-s)*(r-s) )*2 )

print	("6 1 5")
print	(r_cs(6,1))
print	(s_rc(5,6))
print	(c_rs(5,1))
print	("")

print	("8 2 5")
print	(r_cs(8,2))
print	(s_rc(5,8))
print	(c_rs(5,2))
print	("")

2020/05/30
r_cs.py の r_cs で「浮動小数点数」として扱われていなかったので修正.
def r_cs (c , s) : return ( ( c*c ) / ( 8.*s ) + s/2. )

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

PyOpenGL インストール – 2

今度は Ubuntu 環境へのインストール.
先ず Python 2.7 .

iwao@VB-Ubuntu:~$ sudo apt install python
[sudo] iwao のパスワード: 
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
以下の追加パッケージがインストールされます:
  libpython-stdlib libpython2-stdlib libpython2.7-minimal libpython2.7-stdlib
  python-minimal python2 python2-minimal python2.7 python2.7-minimal
提案パッケージ:
  python-doc python-tk python2-doc python2.7-doc binfmt-support
以下のパッケージが新たにインストールされます:
  libpython-stdlib libpython2-stdlib libpython2.7-minimal libpython2.7-stdlib
  python python-minimal python2 python2-minimal python2.7 python2.7-minimal
アップグレード: 0 個、新規インストール: 10 個、削除: 0 個、保留: 9 個。
3,883 kB のアーカイブを取得する必要があります。
この操作後に追加で 16.7 MB のディスク容量が消費されます。
続行しますか? [Y/n] 

Ubuntu に Python 2.7 をインストール
続いて pip .

iwao@VB-Ubuntu:~$ pip

Command 'pip' not found, but can be installed with:

sudo apt install python-pip

iwao@VB-Ubuntu:~$ sudo apt install python-pip
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
以下の追加パッケージがインストールされます:
  javascript-common libexpat1 libexpat1-dev libjs-jquery libjs-sphinxdoc libjs-underscore libpython-all-dev
  libpython-dev libpython2-dev libpython2.7 libpython2.7-dev python-all python-all-dev python-asn1crypto
  python-cffi-backend python-configparser python-crypto python-cryptography python-dbus python-dev python-entrypoints
  python-enum34 python-gi python-idna python-ipaddress python-keyring python-keyrings.alt python-pip-whl
  python-pkg-resources python-secretstorage python-setuptools python-six python-wheel python-xdg python2-dev
  python2.7-dev
提案パッケージ:
  apache2 | lighttpd | httpd python-crypto-doc python-cryptography-doc python-cryptography-vectors python-dbus-dbg
  python-dbus-doc python-enum34-doc python-gi-cairo libkf5wallet-bin gir1.2-gnomekeyring-1.0 python-gdata
  python-keyczar python-secretstorage-doc python-setuptools-doc
以下のパッケージが新たにインストールされます:
  javascript-common libexpat1-dev libjs-jquery libjs-sphinxdoc libjs-underscore libpython-all-dev libpython-dev
  libpython2-dev libpython2.7 libpython2.7-dev python-all python-all-dev python-asn1crypto python-cffi-backend
  python-configparser python-crypto python-cryptography python-dbus python-dev python-entrypoints python-enum34
  python-gi python-idna python-ipaddress python-keyring python-keyrings.alt python-pip python-pip-whl
  python-pkg-resources python-secretstorage python-setuptools python-six python-wheel python-xdg python2-dev
  python2.7-dev
以下のパッケージはアップグレードされます:
  libexpat1
アップグレード: 1 個、新規インストール: 36 個、削除: 0 個、保留: 8 個。
37.0 MB 中 36.9 MB のアーカイブを取得する必要があります。
この操作後に追加で 72.7 MB のディスク容量が消費されます。
続行しますか? [Y/n] 

Ubuntu に pip をインストール


PyOpenGL .
$ pip install PyOpenGL
$ pip install PyOpenGL_accelerate
PyOpenGL のインストール
Ubuntu はこのインストールで良いみたい.
Fedora の様に OpenGL.GL にあたるパッケージのインストールは必要なさそう.


Raspberry Pi へのインストール.
Python 2.7 は入っているので PyOpenGL のインストール.
$ pip install PyOpenGL
$ pip install PyOpenGL_accelerate
Raspberry Pi に PyOpenGL のインストール
これだけ良いみたい.


2020/07/29
PyOpenGL 3.x The Python OpenGL Binding

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.