UnicodeDecodeError: 'utf-8' codec can't decode byte

AI빅데이터|2020. 3. 15. 10:18
반응형

다음과 같이 subprocess에서 받아온 값에 한글이 포함될 경우,

Abaconda prompt에서 py를 실행할 경우, 제목과 같은 오류가 발생한다.

 

<코드>

RLTrader = subprocess.Popen([envPath, exeFilePath], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, creationflags=subprocess_flags)
(stdout, stderr) = RLTrader.communicate(input=transData)
print("aftershock" + str(stdout))
RLTrader_results = stdout
RLTrader_results02 = RLTrader_results.decode()

 

<실행결과>

aftershockb'\xb0\xfc\xb8\xc1&&&0\r\n'
Traceback (most recent call last):
  File "pytrader4.py", line 517, in 
    SH.Start_of_RLTrader()
  File "pytrader4.py", line 294, in Start_of_RLTrader
    self.Requirement_of_current()
  File "pytrader4.py", line 425, in Requirement_of_current
    RLTrader_results02 = RLTrader_results.decode()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb0 in position 0: invalid start byte

 

 

RLTrader = subprocess.Popen([envPath, exeFilePath], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, creationflags=subprocess_flags)
(stdout, stderr) = RLTrader.communicate(input=transData)
print("aftershock" + str(stdout))
RLTrader_results = stdout 
RLTrader_results02 = RLTrader_results.decode(encoding='CP949')

 

이렇게 수정해 주니, 에러가 없어졌네요..

반응형

댓글()

ValueError: cannot convert float NaN to integer

AI빅데이터|2020. 3. 14. 15:43
반응형

Python pandas의 dropna() method를 사용해서

 

 - 결측값이 들어있는 행 전체 제거

   (delete row with missing values)

 - 결측값이 들어있는 열 전체를 제거

   (delete column with missing values)

 - 특정 행 또는 열 만을 대상으로 결측값이 들어있으면 제거

   (delete specific row or column with missing values)



출처: https://rfriend.tistory.com/263 [R, Python 분석과 프로그래밍의 친구 (by R Friend)]

 

Sample codes>

con = sqlite3.connect(self.databasePath)
sqlCode = "SELECT * From '%s'" % self.stock_code
chart_data = pd.read_sql(sqlCode, con, index_col=None)
chart_data = chart_data.reset_index(drop=True)
#print('chart_data after reset_indexing: ')
close = chart_data['close']
moving_mean = close.rolling(120).mean() # 120() 이동평균을 구한다.
moving_mean = moving_mean.dropna(axis=0)
moving_std = close.rolling(120).std() # 120() 이동표준편차를 구한다.
moving_std = moving_std.dropna(axis=0)

moving_mean02 = moving_mean.iloc[-1:]
print('moving_mean02: ')
print(moving_mean02)
moving_mean02 = int(pd.DataFrame(moving_mean02).values)
moving_std02 = moving_std.iloc[-1:]
moving_std02 = int(pd.DataFrame(moving_std02).values)
moving_std02 = moving_std02 * 3

반응형

댓글()

ModuleNotFoundError: No module named 'Crypto.Math'

AI빅데이터|2020. 2. 17. 07:35
반응형

exe 파일 생성을 위한 pyinstaller 실행시 발생하는 에러였습니다.

 

다음과 같은 순서대로 하기 실행하니, 없어졌습니다.

 

pip uninstall crypto

pip uninstall pycryptodome

pip install pycryptodome

 

다음으로 다시 실행..

 

conda install pycryptodome

conda uninstall crypto

conda install pyinstaller

 

하기 링크를 참조하였습니다.

https://stackoverflow.com/questions/57713994/modulenotfounderror-no-module-named-crypto-math

반응형

댓글()

AWS EC2 인스턴스 생성 후 Console화면 열기

AI빅데이터|2020. 2. 12. 00:39
반응형

AWS EC2 인스턴스 생성

- 선택: Ubuntu 18.02 버전, 프리티어 선택

 

1) SSH 접속

    해당 인스턴스의 public IP 와 user name: 'ubuntu' 사용하여 로그인한다.

2) 서버 Update

   $ sudo apt-get update

3) 가상환경 프로그램 설치 (virtualenv)
   $ sudo pip3 install virtualenv

4) Jupyter Notecbook 실행하기 위한 가상환경 생성 (venv)
  $ virtualenv venv

5) 가상환경 활성화
  $ source venv/bin/activate

6) 가상환경에서 Jupyter Notebook 설치
  $ sudo pip3 install notebook

7) 가상환경에서 설치된 프로그램 List 확인

  $ pip3 list

8) python3 이 정상적으로 실행되는지 확인
  $ python3

9) ipython 인터프리터에서 다음과 같이 실행하여 비밀번호 생성
   $ ipython

     (Console 화면)

    (venv) ubuntu@ip-172-31-15-177:~$ ipython
    /usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py:935: UserWarning: Attempting  

    to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.

    warn("Attempting to work in a virtualenv. If you encounter problems, please "
    Python 3.6.9 (default, Nov 7 2019, 10:44:02)
    Type 'copyright', 'credits' or 'license' for more information
    IPython 7.12.0 -- An enhanced Interactive Python. Type '?' for help.

    In [1]: from notebook.auth import passwd

    In [2]: passwd()
    Enter password:
    Verify password:
    Out[2]: 'sha1:015d71bac4da:deae4732e311fb67c3ab20ceb9d12244553e2440'

 

10) EC2의 Port를 Open 함 (아래의 예는 8888 Port)

11) Jupyter Notebook에 root 권한 부여 후 Background 에서 항상 실행되도록 함
   $ jupyter notebook --ip=0.0.0.0 --port=8888 --allow-root

   [Ctrl] + Z 입력하여 실행 종료

   $ bg
   $ disown -h

 

12) Public IP로 접속 후, 기 설정한 Password 입력하여 로그인

반응형

댓글()

pytorch jupyter notebook 실행시 OSError: [Errno 99] Cannot assign requested address

카테고리 없음|2020. 2. 12. 00:09
반응형

 

다음 순서대로.. update하고, jupyter설치한 다음

다음처럼 쭉 하나씩 처리하시면 됩니다.

어떤 분은 "$jupyter notebook --allow-root" 이럻게 하면 저런 에러 납니다.

 

$sudo apt update
$sudo apt install python3-pip
$sudo pip3 install -vU setuptools
$sudo pip3 install jupyter
$jupyter notebook --ip=0.0.0.0 --port=8888 --allow-root

 

참고 사이트: https://nevido.tistory.com/331

반응형

댓글()

No module named 'win32com'

AI빅데이터|2020. 2. 9. 14:47
반응형

>pyinstaller --noconfirm --log-level=WARN --onefile --nowindow main.spec

실행시마다, 다음 에러가 납니다.

 

208712 INFO: MKL libraries found when importing numpy. Adding MKL to binaries
Traceback (most recent call last):
  File "", line 2, in 
ModuleNotFoundError: No module named 'win32com'
Traceback (most recent call last):
  File "", line 2, in 
ModuleNotFoundError: No module named 'win32com'
232763 WARNING: lib not found: mpich2mpi.dll dependency of C:\ProgramData\Anaconda3\Library\bin\mkl_blacs_mpich2_lp64.dll
234256 WARNING: lib not found: impi.dll dependency of C:\ProgramData\Anaconda3\Library\bin\mkl_blacs_intelmpi_lp64.dll
235498 WARNING: lib not found: mpich2mpi.dll dependency of C:\ProgramData\Anaconda3\Library\bin\mkl_blacs_mpich2_ilp64.dll
236199 WARNING: lib not found: impi.dll dependency of C:\ProgramData\Anaconda3\Library\bin\mkl_blacs_intelmpi_ilp64.dll
236300 WARNING: lib not found: pgf90.dll dependency of C:\ProgramData\Anaconda3\Library\bin\mkl_pgi_thread.dll
236317 WARNING: lib not found: pgc14.dll dependency of C:\ProgramData\Anaconda3\Library\bin\mkl_pgi_thread.dll
236350 WARNING: lib not found: pgf90rtl.dll dependency of C:\ProgramData\Anaconda3\Library\bin\mkl_pgi_thread.dll

 

 

이때마다, 매번 다운받아둔, pywin32-221.win-amd64-py3.7.exe

를 다시 설치해 주고 있습니다.

 

그러면, 에러난 안나긴 하는데.. 맞는 방법인지 아직 검증은 못했습니다.

 

반응형

댓글()

MatplotlibDeprecationWarning

카테고리 없음|2020. 2. 8. 09:45
반응형

pyinstaller --noconfirm --log-level=WARN --onefile --nowindow main.pypyinstaller --noconfirm --log-level=WARN --onefile --nowindow main.spec

이렇게 만든 main.exe파일을 다음처럼 실행하니..Matplotlib 관련 에러가 납니다.

 

(venv) C:\Users\howard kim\PycharmProjects\newTestAI>main.exe
c:\users\howard kim\pycharmprojects\newtestai\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py:489: MatplotlibDeprecationWarning:
The MATPLOTLIBDATA environment variable was deprecated in Matplotlib 3.1 and will be removed in 3.3.
  exec(bytecode, module.__dict__)

 

해결 방법을 뒤져봅니다.. 

 

https://scripting.tistory.com/805 여기를 보니.. 다음과 같이 설명되어 있네요..

 

모두 설치를 한후 , 다시 exe파일을 만들어 봅니다.

반응형

댓글()

ModuleNotFoundError: No module named 'win32com'

AI주식자동매매|2020. 2. 8. 07:54
반응형

파이썬에서 다음 에러 발생시 조치 방법입니다.

ModuleNotFoundError: No module named 'win32com'

 

우선, 하기 사이트로 들어가셔셔..

https://sourceforge.net/projects/pywin32/

 

Python for Windows Extensions

Download Python for Windows Extensions for free. OLD project page for the Python extensions for Windows. This project has been migrated to github - please visit https://github.com/mhammond/pywin32 Please file all issues via github.

sourceforge.net

 

pywin32를 선택합니다.

 

그리고, Build221 선택하시고..

 

최종 버젼이나, 현재 사용하시는 버젼 선택하시면..됩니다.

다운 받으시고, 바로 setup 실행하시면 설치됩니다.

다음 누르고 설치하면 됩니다.

 

이런 에러때문에 난감했는데.. 

ModuleNotFoundError: No module named 'win32com'
Traceback (most recent call last):
  File "", line 2, in 
ModuleNotFoundError: No module named 'win32com'
92888 WARNING: lib not found: mpich2mpi.dll dependency of C:\ProgramData\Anaconda3\Library\bin\mkl_blacs_mpich2_ilp64.dll
92985 WARNING: lib not found: impi.dll dependency of C:\ProgramData\Anaconda3\Library\bin\mkl_blacs_intelmpi_ilp64.dll
94039 WARNING: lib not found: mpich2mpi.dll dependency of C:\ProgramData\Anaconda3\Library\bin\mkl_blacs_mpich2_lp64.dll
95095 WARNING: lib not found: impi.dll dependency of C:\ProgramData\Anaconda3\Library\bin\mkl_blacs_intelmpi_lp64.dll
96104 WARNING: lib not found: pgf90rtl.dll dependency of C:\ProgramData\Anaconda3\Library\bin\mkl_pgi_thread.dll
96116 WARNING: lib not found: pgf90.dll dependency of C:\ProgramData\Anaconda3\Library\bin\mkl_pgi_thread.dll
96119 WARNING: lib not found: pgc14.dll dependency of C:\ProgramData\Anaconda3\Library\bin\mkl_pgi_thread.dll

 

깔끔하게 해결이 되었는데..  

이거 

pyinstaller --noconfirm --log-level=WARN --onefile --nowindow main.py

를 실행할때마다, 위 에러가 또 나서..

그럴때마다, 

pywin32-221.win-amd64-py3.7.exe

이거 다시 실행해주고, 다시 하고 있습니다. ^^;;

 

win32com 설치하는건 하기 사이트를 참조했습니다. 감사합니다.

https://trialso88.tistory.com/125

 

반응형

댓글()