Microsoft MVP성태의 닷넷 이야기
개발 환경 구성: 675. Windows Octave 8.1.0 - Python 스크립트 연동 [링크 복사], [링크+제목 복사],
조회: 11418
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

(시리즈 글이 7개 있습니다.)
개발 환경 구성: 335. Octave의 명령 창에서 실행한 결과를 복사하는 방법
; https://www.sysnet.pe.kr/2/0/11309

개발 환경 구성: 388. Windows 환경에서 Octave 패키지 설치하는 방법
; https://www.sysnet.pe.kr/2/0/11622

개발 환경 구성: 674. WSL 2 환경에서 GNU Octave 설치
; https://www.sysnet.pe.kr/2/0/13319

개발 환경 구성: 675. Windows Octave 8.1.0 - Python 스크립트 연동
; https://www.sysnet.pe.kr/2/0/13320

개발 환경 구성: 676. WSL/Linux Octave - Python 스크립트 연동
; https://www.sysnet.pe.kr/2/0/13321

개발 환경 구성: 677. Octave에서 Excel read/write를 위한 io 패키지 설치
; https://www.sysnet.pe.kr/2/0/13323

.NET Framework: 2108. C# - Octave의 "save -binary ..."로 생성한 바이너리 파일 분석
; https://www.sysnet.pe.kr/2/0/13324




Windows Octave 8.1.0 - Python 스크립트 연동

예전에 4.x로 테스트할 때만 해도 파이썬을 별도로 설치해야 했는데요, 근래에 새롭게 받은 8.1.0은 자체 포함하고 있습니다.

가령 Octave를 설치한 경로의 .\usr\bin 디렉터리를 보면 다음과 같은 python 실행 파일을 찾을 수 있습니다.

python.exe
python3.10.exe
ptthon3.exe

간단하게 테스트를 위해 python 스크립트 파일을 하나 만들고,

# C:\Octave\8.1.0\scripts\test.py

import sys
print(sys.version)

Octave 내에서 실행했더니 이런 오류가 발생합니다.

>> cd scripts

>> python test.py
python: can't open file '/scripts/C:\\Octave\\8.1.0\\scripts\\test.py': [Errno 2] No such file or directory
ans =

그러니까, 파일 경로에 '/scripts'와 같이 리눅스 체계의 경로를 추가해 버리는 것입니다.




사실 python 명령어는 system 명령어의 wrapper에 불과하므로 이렇게 된 이상 system 명령어로 대체할 수도 있습니다. 그래서 다음과 같이 명령을 내렸더니,

>> system('python C:\octave\8.1.0\scripts\test.py')
python: can't open file '//C:\\octave\\8.1.0\\scripts\\test.py': [Errno 2] No such file or directory
ans = 2

>> dos('python C:\octave\8.1.0\scripts\test.py')
python: can't open file '//C:\\octave\\8.1.0\\scripts\\test.py': [Errno 2] No such file or directory
ans = 2

문제의 원인이 드러납니다. 보이시나요? ^^ 2개의 명령어 모두 python에서 오류가 나는 건데요, 즉, 내장한 python이 리눅스 디렉터리 체계를 따르도록 빌드가 된 것입니다. 실제로 내장 python을 명령행에서 직접 입력해 보면,

C:\Octave\8.1.0\usr\bin>python C:\Octave\8.1.0\scripts\test.py
python: can't open file '/usr/bin/C:\\Octave\\8.1.0\\scripts\\test.py': [Errno 2] No such file or directory

동일한 현상이 나옵니다. 따라서, 내장 python이 아닌, 윈도우 시스템에 설치한 별도의 python을 선택해 실행해야 합니다.

>> [status, output] = system('c:\python37\python c:\octave\8.1.0\scripts\test.py')
status = 0
output = 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)]

자, 그렇다면 최대한 편하게 외부 python을 사용하도록 만들어야 하는데, 원래 Octave는 환경 변수 PATH에 등록된 경로에서 python을 찾게 되어 있습니다. 하지만 (아마도) 우선순위가 내장 python에 있기 때문에 PATH에 등록한 파이썬 실행 파일을 찾지 않게 되는데요, 어쩔 수 없습니다, 그냥 내장 python인 "c:\Octave\8.1.0\usr\bin\python.exe"을 사용하지 못하도록 아예 이름을 바꿔야 합니다. (혹시 다른 방법을 아시는 분은 덧글 부탁드립니다. ^^)

어쨌든 그렇게 해서 python 명령을 실행하면 아래와 같이 (PATH 환경 변수에 있는 파이썬이) 잘 동작합니다.

>> python test.py
ans = 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)]

참고로, 문서에 보면 PYTHON 환경 변수를 설정하면 된다고 하는데요,

>> setenv PYTHON 'c:\python37\python.exe'

실제로 해보면, 그걸 무시하고 PATH 환경 변수에 있는 python이 실행됩니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 4/13/2023]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 76  77  78  79  80  81  [82]  83  84  85  86  87  88  89  90  ...
NoWriterDateCnt.TitleFile(s)
11885정성태5/7/201916038오류 유형: 533. mstest.exe 실행 시 "File extension specified '.loadtest' is not a valid test extension." 오류 발생
11884정성태5/5/201920874.NET Framework: 828. C# DLL에서 Win32 C/C++처럼 dllexport 함수를 제공하는 방법 - 두 번째 이야기
11883정성태5/3/201926082.NET Framework: 827. C# - 인터넷 시간 서버로부터 받은 시간을 윈도우에 적용하는 방법파일 다운로드1
11882정성태5/2/201922329.NET Framework: 826. (번역글) .NET Internals Cookbook Part 11 - Various C# riddles파일 다운로드1
11881정성태4/28/201922474오류 유형: 532. .NET Core 프로젝트로 마이그레이션 시 "CS0579 Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute" 오류 발생
11880정성태4/25/201918263오류 유형: 531. 이벤트 로그 오류 - Task Scheduling Error: m->NextScheduledSPRetry 1547, m->NextScheduledEvent 1547
11879정성태4/24/201926675.NET Framework: 825. (번역글) .NET Internals Cookbook Part 10 - Threads, Tasks, asynchronous code and others파일 다운로드2
11878정성태4/22/201922465.NET Framework: 824. (번역글) .NET Internals Cookbook Part 9 - Finalizers, queues, card tables and other GC stuff파일 다운로드1
11877정성태4/22/201922471.NET Framework: 823. (번역글) .NET Internals Cookbook Part 8 - C# gotchas파일 다운로드1
11876정성태4/21/201921587.NET Framework: 822. (번역글) .NET Internals Cookbook Part 7 - Word tearing, locking and others파일 다운로드1
11875정성태4/21/201922524오류 유형: 530. Visual Studo에서 .NET Core 프로젝트를 열 때 "One or more errors occurred." 오류 발생
11874정성태4/20/201922699.NET Framework: 821. (번역글) .NET Internals Cookbook Part 6 - Object internals파일 다운로드1
11873정성태4/19/201921214.NET Framework: 820. (번역글) .NET Internals Cookbook Part 5 - Methods, parameters, modifiers파일 다운로드1
11872정성태4/17/201922048.NET Framework: 819. (번역글) .NET Internals Cookbook Part 4 - Type members파일 다운로드1
11871정성태4/16/201920815.NET Framework: 818. (번역글) .NET Internals Cookbook Part 3 - Initialization tricks [3]파일 다운로드1
11870정성태4/16/201919008.NET Framework: 817. Process.Start로 실행한 콘솔 프로그램의 출력 결과를 얻는 방법파일 다운로드1
11869정성태4/15/201924826.NET Framework: 816. (번역글) .NET Internals Cookbook Part 2 - GC-related things [2]파일 다운로드2
11868정성태4/15/201920808.NET Framework: 815. CER(Constrained Execution Region)이란?파일 다운로드1
11867정성태4/15/201920012.NET Framework: 814. Critical Finalizer와 SafeHandle의 사용 의미파일 다운로드1
11866정성태4/9/201923190Windows: 159. 네트워크 공유 폴더(net use)에 대한 인증 정보는 언제까지 유효할까요?
11865정성태4/9/201918873오류 유형: 529. 제어판 - C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools is not accessible.
11864정성태4/9/201917583오류 유형: 528. '...' could be '0': this does not adhere to the specification for the function '...'
11863정성태4/9/201917453디버깅 기술: 127. windbg - .NET x64 EXE의 EntryPoint
11862정성태4/7/201920108개발 환경 구성: 437. .NET EXE의 ASLR 기능을 끄는 방법
11861정성태4/6/201919493디버깅 기술: 126. windbg - .NET x86 CLR2/CLR4 EXE의 EntryPoint
11860정성태4/5/201923338오류 유형: 527. Visual C++ 컴파일 오류 - error C2220: warning treated as error - no 'object' file generated
... 76  77  78  79  80  81  [82]  83  84  85  86  87  88  89  90  ...