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
はつけません