3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[自分用]python環境構築(pyenv+pyenv-virtualenv)/GAE

Last updated at Posted at 2018-01-13

目的

python+pyenvでの環境構築はやったことあったけど、(python2系とpython3系の共存のため)
pyenv-virtualenvを入れるのが初+変なところで詰まったので備忘録用

  • GAE用の環境構築
  • python2.7

環境

  • ubuntu16.04

手順

pyenvを使ってAnacondaを入れる

  • anaconda2-5.0.1
  • anaconda3-5.0.1
    を入れる.

参考1):【随時更新】pyenv + Anaconda (Ubuntu 16.04 LTS) で機械学習のPython開発環境をオールインワンで整える
git cloneするときにsudoつけてしまってその後、source ~/.bashrcしようとしたら
許可がありませんになって困った。
sudo source ~/.bashrc はコマンドが見つかりませんでエラー。
そもそもはじめのgit cloneでsudoつけたのが原因。
すべてsudoなしで実行する。

pyenv-virtualenvを入れる

参考2):pyenv と pyenv-virtualenv で環境構築

pyenv-virtualenvをつかってtest環境を作ってみる

目的:test環境用にanaconda2のパッケージが使える仮想環境を作りたい

失敗例
$ pyenv virtualenv anaconda2-5.0.1 test

これだと、anacondaのパッケージが使えない、仮想環境ができてしまう

$ pyenv virtualenv --system-site-packages anaconda2-5.0.1 test
pyenv-virtualenv: ~/.pyenv/versions/anaconda2-5.0.1/envs/test already exists
continue with installation? (y/N) y
usage: conda [-h] [-V] command ...
conda: error: unrecognized arguments: --system-site-packages
Installing pip from https://bootstrap.pypa.io/get-pip.py...
pyenv: python: command not found

The `python' command exists in these Python versions:
  anaconda2-5.0.1
  anaconda3-5.0.1

error: failed to install pip via get-pip.py

どうやらpythonが呼び出せないらしい。
pythonを指定するコマンドを追加

$ pyenv virtualenv --system-site-packages --python ~/.pyenv/versions/anaconda2-5.0.1/bin/python2.7 anaconda2-5.0.1 test
continue with installation? (y/N) y
usage: conda [-h] [-V] command ...
conda: error: unrecognized arguments: --system-site-packages
Installing pip from https://bootstrap.pypa.io/get-pip.py...
pyenv: python: command not found

The `python' command exists in these Python versions:
  anaconda2-5.0.1
  anaconda3-5.0.1

error: failed to install pip via get-pip.py

うーん。だめみたい。

とりあえず

何が違うのかわかっていないがconda createでも作れるみたいなのでやってみる。
参考3):Anacondaの使い方 その3(よく使うコマンド一覧)

$ conda create --name test python=2.7 anaconda
Package plan for installation in environment ~/.pyenv/versions/anaconda2-5.0.1/envs/test:
(以下略

conda createだとなんかpathを通しているのではなく新たにインストールしてる?感
この環境は.pyenvの中にできるのね…anaconda2なのはconda createした時にlocal環境がanaconda2-5.0.1だったから?

local環境に適用するときは、

$ pyenv local anaconda2-5.0.1/envs/test

ちなみにこれの後に同名で、以下のようにやってみた結果

$ pyenv virtualenv anaconda2-5.0.1 test
pyenv-virtualenv: ~/.pyenv/versions/anaconda2-5.0.1/envs/test already exists
continue with installation? (y/N) y

CondaValueError: prefix already exists: ~/.pyenv/versions/anaconda2-5.0.1/envs/test

Installing pip from https://bootstrap.pypa.io/get-pip.py...
Requirement already up-to-date: pip in ~/.pyenv/versions/anaconda2-5.0.1/envs/testGAE/lib/python2.7/site-packages

PATHの追加

./.bashrc

$ export PATH="$HOME/.pyenv/shims:$PATH"

環境の切り替え

$ pyenv local test

GAEのセットアップ

参考4):(Python 開発環境のセットアップ)[https://cloud.google.com/python/setup]

$  pip install --upgrade google-cloud-storage
3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?