Using multiple versions of Python on Mac OS X (2) Usage

Last time Using multiple versions of Python on Mac OS X (1) Multiple Ver installation Described how to install Python for each version using homebrew.

Now, let's use them concretely to create a Python execution environment.

Premise

I think there are various development styles, but for Python, I think that "using virtualenv to build and use a unique environment for each project without using a global environment" is currently easier. I will.

Since # Python3.3 has officially made it possible to build individual environments, we may move to that one in the future.

What is virtualenv?

It is a tool that allows you to build a number of Python execution environments that are independent of virtualenv, apart from the global ones. Not only the Python version but also various necessary libraries can be created separately for each environment, so prepare an environment created with virtualenv for each project and run the program in the environment under virtualenv including commercial deployment. I think there are many cases.

virtualenv can specify a Python interpreter separate from its own installation environment. In short, it is possible to do something like "Create a Python3 virtual environment with a virtualenv installed in a Python2.7 environment", so there is no need to put a virtualenv in both Python2 and 3 systems.

This time as well, put virtualenv only in 2.7 and do the subsequent work.

Install virtualenv

[~] pip install virtualenv

This one line is the end. pip is a python library management tool. Virtualenv has been installed under the environment of python2.7.

Try to create a unique environment

After installation, you can create a new environment with the following command.

[~] virtualenv --python=/usr/local/bin/python3 testenv

The Path of the Python interpreter you want to use is specified in the --python option (this time Python3.3 installed from homebrew last time).

testenv is the name of the unique environment created this time.

When this command is executed, a folder called testenv is created directly under the executed directory, and an independent Python execution environment is packed in it.

Switch environment

[~] source testenv/bin/activate
(testenv)[~]← Entered the testenv environment
(testenv)[~] python --version
Python 3.3.2


(testenv)[~] deactivate
[~]← Exited the testenv environment and returned to the global environment

This is just one line. You can enter the testenv environment created this time just by executing activate under (virtual environment name) / bin. It's easy to understand because the environment you are in is displayed in parentheses.

Notice that the Python version is that of the interpreter specified by --python. You can deactivate when you exit.

that's all!

Currently, there is no specific project, I just want to play with Python, but ... for the time being

However, I think that you should give an environment name and install various libraries in it. Library installation

pip install (Library name)

so.

sudo pip install (Library name)

Please note that even though the environment has been cut off uniquely, it will enter the global market.

#bonus There is also a wrapper that can manage virtualenv, such as virtualenvwrapper, with a single workon command.

Is possible. If you create the environment in a directory somewhere, it will not be so complicated and I think it is simple enough, so I do not use it, but if you are interested, please search. </ del> The previous statement is withdrawn (^^; ゞ It's convenient, so if you are interested, please see this article for the installation method and usage.

Recommended Posts

Using multiple versions of Python on Mac OS X (2) Usage
Using multiple versions of Python on Mac OS X (1) Multiple Ver installation
How to build an environment for using multiple versions of Python on Mac
Using NAOqi 2.4.2 Python SDK on Mac OS X El Capitan
Run Zookeeper x python (kazoo) on Mac OS X
Shpinx (Python documentation builder) on Mac OS X
Install multiple versions of Python
Handling of python on mac
Memo on Mac OS X
Try using E-Cell 4 on Windows 7 or Mac OS X
Build a Python development environment on Mac OS X
Install Sphinx on Mac OS X
Installation of scikit-learn (Mac OS X)
Install mitmproxy on Mac OS X
Environment construction of python3.8 on mac
Easy on Mac! Plot of unit step response using Python
Install pgmagick on Mac OS X 10.9
Get started with the Python framework Django on Mac OS X
Continuation ・ Notes on preparing the Python development environment on Mac OS X
Install lp_solve on Mac OS X and call it with python.
How to install Theano on Mac OS X 10.10 (using pyenv, anaconda)
Installed aws-cli On Mac OS X Lion
How to erase Python 2.x on Mac.
Install multiple versions of Polyphony using venv
Study on Tokyo Rent Using Python (3-1 of 3)
Video processing using Python + OpenCV on Mac
Run NASA CEA on Mac OS X
python on mac
Notes on setting pyenv and python environment using Homebrew on Mac OS Marvericks
I tried putting various versions of Python + OpenCV + FFmpeg environment on Mac
Use multiple versions of python environment with pyenv
Put Python 2.7.x on Mac OSX 10.15.5 with pyenv
I installed Pygame with Python 3.5.1 in the environment of pyenv on OS X
Install Python on Mac
Install Python 3 on Mac
Usage of Python locals ()
Install Python 3.4 on Mac
Preparing to use aws cli on Mac OS X
Building an environment for "Tello_Video" on Mac OS X
Build a machine learning Python environment on Mac OS
Very easy to install SciPy on Mac OS X
Build a Python environment on your Mac using pyenv
mac OS X 10.15.x pyenv Python If you can't install
Install PyQt5 with homebrew on Mac OS X Marvericks (10.9.2)
Minimum memo when using Python on Mac (pyenv edition)
Create a Python development environment on OS X Lion
pangolin x python x mac os build failed memorandum unsolved
Minimum notes when using Python on Mac (Homebrew edition)
When import tkinter is not possible on Mac OS X 10.11.3 (El Capitan) + pyenv + Python 3.5.1.
[Is it explosive !?] Setup for using the GPU version of Tensorflow on OS X
Steps to use the AWS command line interface (Python / awscli) on Mac OS X
[Python] Correct usage of map
Word Count with Apache Spark and python (Mac OS X)
Install pygame on python3.4 on mac
Building a Python environment on a Mac and using Jupyter lab
Put Python 3.x on Ubuntu
Test Python with Miniconda on OS X and Linux with travis-ci
Run Tensorflow 2.x on Python 3.7
python: Basics of using scikit-learn ①
Update python on Mac to 3.7-> 3.8
Install pandas 0.14 on python3.4 [on Mac]