반응형

python, anaconda 가상환경에서 파이썬 버전 확인 및 변경

 

VScode에서 인터프리터 연결이 제대로 안될때. 버전이 낮아서 인터프리터 실행못할때 확인 필요

 

가상환경이름을 p_pygame  이라고 가정하고.

 

0. conda  activate (가상환경명) : 가상환경 실행.

1. python -V : 파이썬 버전 확인.

2. conda search python : 사용 가능한 python list 확인.

3. conda install python=x.x.x : 입력 버전으로 파이썬 버전이 변경됨.

4. conda deactivate

5. conda activate p_pygame   : 가상환경 실행.

6. python -V : 변경된 파이썬 버전을 확인할 수 있음.

반응형
반응형
가상환경(virtualenv)은 여러 개의 파이썬 프로젝트가 하나의 컴퓨터에서 충동을 일으키지 않고 존재할 수 있도록 해줍니다. virtualenv는 각 프로그램별로 완전히 독립적인 가상의 환경을 만들어서 각 프로그램별로 라이브러리 모듈등의 버전을 별도로 지정할 수 있게 합니다. 즉 한 컴퓨터에 여러 개발환경을 서로 독립적으로 설치, 실행할 수 있게 해줍니다.
왜 가상 환경을 만들어서 작업을 진행할까? 한마디로 요약하자면 "독립적인 작업환경에서 작업할 수 있다." 로 말할 수 있습니다.
프로젝트를 진행하다보면 여러 라이브러리, 패키지를 다운로드하여서 사용하게 됩니다. 그러다 보면 각 라이브러리들끼리 충돌을 일으키는 문제를 발생시키는 경우가 있습니다. 또는, 특정 버전과 호환하는 경우가 생겨서 최신 버전과 이전 버전 중 선택해야 하는 상황이 발생됩니다. 가상환경은 각 프로그램별로 라이브러리 모듈 등의 버전을 별도로 지정할 수 있게 합니다. 즉 한 컴퓨터에 여러 개발환경을 서로 독립적으로 설치, 실행할 수 있게 해줍니다.
 
다음 명령어를 통해 가상환경이 만들어 집니다.
 
>conda create -n <환경명> python=<버전(ex:3.5이나 3.7 등)>
 
본 교재의 모든 예제들은 다음과 같은 명령으로 만들어 실행하도록 합니다. 본인 스스로 가상 환경을 관리할 수 있다면 다른 이름을 사용해도 관계없습니다.
 
>conda create -n koreait python=3.7
 
- koreait 은 가상환경 이름을 의미합니다.
- python=3.7 는 파이썬 3.7 환경으로 가상환경을 만들어라 하는 것 입니다. 다른 패키지들과의 호환성을 위해 본 교재는 파이썬 3.7를 사용합니다.
- numpy ~ statsmodels : 사용해야 할 라이브러리들을 지정할 수 있습니다. 필요시 pip install 을 사용하여 개별적으로 설치 할 수도 있습니다.
위의 명령을 실행하면 "c:\users\사용자계정\anaconda3\env\koreait" 라는 디렉토리가 생성되면서 그 안에 필요한 것들을 설치하겠냐고 묻게 됩니다. 당연히 "y" 를 눌러서 설치를 합니다.
내가 제대로 환경을 만들었는지 다음 명령을 실행하여 확인합니다.
>conda env list
내가 만든 환경이 리스트에 존재한다면 성공적으로 만들어 진 것입니다.
이후에 가상환경을 활성화하고 싶으면 activate 명령어로 해당 가상환경을 활성화합니다.
activate 가상환경명 혹은 conda activate 가상환경명
>conda activate koreait
>activate koreait
(base)표시가 (koreait) 으로 변경되었음을 볼 수 있습니다.
비활성화 시키고 싶으면 koreait 이 활성화되어 있는 상태에서
>deactivate 혹은 >conda deactivate
라고 해 주면 됩니다.
가상 환경을 제거하고 싶으면 아나콘다 터미널에서 (base)환경을 확인하고 다음을 입력한 후 실행하면 됩니다.
>conda remove -n name --all
만들어진 koreait 환경을 제거하고 다시 설치하고 싶다면 다음 명령으로 가상환경을 제거하고 다시 만들어 주시면 됩니다.
(base)>conda remove -n koreait --all
Anaconda Prompt에서 (koreait )이 표시되어 있다면 deactivate 를 입력하여 (base)환경으로 돌아옵니다. (base) 환경에서 python --version 을 실행해 봅니다. 그리고 “conda activate koreait ” 명령으로 가상환경 (koreait )을 활성화시킨 후 python --version 을 실행해 봅니다. (base) 환경에서 파이썬 버전은 3.7.2 이고 (koreait ) 환경에서 파이썬 버전은 3.5.6 이 적용됨을 확인할 수 있습니다.
가상환경 (koreait )에서 파이썬이 제대로 동작하는지 “Hello Workd” 예제를 사용하여 확인해 보자.
Anaconda Prompt에서 (koreait ) 환경에서 “python”을 입력합니다.
>>> 표시가 나타나면 print(“Hello World”) 를 입력하고 엔터를 누릅니다.
 
반응형
반응형

conda update

 


Anaconda Prompt 에 들어오면 conda 패키지 관리자를 사용할 수 있게 됩니다.


> conda activate main

1.우선 conda 자체를 업그레이드 해줍니다.

> conda update -n base conda

2.다음으로 설치된 파이썬 패키지를 모두 최신 버전으로 업데이트 해줍니다.

>conda update -all 

3. tensorflow 를 설치합니다

>pip install tensorflow 

4.keras도 설치해줍니다

>pip install keras
반응형
반응형

mpld3 - Bringing Matplotlib to the Browser

https://mpld3.github.io/install.html

 

Installing mpld3 — Bringing Matplotlib to the Browser

Dependencies The mpld3 package is compatible with Python versions 2.6, 2.7, 3.3, and 3.4. It requires matplotlib version 1.3+ and jinja2 version 2.7+. Optionally, mpld3 can be used within the IPython notebook, and requires IPython version 1.0+, and prefera

mpld3.github.io

 mpld3는 매트플롯립과 d3js를 사용해서 웹의 인터랙티브 데이터 시각화 를 가능하도록 만드는 것이 목적이라고 하네요. 간단하게, matpllitb의 그래픽을 html코드로(코드를 뜯어보면, 사실 거의 d3js 코드입니다만), 변환해줍니다. 이걸 가지고, 차트 같은 것을 좀 더 편하게 변환할 수 있겠죠.

https://anaconda.org/conda-forge/mpld3

Installers

Info: This package contains files in non-standard labels.

conda install 

  •  linux-64  v0.3
  •  win-32  v0.3
  •    noarch  v0.5.7
  •  osx-64  v0.3
  •  win-64  v0.3
To install this package with conda run one of the following:
conda install -c conda-forge mpld3
conda install -c conda-forge/label/gcc7 mpld3
conda install -c conda-forge/label/cf201901 mpld3
conda install -c conda-forge/label/cf202003 mpld3
반응형
반응형

 

Mlxtend (machine learning extensions) is a Python library of useful tools for the day-to-day data science tasks.

 

https://github.com/rasbt/mlxtend 

 

GitHub - rasbt/mlxtend: A library of extension and helper modules for Python's data analysis and machine learning libraries.

A library of extension and helper modules for Python's data analysis and machine learning libraries. - GitHub - rasbt/mlxtend: A library of extension and helper modules for Python's data an...

github.com

Installing mlxtend

PyPI

To install mlxtend, just execute

pip install mlxtend  

Alternatively, you could download the package manually from the Python Package Index https://pypi.python.org/pypi/mlxtend, unzip it, navigate into the package, and use the command:

python setup.py install

Conda

If you use conda, to install mlxtend just execute

conda install -c conda-forge mlxtend 

반응형
반응형

 

pip install pandas 

 

conda install -c anaconda pandas 

When working with tabular data, such as data stored in spreadsheets or databases, pandas is the right tool for you. pandas will help you to explore, clean, and process your data. In pandas, a data table is called a DataFrame.

반응형
반응형

1. Anaconda 3버전과 Visual Studio Code (이하 vscode) 준비

(일반 Python을 사용하시는 분은 pip을 같이 설치해주세요)

 

2. vscode에 Python (Microsoft) Extension 설치

 

3. 가상환경에 autopep8 패키지 설치 (PEP8 기준 자동정렬 기능 추가)

(아나콘다 기준)  conda install --name 가상환경명 autopep8

(pip 기준)  pip install autopep8

 

위의 명령어로 직접 설치하지 않아도 vscode 내에서 자동정렬 키를 누르면 패키지를 설치하겠냐는 팝업이 뜹니다.

 

4. 가상환경에 pylint 패키지 설치 (구문오류 체크)

(아나콘다 기준)  conda install --name 가상환경명 pylint

(pip 기준)  pip install pylint

 

위의 명령어로 직접 설치하지 않아도 저장이나 build 시 패키지를 설치하겠냐는 팝업이 뜹니다.

 

 

5. 마우스 우클릭 혹은 Command Palette(F1키)에서 Run Python File in Terminal을 선택하면 Terminal에서 실행

 

입맛에 따라 단축키를 지정해주시면 빠르게 실행결과를 볼 수 있습니다.


[오류]conda: 'conda' 용어가 cmdlet,함수,스크립트 파일 또는 실행할 수 있는 프로그램 이름으로 인식되지 않습니다.

 

VSCODE 에서 python 연동하기. 

 

Visual Studio Code의 기본 터미널이 Windows의 Power Shell로 설정되어 있기 때문.

 

    "terminal.integrated.defaultProfile.windows":"Command Prompt",
    "python.terminal.activateEnvInCurrentTerminal": true

settings.json에서 cmd.exe 추가하고, python.terminal.activateEnvInCurrentTerminal : true 로 변경하면  

해당 편집파일에서 "Run Python File" 실행시 cmd 실행되면서 python ENV 가 activate가 되면서 파일이 실행 된다. 

 

 

 

 

 

https://velog.io/@dbal9357/conda-conda-%EC%9A%A9%EC%96%B4%EA%B0%80-cmdlet%ED%95%A8%EC%88%98%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8-%ED%8C%8C%EC%9D%BC-%EB%98%90%EB%8A%94-%EC%8B%A4%ED%96%89%ED%95%A0-%EC%88%98-%EC%9E%88%EB%8A%94-%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%A8-%EC%9D%B4%EB%A6%84%EC%9C%BC%EB%A1%9C-%EC%9D%B8%EC%8B%9D%EB%90%98%EC%A7%80-%EC%95%8A%EC%8A%B5%EB%8B%88%EB%8B%A4

 

[오류]conda: 'conda' 용어가 cmdlet,함수,스크립트 파일 또는 실행할 수 있는 프로그램 이름으로 인식

원인 Visual Studio Code의 기본 터미널이 Windows의 Power Shell로 설정되어 있기 때문.해결이 기본 터미널의 종류를 cmd 또는 Git Bash로 변경하면 오류없이 실행이 가능.방법setting.json파일이 열리면 ""안에 c

velog.io

 

반응형
반응형



** 설치된 모듈의 위치정보 등 알아내기


    --  pip show  설치된모듈이름



 



TensorFlow on Windows: “Couldn't open CUDA library cudnn64_5.dll”




First of all, note that cuDNN is not distributed with the rest of the CUDA toolkit, so you will need to download it separately from the NVIDIA website. On Windows, it is distributed as a ZIP archive, so you must extract it and find the directory containing cudnn64_5.dll. For example, if you extract it to C:\tools\cuda, the DLL will be in C:\tools\cuda\bin\cudnn64_5.dll. Finally, you can add it to your path by typing the following at the command prompt:


C:\> set PATH=%PATH%;C:\tools\cuda\bin

C:\> python

...

>>> import tensorflow as tf


 

 I didn't have such issues with TensorFlow 0.12.1 (installed with pip install tensorflow==0.12.1):

 



---------------------------------------------------------------------------------

KNL

---------------------------------------------------------------------------------


matplotlib install  -  http://matplotlib.org/faq/installing_faq.html


> pip install matplotlib


or 


> git clone git://github.com/matplotlib/matplotlib.git

> cd matplotlib

> python setup.py install

> python setup.py develop


matplotlib test 

http://matplotlib.org/faq/howto_faq.html#how-to-search-examples


---------------------------------------------------------------------------------


konlpy install - http://konlpy.org/ko/v0.4.3/install/


> pip install --upgrade pip

> pip install JPype1-0.5.7-cp27-none-win_amd64.whl


> pip install konlpy


Binary Install

Ensure you have installed Anaconda/Miniconda. Instructions can be found here.

Install from the conda-forge software channel:


conda install -c conda-forge jpype1


$ pip install wheel


jpype  download : http://www.lfd.uci.edu/~gohlke/pythonlibs/#jpype


---------------------------------------------------------------------------------


JAVA_HOME 설정 

java 설치 - http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html


환경변수 - JAVA_HOME  C:\Program Files\Java\jdk1.8.0_121


---------------------------------------------------------------------------------


To install this package with conda run: https://anaconda.org/anaconda/gensim


> conda install -c anaconda gensim=1.0.1


To install this package with conda run: https://anaconda.org/anaconda/scipy


> conda install -c anaconda scipy=0.19.0



---------------------------------------------------------------------------------


sklearn install


https://sourceforge.net/projects/scikit-learn/files/


sklearn test 

http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html


---------------------------------------------------------------------------------


Activate the conda environment by issuing the following command:


C:> activate tensorflow

 (tensorflow)C:>  # Your prompt should change 




예제 :: 

Saved model checkpoint to D:\PythonProject\cnn-text-classification-tf-master\runs\1490667625\checkpoints\model-1000



word2vec_example - https://gist.github.com/solaris33/8ce9913dea1aa4225876cbcfdd2963be#file-word2vec_example-py



Pycharm & tensorflow & Anaconda = http://yeramee.tistory.com/1


anaconda > tensorflow install : http://www.lfd.uci.edu/~gohlke/pythonlibs/#tensorflow





starting jupyter notebook

> jupyter notebook 

or 

> jupyter notebook --port 9999





5-1. 텐서플로우(TensorFlow)를 이용해 자연어를 처리하기(NLP) – Word Embedding(Word2vec) :: http://solarisailab.com/archives/374


jupyter notebook 사용하기 : http://goodtogreate.tistory.com/entry/IPython-Notebook-%EC%84%A4%EC%B9%98%EB%B0%A9%EB%B2%95




.

반응형

+ Recent posts