LoginSignup
4
5

More than 5 years have passed since last update.

[AWS] Python2.7環境にawscliとboto3をインストールするときの問題回避メモ

Last updated at Posted at 2016-11-12

はじめに

AWS LambdaのPythonのバージョンは、Python 2.7。
Windows Anaconda環境, Python 2.7環境にawscliとboto3をインストールするときの問題回避メモです。
回避する問題は下記の2点。

  1. win-64用のawscli, boto3パッケージが見つからない(Windows Anaconda環境で発生)

    > conda install awscli
    PackageNotFoundError: Package not found: '' Package missing in current win-64 channels:
      - awscli
    
    > conda install boto3
    PackageNotFoundError: Package not found: '' Package missing in current win-64 channels:
      - boto3
    

     

  2. Unicode Warning(Python 2.7環境で発生)
    コマンド例

    > aws s3 ls s3://<bucket_name>
    

    Anaconda2環境で発生するUnicodeWarning

    Anaconda2\lib\site-packages\dateutil\parser.py:605: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
      elif res.tzname and res.tzname in time.tzname:
    

    AWSCLIをmsiインストールした環境で発生するUnicodeWarning

    C:\Program Files\Amazon\AWSCLI\.\dateutil\parser.py:601: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
    

awscliのインストール

Windows環境の場合は、conda-forgeを指定します。

> conda install -c conda-forge awscli

boto3のインストール

Windows環境の場合は、conda-forgeを指定します。

> conda install -c conda-forge boto3

インストール状況の確認

  • Anaconda3

    > aws --version
    aws-cli/1.10.44 Python/3.5.2 Windows/10 botocore/1.4.34
    
  • Anaconda2

    > aws --version
    aws-cli/1.10.44 Python/2.7.12 Windows/10 botocore/1.4.34
    

※ awsコマンドは、AnacondaのScriptsフォルダにパスが通っている必要があります。

Python 2.7環境で発生するUnicode Warningの暫定対策

暫定対策ですが、UnicodeWarningを抑制します。

  • awsコマンド
    Anaconda2\Scripts\aws.cmd 19行目に-W ignore::UnicodeWarningを指定します。

    変更前.py
    %PythonExe% -x %PythonExeFlags% "%~f0" %*
    
    変更後.py
    %PythonExe% -W ignore::UnicodeWarning -x %PythonExeFlags% "%~f0" %*
    

    ※ AWSCLI64.msiをインストールしている場合はAWSCLI64.msiをアンインストールします。
     

  • pythonコマンド
    -W ignore::UnicodeWarningを指定します。
    Botoのサンプルを実行する場合の例

    > python -W ignore::UnicodeWarning .\s3_sample.py
    
  • IPython
    IPython起動時にUnicodeWarning抑制スクリプトを実行します。
    ~/.ipython/profile_default_startup or <user_home>\.ipython\profile_default\startup

    00-ignore-UnicodeWarning.py
    import warnings
    warnings.filterwarnings('ignore', category=UnicodeWarning)
    
4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5