New information on this page has been added to the following pages. Building Python environment with anyenv (2017/10/21)
Build a Python environment that meets the following conditions on Mac
pyenv A tool that makes it easy to switch between multiple versions of Python. Changed for Python by forking from rbenv and ruby-build.
virtualenv A tool for creating a separate Python environment. You can put different packages for each environment.
pyenv-virtualenv
pyenv plugin. Once installed, you will be able to use the pyenv virtualenv
command.
It seems that it is calling virtualenv internally.
$ brew install pyenv-virtualenv
~/.zshrc
# pyenv
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
export PYENV_ROOT=/usr/local/var/pyenv
# pyenv-virtualenv
if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi
$ source ~/.zshrc
Python
When installing Python 3.4.3. Execute the following.
$ pyenv install 3.4.3
In my environment, with 3.4.3 installation
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?
I got the error, so follow here
CFLAGS="-I$(brew --prefix openssl)/include" \
LDFLAGS="-L$(brew --prefix openssl)/lib" \
pyenv install -v 3.4.3
Was executed and installed.
$ pyenv install -l
$ pyenv versions
When creating a virtual environment for Python 3.4.3
$ pyenv virtualenv 3.4.3 myenv343
You can confirm that it is registered in the version of pyenv
$ pyenv versions
* system (set by /usr/local/var/pyenv/version)
3.4.3
myenv343
When creating a projecjt-a folder and setting the myenv343 environment
$ mkdir project-a
$ cd project-a
$ pyenv local myenv343
Now when you move to the project-a folder, you will automatically be in the environment of myenv 3.4.3.
$ cd project-a
(myenv343)$ python --version
Python 3.4.3
(myenv343)$ exit
$ cd ~
$ python --version
Python 2.7.10
$ pyenv uninstall myenv343
Recommended Posts