0
2

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.

virtual environment in Python

Last updated at Posted at 2019-11-21

Overview

  • pyenv (Python version management)
  • pipenv (Python libraries' version management)
  • virtualenv

pyenvとpipenvを組み合わせるのが吉のよう。

pyenvとpipenvで開発

$pyenv versions (python version check)
$pyenv install 3.7.0 (install the version signified in the project)
$pyenv local 3.7.0 (set and fix python version in the project)
$pip install pipenv (if pipenv is not installed yet)
$pipenv --python 3.7.0 (create virtual env with python 3.7.0)
$pipenv shell (go into the virtual env)
$pipenv install some_package (even in the virtual env shell, use pipenv install, not pip install)
# ここで開発
$exit (go out of virtual env)

注意

After you pip install some packages in the project, notify that to other members who are working on other branches. This avoids the conflict of package versions when these branches are merged.

以下、それぞれを細かく説明。

Pipenvの詳細

# If you are the person who makes Pipfiles,,,  in the project root dir, launch python venv. This creates Pipfile and Pipfile.lock.
$pipenv --python 3.6
# If you would like to set up venv from Pipfiles made by another person, create venv and then install packages wirtten in Pipfiles
$pipenv install --deploy
(NOTE: --deploy causes build-fail when package has not been synced)
# Other commands
$pipenv import pandas==3.5  =  $pipenv run pip install pandas==3.5
# Import python package into venv
$pipenv --python
# Import python package (which is not used in src) into venv
$pipenv install --dev flake8
# terminate venv by deleting ve
pip env --rm 
# Go into the venv
$pipenv shell
# Go out of the venv
$exit

virtualenvの詳細

まずpythonのバージョンをpyenvで指定し、その後virtualenv環境(名前はtest)を構築。
終了後はtestディレクトリを消してやる。

$ cd ~/path_to/lambda_data_agg
$ pyenv local 3.6.0
$ virtualenv test
$ source test/bin/activate
$ pip install -r requirements.txt
# 作業
$ deactive
$ rm -rf test

requirements.txtの作り方/使い方

# create requirements.txt, at current directory
$ pipreqs .

# install packages listed in requirements.txt
$ pip install -r requirements.txt
0
2
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
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?