There is a lot of information about installing pyenv, but ubuntu leaves a solution to the problem that the path is overwritten with secure_path when using sudo and pyenv is not recognized.
The official GitHub repository is here [https://github.com/pyenv/pyenv)
environment OS: Debian 9.0 stretch Python: 3.6.3
update 2019.01.29 Changed apt-get to apt
First you need to include git to install pyenv. ((Y / n) during installation should be Y (meaning = Yes))
sudo apt update
sudo apt install -y git
Clone the repository from github.
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
Then add the path to .profile (.bash_profile). (By the way → ". Bash_profile? .Bashrc? There are various things, where and what?")
(For first-time users)
If you use ls -al ~ /
once to check if there is a .profile under / home / USERNAME
, it may not be wasted.
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.profile
This is the process of setting the environment variable * PYENV_ROOT * in the first line and adding * PYENV_ROOT / bin * to the environment variable * PATH * in the second line. Now apply the added settings by reloading .profile (.bash_profile).
source ~/.profile
Reloaded the .profile.
Of course, open .profile (.bash_profile) using some editor such as vim
sudo vim ~/.profile
It is the same even if the following is added.
export PYENV_ROOT=$HOME/.pyenv
export PATH=$PYENV_ROOT/bin:$PATH
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
afterwards
which pyenv
To run
/home/USERNAME/.pyenv/bin/pyenv
If you get a result like this, it's OK.
This is a solution to the problem that PATH is not inherited and an error occurs at `$ sudo pyenv```. There are various solutions, but the following seems to be the best, so I referred to it. The same thing happens in Debian, but pyenv install is possible without sudo, so I think the following should be handled only for ubuntu. [[Ubuntu] How to take over PATH when sudo](http://qiita.com/hidekuro/items/0f8acd0504baa6efde34) In addition, please change **
USERNAME``` part to your own user name. ** **
sudo groupadd developer
sudo gpasswd --add USERNAME developer
sudo visudo
Defaults exempt_group="developer"
After this, be sure to log in to ssh again.
Before that, install the necessary tools.
sudo apt install -y gcc make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
And here, let's check what can be installed now.
pyenv install --list
The items that can be installed are listed.
Here we will install Python 3.6.3. ** (Note that mod_wsgi cannot be installed unless you add an option here) ** In case of ubuntu, please execute with sudo.
pyenv install 3.6.3
#Later mod as a python package_When installing wsgi, install with the following options
#env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.6.3
Make sure 3.6.3 is installed
pyenv versions
When you run
* system
3.6.3 (set by /home/USER_NAME/.pyenv/version)
You can see that 3.6.3 has been added in.
I think it's a good idea to change python and update pip to the latest version. By the way, here is the difference between global and local (→ Difference between pyenv local and pyenv global in pyenv). Since it is a tool that divides the environment, I think that basically local is often used. In case of ubuntu, please add sudo.
pyenv global 3.6.3
pip install --upgrade pip
Following pyenv, also install a plugin called pyenv-virtualenv.
git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv
It is an addition to .profile (.bash_profile).
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.profile
Apply the added settings by reloading .profile (.bash_profile) in the same way as pyenv.
source ~/.profile
Then try creating a new environment myenv
.
In ubuntu it is sudo.
pyenv virtualenv 3.6.3 myenv
#In addition, there is such an option
# --system-site-packages <-Use installed modules
# --no-site-packages <-A virtual environment is created with all installed modules removed
#For example, already 3.6.3 When inheriting the modules installed in the environment
# pyenv virtualenv --system-site-packages 3.6.3 myenv
You can see that myenv has been created by checking the list of versions.
pyenv versions
system
* 3.6.3 (set by /home/USERNAME/.pyenv/version)
3.6.3/envs/myenv
myenv
Recommended Posts