What Is the Most Compatible Way to Install Python Modules on a MAC

What is the most compatible way to install python modules on a Mac?

The most popular way to manage python packages (if you're not using your system package manager) is to use setuptools and easy_install. It is probably already installed on your system. Use it like this:

easy_install django

easy_install uses the Python Package Index which is an amazing resource for python developers. Have a look around to see what packages are available.

A better option is pip, which is gaining traction, as it attempts to fix a lot of the problems associated with easy_install. Pip uses the same package repository as easy_install, it just works better. Really the only time use need to use easy_install is for this command:

easy_install pip

After that, use:

pip install django

At some point you will probably want to learn a bit about virtualenv. If you do a lot of python development on projects with conflicting package requirements, virtualenv is a godsend. It will allow you to have completely different versions of various packages, and switch between them easily depending your needs.

Regarding which python to use, sticking with Apple's python will give you the least headaches, but If you need a newer version (Leopard is 2.5.1 I believe), I would go with the macports python 2.6.

Modules are installed using pip on OSX but not found when importing

Since your problem maybe caused due to various reason, I have listed down a few of them here :

  • This is possibly because of what ever is stated here : Pip installs but module is not found. Have updated the answer with newer link.

The link you were looking for : https://pythonhosted.org/setuptools/setuptools.html#development-mode

  • It may also happen if you have two versions of python installed. If the pip that you are accessing is of one version & the python interpreter used is another.

So just see to that you are using the same version of python to install and use the package.

You may fix this using alias,

First, set up a shell alias:

alias python=/usr/local/bin/python3

Then, type that at a prompt, or put it in your ~/.bashrc so that whenever you open python from the terminal the correct version opens.

  • If both of the above methods don't work for you then check this :

ImportError No module named or this

Mac: Can installing Python wrong break other codes etc.?

You can simply install a Python3 version. If you use Homebrew you can easy install a version with the following command:

brew install python3

After the installation you can check your currently python version:

python3 --version

At the end you can still run python scripts with Python2 by simply typing python.

I need 'python-support' on a Mac. Where can I find it?

update-python-modules does not update the modules to their latest version. It rebuilds the byte code for the existing modules and is intended to be used after upgrading Python to a new version. There's a similar script named python-updater in Gentoo.

I doubt you have any reason to have it on a Mac; Python versions usually only change with OS updates, and those clean out your site-packages. If you really need this exact functionality, you can use find like so:

find {,/Users/*}/Library/Python/*/ -name '*.py[co]' -exec rm {} \;

What is the best way to install python 2 on OS X?

Using MacPorts, you can install python 2.6, 2.7, 3.1 and 3.2 at the same time, with their own packages, without ever touching the built-in python.

numpy, scipy, matplotlib, and ipython are also available as ports for most of those python versions.

Moreover, if you install the python_select port, you'll be able:

  • to choose which one of those (plus the built-in python) is the "default" python;

  • to install python packages through easy_install/pip for the "selected" python, if they're not available as ports.

Add virtualenv to the mix, and you'll have a very, very flexible Python development environment.

As for your questions:

Q1: with MacPorts, no. while not a frequent user, I've installed and used matplotlib in 2.6 and 2.7, switching between the two using python_select.

Q2: easy_install, pip, ipython will be "linked" to the python they were installed by. (but see tip 1)

Q3: it's easier to install one of the py{26,27,xx}-numpy ports, or pip install numpy under your python_select'ed python.

Q4: well, MacPorts is the best thing I know after APT on Debian/Ubuntu... :-)

Now, two tips if you try MacPorts:

  1. MacPorts cleanly installs ports separately from the OS X installation, in an /opt/local directory, and each python version is installed in a /opt/local/Library/Frameworks/Python.framework/Versions/{2.5,2.6,2.7,...} directory. Using python_select cleanly switch the "python" command using links. BUT... the Versions/{2.5,2.6,2.7,...}/bin directory, where python scripts are installed, is not added to the PATH. Just adding: export PATH=/opt/local/Library/Frameworks/Python.framework/Versions/Current/bin:$PATH to your ~/.profile will always give you direct access to the scripts installed for the selected python.

  2. to avoid bad surprises, I've added a echo Selected python is \"$(python_select -s)\" line to my ~/.profile, so I always know which is my currently selected python when opening a session... :-)

Regards,

Georges

Install a module using pip for specific python version

Use a version of pip installed against the Python instance you want to install new packages to.

In many distributions, there may be separate python2.6-pip and python2.7-pip packages, invoked with binary names such as pip-2.6 and pip-2.7. If pip is not packaged in your distribution for the desired target, you might look for a setuptools or easyinstall package, or use virtualenv (which will always include pip in a generated environment).

pip's website includes installation instructions, if you can't find anything within your distribution.



Related Topics



Leave a reply



Submit