data analysis & visualization

 

 

 

conda pack을 통해 환경을 추출했는데 spyder 에서 아래와 같은 에러가 뜨는 경우가 있다.

 

 

해당 에러에 대하여 pyqt나 qt qtpy를 다시 인스톨하라는 stackoverflow 답변들이 많았다. 

 

test 해 본 결과 

 

해당 상태에서 qt만 다시 인스톨해주면 spyder가 열리는 것을 확인하였다. 

 

anaconda.org/anaconda/qt/files

 

Files :: Anaconda Cloud

 

anaconda.org

 

 

 

 

운영체제에 맞게 다운로드 

 

conda install <패키지 경로>\<패키지 명>

 

conda install qt-5.9.7-vc14h73c81de_0.tar.gz

 

이제 다시 spyder를 실행하면 실행이 된다. 

나는 conda create -n <환경명> python=3.6으로 환경을 설치해서 쓰던 도중 python의 버전이 변경되는 이상한 현상을 겪었다. 물론 내 실수겠거니 싶지만 고치는게 문제였다. python을 지우게 되면 버전이 다 바뀌게되기 때문이다.

그래서 python의 default 설정을 바꿔보도록 하자. 

 

우선 내 문제는 conda 가상환경의 python을 default로 잡지 않고 base의 경로를 잡는게 문제였다.

 

python은 환경의 경로 /bin/<python버전 ex)python3.6>으로 나타난다. 예를들어 python3.8이 설정된 base는 

/root/anaconda3/bin/python3.8이다.   

GPU환경에서 /root/anaconda3/envs/bin/python3.6에 있어야 할 GPU버전이 base경로로 잡혀있다. 이제 이 설정을 바꿔보자 .

 

python 의 경로를 확인하는 명령어는 windows에서는 where python, mac이나 linux에서는 which python이다. 

 

해당 가상환경에 activate 한 뒤 아래와 같이 설정하자. 

alias python='/root/anaconda3/envs/bin/python3.6'

. ~/.bashrc

 

 

이렇게 jupyter라는 가상환경을 고쳐 보았고 아래와 같이 나타났다. 

 

'python' 카테고리의 다른 글

python oracle DB 연동  (0) 2020.12.03
offline conda pack spyder설치 에러  (0) 2020.12.01
jupyterlab 확장기능  (0) 2020.11.21
아나콘다 오프라인 가상환경 생성 , 가상환경 추출 및 설치  (0) 2020.11.20
pyinstaller  (0) 2020.11.20

jupyterlab 확장기능

python2020. 11. 21. 00:52

 

확장기능 조회 

jupyter labextension list

 

확장기능을 사용하기위해 npm과 nodejs를 깔아주어야한다. 

apt install npm

 

nodejs는 아래처럼 설치해도 되나 10 버전 이상부터 깔리는 확장기능이 있어 14.15.1 버전 저렇게 찾아서 설치하면 된다.

 

sudo apt install nodejs

 

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

source ~/.bashrc

nvm list-remote

nvm install v14.15.1

 

 

ipywiget 설정 : 모르면 왠만하면 하는게 좋다.

jupyter labextension install @jupyter-widgets/jupyterlab-manager

#jupyter lab 버전에 맞게 설치해주면 되며 2점대버전은 아래와 같다.

jupyter labextension install @jupyter-widgets/jupyterlab-manager@2.0

 

실행시간 출력되게 설정

jupyter labextension install jupyterlab-execute-time

 

 Settings->Advanced Settings Editor->Notebook에서 세팅을 아래 부분을 바꾸면되는데 아래 그림과 같이 한 후 저장!

{"recordTiming": true}

 

 

메모리 및 CPU설정 조회 

 

jupyter labextension install jupyterlab-topbar-extension jupyterlab-system-monitor

conda install -c conda-forge nbresuse

cpu 개수 확인

grep ^processor /proc/cpuinfo | wc -l

 

 

구글드라이브 설정

jupyter labextension install @jupyterlab/google-drive

 

console.cloud.google.com/apis

 

Google Cloud Platform

하나의 계정으로 모든 Google 서비스를 Google Cloud Platform을 사용하려면 로그인하세요.

accounts.google.com

 

 

 

API 및 서비스 사용 설정 클릭

 

 

 

 

 

 

 

 

 

 

 

깃허브 설정

jupyter labextension install @jupyterlab/github

 

깃 설정

conda install -c conda-forge jupyterlab jupyterlab-git

jupyter lab build

vi ~/.jupyter/jupyter_notebook_config.py

c.JupyterLabGit.actions = {"post_init": ["touch dummy_init.dat"]}

변수목록 조회 기능

jupyter labextension install @lckr/jupyterlab_variableinspector

 

leaflet 기능 사용가능하게 설정

conda install -c conda-forge ipyleaflet
jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter-leaflet

 

matplotlib 조절 가능하게 설정

conda install -c conda-forge ipympl

jupyter labextension install @jupyter-widgets/jupyterlab-manager

jupyter lab build

 

 

목차설정

jupyter labextension install @jupyterlab/toc

 

kite 설정(자동완성기능)

bash -c "$(wget -q -O - https://linux.kite.com/dls/linux/current)"

pip install jupyter-kite

jupyter labextension install "@kiteco/jupyterlab-kite"

drawio 설정

jupyter labextension install jupyterlab-drawio

 

debugging 설정

conda install -c conda-forge xeus-python

jupyter labextension install @jupyterlab/debugger

 

대시 설정 (설치실패)

conda install -c plotly -c defaults -c conda-forge "jupyterlab>=1.0" jupyterlab-dash=0.1.0a3

jupyter labextension install jupyterlab-dash

 

그림 코드 추출 (설치실패)

jupyter labextension install nbgather

conda install -c conda-forge itkwidgets

 

SQL 연결 

conda install -c conda-forge pymapd nodejs

pip install jupyterlab-omnisci

jupyter labextension install @jupyter-widgets/jupyterlab-manager --no-build

jupyter labextension install jupyterlab-omnisci

 

 

 

이메일 연동

pip install jupyterlab_email

jupyter labextension install jupyterlab_email

jupyter serverextension enable --py jupyterlab_email

 

vi ~/.jupyter/jupyter_notebook_config.py

c.JupyterLabEmail.smtp_servers = [{'name': 'gmail', 'domain': 'gmail.com', 'username': '<YOUR USERNAME>', 'smtp': 'smtp.gmail.com', 'port': 465}]

 

ufw allow 465

 

tensorboard 설정

jupyter labextension install jupyterlab_tensorboard

vi ~/.jupyter/jupyter_notebook_config.py

c.Spawner.cmd = ['jupyter-labhub']

 

오프라인으로 가상환경 생성

 

conda create -n <가상환경명> {python=3.6} {<패키지명=={버전}>}

위 형태가 기본 가상환경 만드는 형태

오프라인의 경우 패키지 설치가 안되므로 가상환경조차 생성되지 않음.

 

conda create -n <새로운 가상환경명> --clone <복제할 가상환경명>으로 가상환경 복제 가능

따라서 anaconda 설치 시 기본설치되는 root 를 복제하면 가상환경 생성이 가능

 

conda create -n test --clone root 혹은 conda create –n test --clone base

 

아나콘다 오프라인으로 가상환경 추출 및 설치

 

 

conda env list : 가상환경명 , 가상환경경로 확인 가능

conda list : 해당 가상환경에 패키지 목록 및 버전 확인 가능

 

패키지는 아나콘다를 C드라이브에 설치했을 경우

C:\Users\<윈도우 사용자명>\anaconda3\envs\<가상환경명>\Lib\site-packages에 설치됨

 

conda pack을 활용하면 자료를 추출 가능

conda install –c conda-forge conda-pack conda pack설치

 

conda pack –n <추출할 가상환경명> -o <추출할 가상환경압축파일.tar.gz>

conda export 를 써서 패키지명을 추출 가능[생략]

 

 

 

 

 

'python' 카테고리의 다른 글

conda python 경로 인식못할 때  (0) 2020.11.28
jupyterlab 확장기능  (0) 2020.11.21
pyinstaller  (0) 2020.11.20
matplotlib 시각화 정리 [여러 그림 그리기, quiver plot]  (0) 2020.11.05
pypy  (0) 2020.08.31

pyinstaller

python2020. 11. 20. 13:24

 

 

 

 

 

 

 

 

 

In [1]:
import matplotlib
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
In [2]:
import os,re
files=[i for i in os.listdir(os.getcwd()) if re.compile('csv').findall(i)]
print(files)
 
['OBS_AWS_TIM_20201103160221.csv']
In [3]:
df=pd.read_csv(os.getcwd()+'/'+files[0],encoding='cp949')
u=np.sin(np.deg2rad(270-df['풍향(deg)']))*df['풍속(m/s)']
v=np.cos(np.deg2rad(270-df['풍향(deg)']))*df['풍속(m/s)']
In [4]:
df['일시']=pd.to_datetime(df['일시'])
df=df.set_index(['일시'])
In [5]:
df.head(1)
Out[5]:
  지점 지점명 기온(°C) 풍향(deg) 풍속(m/s) 강수량(mm) 현지기압(hPa) 해면기압(hPa) 습도(%)
일시                  
2020-10-20 966 풍도 17.3 330.5 2.1 0 1021.4 1025.9 77.7
In [6]:
df.columns
Out[6]:
Index(['지점', '지점명', '기온(°C)', '풍향(deg)', '풍속(m/s)', '강수량(mm)', '현지기압(hPa)',
       '해면기압(hPa)', '습도(%)'],
      dtype='object')
 

폰트 설정

In [7]:
import matplotlib.font_manager as fm
font=fm.get_fontconfig_fonts()[11]
font
Out[7]:
'/usr/share/fonts/truetype/nanum/NanumGothicLight.ttf'
In [8]:
font_name = fm.FontProperties(fname=font).get_name()
#matplotlib.rc('font', family=font_name)
matplotlib.rc('font',family='NanumBarunGothic.ttf')
#'C:/Windows/Fonts/malgun.TTF'
 

마이너스 부호

In [9]:
matplotlib.rcParams['axes.unicode_minus']=False
 

figure 기본옵션

In [10]:
plt.figure(num=None, figsize=[6.4,4.8], dpi=100, facecolor='white', edgecolor='w', frameon=True)
plt.plot([1,2,3])
Out[10]:
[<matplotlib.lines.Line2D at 0x7ff568f5e438>]
 
 
 
 

여러개로 된 그래프 한번에 그릴 때 옵션 조절하기

In [11]:
matplotlib.gridspec.GridSpec(nrows=3, ncols=3,left=0.1, bottom=0.15, right=0.94, top=0.94, wspace=0.3, hspace=0.3\
                             ,width_ratios=None,height_ratios =None)
Out[11]:
<matplotlib.gridspec.GridSpec at 0x7ff56c34b320>
In [12]:
# equivalent but more general
ax1=plt.subplot(2, 2, 1)
# add a subplot with no frame
ax2=plt.subplot(222, frameon=False)
# add a polar subplot
plt.subplot(223, projection='polar')
# add a red subplot that shares the x-axis with ax1
plt.subplot(224, sharex=ax1, facecolor='red')
# delete ax2 from the figure
plt.delaxes(ax2)
# add ax2 to the figure again
plt.subplot(ax2)
Out[12]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff568ec0e48>
 
 
 
In [13]:
fig, ax = plt.subplots(2,3)
plt.show()
 
 
 
In [14]:
fig = plt.figure()
#fig를 shape으로 나눴을 때 rowspan, colspan만큼 차지하며 위치는 loc로 찾음
ax1 = plt.subplot2grid(shape=(3,3),loc=(0,0),rowspan=1,colspan=1)
ax2 = plt.subplot2grid(shape=(2,2),loc=(1,1))
plt.show()
 
 
 
In [15]:
df.columns
Out[15]:
Index(['지점', '지점명', '기온(°C)', '풍향(deg)', '풍속(m/s)', '강수량(mm)', '현지기압(hPa)',
       '해면기압(hPa)', '습도(%)'],
      dtype='object')
In [16]:
defaultColor=['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf']
In [17]:
plt.scatter(df.index,df['기온(°C)'],s=20,c=defaultColor[0],marker='o',label='기온(°C)',edgecolors='black')
plt.grid()
plt.tight_layout() 
plt.ylim((0,20))
plt.yticks(range(0, 20, 5),fontsize=15)
plt.gca().yaxis.set_major_formatter(plt.matplotlib.ticker.StrMethodFormatter('{x:,.0f} °C'))
plt.ylabel('시정(m)',fontsize=20,rotation=30)
plt.gca().axhline(12, linestyle='--', color='gray',alpha=.3) 
plt.axvspan(pd.to_datetime('2020-10-20 01'), pd.to_datetime('2020-10-22 15'), color='red', alpha=0.2,label='dd')
plt.legend(loc='lower right', prop={'size': 15},scatterpoints=300,bbox_to_anchor=(1, 1))
import matplotlib.dates as md
xfmt = md.DateFormatter('%m/%d %H')
plt.gca().xaxis.set_major_formatter(xfmt)
plt.legend(loc=4,bbox_to_anchor=(0.45,-0.28),framealpha=0.0,fontsize=15,ncol=2)
 
 
Out[17]:
<matplotlib.legend.Legend at 0x7ff568c77710>
 
In [18]:
fig=plt.figure()
host= plt.subplot()
ax1 = host.twinx()
host.yaxis.set_label_coords(0.06,1.03)
host.set_ylabel(host.get_ylabel(), rotation=0, labelpad=20,fontsize=20)
ax1.spines['right'].set_position(('axes',1.11))
plt.tight_layout()
p0,=plt.plot([1,2,3])
ax1.plot([4,7,8])
host.tick_params(axis='y', colors=p0.get_color(), direction='in')
ax1.tick_params(axis='y',  direction='in')
host.spines["left"].set_visible(False)
ax1.spines["left"].set_edgecolor(p0.get_color())
 
 
 
In [19]:
x=df.index
k=1
plt.quiver(x[::k],np.zeros(len(x))[::k],u.values.tolist()[::k],v.values.tolist()[::k],scale_units='y',angles='uv',scale=1,width=.0008)
plt.ylim(-10,10)
plt.axis('off')
Out[19]:
(737717.7520833333, 737723.20625, -10.0, 10.0)
 
 
 

'python' 카테고리의 다른 글

아나콘다 오프라인 가상환경 생성 , 가상환경 추출 및 설치  (0) 2020.11.20
pyinstaller  (0) 2020.11.20
pypy  (0) 2020.08.31
python package 생성  (0) 2020.08.17
python gridSearch, RandomSearch  (0) 2020.07.30