Active1 year, 4 months ago
I'm starting to learn python and loving it. I work on a Mac mainly as well as Linux. I'm finding that on Linux (Ubuntu 9.04 mostly) when I install a python module using apt-get it works fine. I can import it with no trouble.
On the Mac, I'm used to using Macports to install all the Unixy stuff. However, I'm finding that most of the python modules I install with it are not being seen by python. I've spent some time playing around with PATH settings and using python_select . Nothing has really worked and at this point I'm not really understanding, instead I'm just poking around.
I get the impression that Macports isn't universally loved for managing python modules. I'd like to start fresh using a more 'accepted' (if that's the right word) approach.
May 03, 2018 This scheme installs pure Python modules and extension modules in the same location (also known as site.USERSITE). Here are the values for UNIX, including Mac OS X: pip/easyinstall/setup.py usually accept a -user flag to install the package only for the current user, generally bypassing the need for admin access. Sep 12, 2011 Manually installing python package. Ask Question. So I guess I need to install the package manually. So can someone plz explain or link to docs that explain how to do this? Python packages pip. Share improve this question. How do I install pip on macOS or OS.
So, I was wondering, what is the method that Mac python developers use to manage their modules?
Bonus questions:
Do you use Apple's python, or some other version?Do you compile everything from source or is there a package manger that works well (Fink?).
ROMANIA_engineer37.1k2020 gold badges164164 silver badges153153 bronze badges
GloryFishGloryFish6,1061515 gold badges4848 silver badges4242 bronze badges
Mac Python 3.6
13 Answers
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 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:
After that, use:
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.
sixthgearsixthgear5,38022 gold badges1717 silver badges1717 bronze badges
Your question is already three years old and there are some details not covered in other answers:
Most people I know use HomeBrew or MacPorts, I prefer MacPorts because of its clean cut of what is a default Mac OS X environment and my development setup. Just move out your /opt folder and test your packages with a normal user Python environment
MacPorts is only portable within Mac, but with easy_install or pip you will learn how to setup your environment in any platform (Win/Mac/Linux/Bsd..). Furthermore it will always be more up to date and with more packages
I personally let MacPorts handle my Python modules to keep everything updated. Like any other high level package manager (ie: apt-get) it is much better for the heavy lifting of modules with lots of binary dependencies. There is no way I would build my Qt bindings (PySide) with easy_install or pip. Qt is huge and takes a lot to compile. As soon as you want a Python package that needs a library used by non Python programs, try to avoid easy_install or pip
At some point you will find that there are some packages missing within MacPorts. I do not believe that MacPorts will ever give you the whole CheeseShop. For example, recently I needed the Elixir module, but MacPorts only offers py25-elixir and py26-elixir, no py27 version. In cases like these you have:
pip-2.7 install --user elixir
( make sure you always type pip-(version) )
That will build an extra Python library in your home dir. Yes, Python will work with more than one library location: one controlled by MacPorts and a user local one for everything missing within MacPorts.
Now notice that I favor pip over easy_install. There is a good reason you should avoid setuptools and easy_install. Here is a good explanation and I try to keep away from them. One very useful feature of pip is giving you a list of all the modules (along their versions) that you installed with MacPorts, easy_install and pip itself:
pip-2.7 freeze
If you already started using easy_install, don't worry, pip can recognize everything done already by easy_install and even upgrade the packages installed with it.
If you are a developer keep an eye on virtualenv for controlling different setups and combinations of module versions. Other answers mention it already, what is not mentioned so far is the Tox module, a tool for testing that your package installs correctly with different Python versions.
Although I usually do not have version conflicts, I like to have virtualenv to set up a clean environment and get a clear view of my packages dependencies. That way I never forget any dependencies in my setup.py
If you go for MacPorts be aware that multiple versions of the same package are not selected anymore like the old Debian style with an extra python_select package (it is still there for compatibility). Now you have the select command to choose which Python version will be used (you can even select the Apple installed ones):
Add tox on top of it and your programs should be really portable
Osteoboon33411 gold badge33 silver badges1313 bronze badges
SystematicFrankSystematicFrank10.8k44 gold badges4545 silver badges8686 bronze badges
Please see Python OS X development environment. The best way is to use MacPorts. Download and install MacPorts, then install Python via MacPorts by typing the following commands in the Terminal:
OR
Use the first set of commands to install Python 2.6 and the second set to install Python 3.0. Then use:
OR
In the above commands, replace packagename with the name of the package, for example:
These commands will automatically install the package (and its dependencies) for the given Python version.
For a full list of available packages for Python, type:
OR
Which command you use depends on which version of Python you chose to install.
Community♦
Michael Aaron SafyanMichael Aaron Safyan79.6k1313 gold badges117117 silver badges185185 bronze badges
I use MacPorts to install Python and any third-party modules tracked by MacPorts into
/opt/local
, and I install any manually installed modules (those not in the MacPorts repository) into /usr/local
, and this has never caused any problems. I think you may be confused as to the use of certain MacPorts scripts and environment variables.MacPorts
python_select
is used to select the 'current' version of Python, but it has nothing to do with modules. This allows you to, e.g., install both Python 2.5 and Python 2.6 using MacPorts, and switch between installs.The
$PATH
environment variables does not affect what Python modules are loaded. $PYTHONPATH
is what you are looking for. $PYTHONPATH
should point to directories containing Python modules you want to load. In my case, my $PYTHONPATH
variable contains /usr/local/lib/python26/site-packages
. If you use MacPorts' Python, it sets up the other proper directories for you, so you only need to add additional paths to $PYTHONPATH
. But again, $PATH
isn't used at all when Python searches for modules you have installed.How to start a manual icloud backup from my mac download.
mipadimipadi$PATH
is used to find executables, so if you install MacPorts' Python, make sure /opt/local/bin
is in your $PATH
.304k7171 gold badges471471 silver badges453453 bronze badges
There's nothing wrong with using a MacPorts Python installation. If you are installing python modules from MacPorts but then not seeing them, that likely means you are not invoking the MacPorts python you installed to. In a terminal shell, you can use absolute paths to invoke the various Pythons that may be installed. For example:
To get the right python by default requires ensuring your shell $PATH is set properly to ensure that the right executable is found first. Another solution is to define shell aliases to the various pythons.
A python.org (MacPython) installation is fine, too, as others have suggested.
Ned DeilyNed Deilyeasy_install
can help but, again, because each Python instance may have its own easy_install
command, make sure you are invoking the right easy_install
.69.9k1414 gold badges117117 silver badges144144 bronze badges
If you use Python from MacPorts, it has it's own easy_install located at: /opt/local/bin/easy_install-2.6 (for py26, that is). It's not the same one as simply calling easy_install directly, even if you used python_select to change your default python command.
TudorTudor3,22855 gold badges3333 silver badges4848 bronze badges
Have you looked into easy_install at all? It won't synchronize your macports or anything like that, but it will automatically download the latest package and all necessary dependencies, i.e.
for the nose unit testing package, or
for the
trac
bug tracker.There's a bit more information on their EasyInstall page too.
Mark RushakoffMark Rushakoff192k3131 gold badges369369 silver badges378378 bronze badges
For MacPython installations, I found an effective solution to fixing the problem with setuptools (easy_install) in this blog post:
One handy tip includes finding out which version of python is active in the terminal:
EdmunditoEdmundito76322 gold badges55 silver badges1010 bronze badges
When you install modules with MacPorts, it does not go into Apple's version of Python. Instead those modules are installed onto the MacPorts version of Python selected.
You can change which version of Python is used by default using a mac port called python_select. instructions here.
Also, there's easy_install. Which will use python to install python modules.
Jon WJon W12.3k55 gold badges3232 silver badges4444 bronze badges
You may already have
pip3
pre-installed, so just try it!Shayan AmaniShayan Amani
Install Os Python
Regarding which python version to use, Mac OS usually ships an old version of python. It's a good idea to upgrade to a newer version. You can download a .dmg from http://www.python.org/download/ . If you do that, remember to update the path. You can find the exact commands here http://farmdev.com/thoughts/66/python-3-0-on-mac-os-x-alongside-2-6-2-5-etc-/
Mario FMario F29.1k55 gold badges2929 silver badges3636 bronze badges
I use easy_install with Apple's Python, and it works like a charm.
las3rjocklas3rjock
8,13211 gold badge2727 silver badges3232 bronze badges
Directly install one of the fink packages (Django 1.6 as of 2013-Nov)
Or create yourself a virtualenv:
Or use fink django plus any other pip installed packages in a virtualenv
Kurt SchwehrKurt Schwehr1,24022 gold badges1414 silver badges3636 bronze badges
Not the answer you're looking for? Browse other questions tagged pythonmacosmodulepackagesmacports or ask your own question.
Active7 years, 11 months ago
I'd like to use https://github.com/erikvold/Github-to-Lighthouse-Issue-Migrator/blob/master/migrator.py but in the comments starting on line 8 it says:
But when I try I get the following error:
so I guess I need to install the package manually. so can someone plz explain or link to docs that explain how to do this?
ztaticPython 3 On Mac
ztatic91111 gold badge1212 silver badges2121 bronze badges
1 Answer
As @delnan said, the maintainer of Lighthouse API should really create a setup.py script. Anyway, there are two ways to achieve what you want and both require an understand of python modules.
When you import a module in python like so:
the interpretor searches for a file named lighthouse.py in the directory which the input script was run and if it cannot find it there it then searches in the directories specified by the environment variable PYTHONPATH. If you do not know what an environment variable is, I suggest reading up about them here: http://en.wikipedia.org/wiki/Environment_variable
Mac 2816 weed eater manual. If it can't find it in the directories specified by the PYTHONPATH envi var it then defaults to the
sys.path
var which is installation dependent.What the maintainer of lighthouse is doing (I think) is symlinking these files from whatever directory he downloaded them to into his installation default directory. You can quickly figure out what this directory is by running the python interpretor and looking at the
sys.path
var:You can see that
/usr/local/lib/pthon2.6/dist-packages/
is the folder all the modules are in. I believe this is where the maintainer is symlinking his files. THIS IS NOT A GOOD IDEA. You shouldn't modify this directly. The better approach is to simply download the files and place them in the same directory as your script, or you should place them in a directory and add that directory to the PYTHONPATH environment var.
Jordan MessinaJordan Messina1,06111 gold badge1313 silver badges2424 bronze badges
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.