Things to watch out for when creating a Python environment on a Mac

Since I replaced the machine, I stumbled on various things when I built the Python environment for the first time in a while, so make a note.

Reference page

http://d.hatena.ne.jp/nakamura001/20111129/1322579170 http://www.sicafe.net/macPackageManageTips/html/homebrewPythonInstall.html http://yono.hatenablog.jp/entry/20100923/1285235346 http://mzmttks.blogspot.jp/2011/12/python-site-packagesdist-packages.html http://hello-hello-world.blogspot.jp/2011/09/pythonsite-packages.html

Python is installed by default on Mac.

However, when building a development environment, I don't want to pollute the standard environment, or I need a different version of Python, so I often install it separately.

However, if you do a half-finished setup, the library installation destinations will be mixed unintentionally when installing the library, and the package you should have installed may be missing.

easy_install is already included

/usr/bin/easy_install

But pip was installed from the official installer

/usr/local/bin/pip

It's sloppy. Furthermore, if Python is under / opt, it will be even more chaotic.

For example, the standard python site_packages are:

/Library/Python/2.7/site-packages

For python installed with MacPorts, it will be as follows.

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages

Well, basically, if you use it only in virtualenv, there will be no problem.

Standardize Python installed with MacPorts

This is a case of creating an environment for Python using MacPorts, aside from the details, as it involves historical issues specific to Python.

  1. First of all, python body

$ sudo port install python27

 1. Then easy_install. For some reason setuptools doesn't support select, so easy_install uses a command like easy_install-2.7 to match the destination python.

	```bash
$ sudo port install py27-setuptools

If an error occurs here, it will appear in the error log, but you can fix it with the following command. By the way, in my case, it occurred in the environment after executing the official get_pip.py with python that was put in the port.

```bash

sudo port -f activate py27-distribute ```

  1. Next, put pip in port as well. Switch between standard pips with select.

$ sudo port install py27-pip $ sudo port select --set pip pip27

 1. Virtualenv relationship.
	
	```bash
$ sudo port install py27-virtualenv py27-virtualenvwrapper
$ sudo port select --set virtualenv virtualenv27
$ echo -e "\n# virtualenv\nexport WORKON_HOME=\$HOME/.virtualenvs\nsource `which virtualenvwrapper.sh-2.7`\n" >> ~/.bashrc

Virtualenv can be switched with select. Note that virtualenvwrapper does not have select.

How to find the path

How to find out the path referenced by python

python -c "import site; print(site.getsitepackages())"

Reference to distribute

python -c "import distutils.sysconfig as s; print(s.get_python_lib())"

Recommended Posts

Things to watch out for when creating a Python environment on a Mac
Things to watch out for when using default arguments in Python
Things to watch out for when migrating with Django
Building a Python environment on Mac
Create a Python environment on Mac (2017/4)
Create a virtual environment for python on mac [Very easy]
Create a python environment on your Mac
Creating amateur python environment settings (for MAC)
[Mac] Building a virtual environment for Python
Creating a python virtual environment on Windows
Things to watch out for when naming dynamic routing in nuxt.js
Build a Python environment on Mac (Mountain Lion)
Build a Python development environment on your Mac
A memo when creating a python environment with miniconda
Commands for creating a python3 environment with virtualenv
Procedure for creating a Python quarantine environment (venv environment)
A memo for creating a python environment by a beginner
I want to create a nice Python development environment for my new Mac
How to build an environment for using multiple versions of Python on Mac
[Grasshopper] When creating a data tree on Python script
Build a local development environment for Laravel6.X on Mac
Build a machine learning Python environment on Mac OS
Notes on creating a python development environment on macOS Catalina
How to build a Django (python) environment on docker
Build a Python development environment on Mac OS X
Things to note when initializing a list in Python
Build a Python environment on your Mac using pyenv
Procedure for building a CDK environment on Windows (Python)
How to build a development environment for TensorFlow (1.0.0) (Mac)
Building a Python environment for programming beginners (Mac OS)
How to build a Python environment on amazon linux 2
Python environment construction For Mac
Update python on Mac to 3.7-> 3.8
How to build a beautiful Python environment on a new Mac and install Jupter Notebook
Create a Python (pyenv / virtualenv) development environment on Mac (Homebrew)
How to build a new python virtual environment on Ubuntu
Building a Python environment on a Mac and using Jupyter lab
Dockerfile for creating a data science environment based on pip3
Build a python data analysis environment on Mac (El Capitan)
Build a Python extension for E-Cell 4 on Mac OSX (Yosemite)
When you want to hit a UNIX command on Python
Build a python environment on CentOS 7.7 for your home server
Error when building mac python environment
Building a Python environment on Ubuntu
I want to set up a GUI development environment with Python or Golang on Mac
Python environment construction memo on Mac
When creating a pipenv environment, I got addicted to "Value Error: Not a valid python path"
Create a python environment on centos
Environment construction of python3.8 on mac
Precautions when creating a Python generator
Python3 TensorFlow for Mac environment construction
Steps to install python3 on mac
Build a python3 environment on CentOS7
Update Python on Mac from 2 to 3
Create a Python environment for professionals in VS Code on Windows
How to rebuild python environment from pyenv on Mac environment (El Capitan)
Build a Python environment on your Mac with Anaconda and PyCharm
Things to keep in mind when deploying Keras on your Mac
From building a Python environment for inexperienced people to Hello world
Things to note when running Python on EC2 from AWS Lambda
How to build a Python environment using Virtualenv on Ubuntu 18.04 LTS