Sunday, July 11, 2021

Python virtual environment in MacOS

On mac osx, default python is version 2, to support system pre-installed packages.


To try python3 environment, one option is using virtual environment, which allows installing different packages in isolated environment.


ref: https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/

With python2, install virtualenv

With python3, built-in module is    'venv'



    $ python3 -m pip install --user --upgrade pip     # update pip3


    $ python3 -m pip --version    # check version 


## assume venv for python3

# reuse  ~/.virtualenv  as the root for all new environments


    cd ~/.virtualenv


# (one time only) create new environment for python3


    $ python3 -m venv  py3


## use of environment from now on

# 1) using environment


    $ source py3/bin/activate


    $ which python        # should be within env now


# now can install diff python3 packages for testing


# 2) leaving venv


    $ deactivate



Labels: , , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home