LoginSignup
0
0

More than 3 years have passed since last update.

Ubuntu 19.04でPythonのvirtualenv、virtualenvwrapperのインストール

Posted at

pipのインストール

sudo apt install python3-pip

virtualenv、virtualenvwrapperのインストール

sudo pip3 install virtualenv virtualenvwrapper

.bashrcに追記

~/.bashrc
...
export VIRTUALENVWRAPPER_PYTHON=`which python3`
export WORKON_HOME=~/venv/
source `which virtualenvwrapper.sh`

~/venv/はお好きなディレクトリ名を使ってください

.bashrcを読み込みます

. .bashrc

下記のように必要なディレクトリとファイルが作成されます

virtualenvwrapper.user_scripts creating /home/user_name/venv/premkproject
virtualenvwrapper.user_scripts creating /home/user_name/venv/postmkproject
virtualenvwrapper.user_scripts creating /home/user_name/venv/initialize
virtualenvwrapper.user_scripts creating /home/user_name/venv/premkvirtualenv
virtualenvwrapper.user_scripts creating /home/user_name/venv/postmkvirtualenv
virtualenvwrapper.user_scripts creating /home/user_name/venv/prermvirtualenv
virtualenvwrapper.user_scripts creating /home/user_name/venv/postrmvirtualenv
virtualenvwrapper.user_scripts creating /home/user_name/venv/predeactivate
virtualenvwrapper.user_scripts creating /home/user_name/venv/postdeactivate
virtualenvwrapper.user_scripts creating /home/user_name/venv/preactivate
virtualenvwrapper.user_scripts creating /home/user_name/venv/postactivate
virtualenvwrapper.user_scripts creating /home/user_name/venv/get_env_details

使用例:環境の作成

mkvirtualenv env_name -p 'which python3'

上記を実行するとプロンプトの前に(env_name)とつき、仮想環境に入ったのがわかります

あとは普通に

pip install package_name

してください。仮想環境でパッケージをインストールする際にはsudoはつけません

0
0
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
0