본문 바로가기

Debugging

리눅스, 파이썬, 파이토치, ROS 가상환경 구축하기

1. 아나콘다  or  미니콘다 설치

https://www.anaconda.com/

 

Anaconda | The World's Most Popular Data Science Platform

Anaconda is the birthplace of Python data science. We are a movement of data scientists, data-driven enterprises, and open source communities.

www.anaconda.com

 

https://docs.conda.io/en/latest/miniconda.html

 

Miniconda — conda documentation

Miniconda is a free minimal installer for conda. It is a small, bootstrap version of Anaconda that includes only conda, Python, the packages they depend on, and a small number of other useful packages, including pip, zlib and a few others. Use the conda in

docs.conda.io

 

2. python 가상 환경 만들기

python --version

파이썬 버전 확인해보고

 

conda create -n pytorch python=3.7

을 이용하여 파이썬 3.7 버전만을 위한 가상환경 만들기

 

그런데 혹시나

conda activate pytorch

를 이용하여 가상 환경 안으로 접속할 때, 에러가 뜬다면...

 

 

source ~/anaconda3/etc/profile.d/conda.sh

명령어를 이용하여 해결해주도록 하자

 

그리고나서 다시 가상 환경을 활성화 시켜주면..

 

다음과 같이 활성화를 할 수 있다.

 

3. Pytorch 설치

-GPU 버전

conda install pytorch torchivision cudatoolkit=[version] -c pytorch

 

-CPU 버전

conda install pytorch torchivision cpuonly -c pytorch

 

+ 부가적인 라이브러리

-> 주피터 판다스 맷플랏 라이브러리...

conda install jupyter pandas matplotlib

 

4. Jupyter Notebook or Jupyter Lab 사용법

터미널에 

jupyter notebook

쳐주시고..

 

 

import toch

print(torch.__version__)

 

을 통해 프로그램이 잘 돌아가는지 확인해봅시다.

 

5. ROS 연동 사용법

다음과 같이 파이썬 기본 publisher 를 사용하면 파이썬, 파이토치, ros를 함께 사용할 수 있습니다.

 

주피터 노트북 말고 일반 터미널이나 package 만들어서 사용하고 싶으시다면

 

catkin_create_pkg py_pkg rospy

명령어를 이용해 패키지를 만들고 다음과 같이 구축해봅시다.

그리고 scripts 폴더와 py_test.py를 만들어봅시다.

 

py_test.py

 

 

노드 실행하기 전에 

roscore

실행해주시고

conda activate pytorch

실행 후 가상 환경 실행!

 

rosrun py_pkg py_test.py

노드를 실행해주면 다음과 같이 실행이 잘 됩니다.

 

참조

http://blog.dhkim.info/AJP/#

 

Jupyter 환경의 PyTorch 개발 환경 갖추기

0. Jupyter 환경의 PyTorch 개발 환경 갖추기 순서

blog.dhkim.info