MacPorts for Python on Leopard - python

I haven't found any concrete language on the terminal commands for installing python 3.1 on Leopard using MacPorts. I already have 2.5.1 on Leopard by way of Apple. I don't want to mess with this version & I think having the newer version of Python running from my opt/local file would be better. Also SQL3 comes packed with the standard Python version on Leopard. Do I need to download SQL3 again via MacPorts in order for it to work with Python 3.1? thanks.

I haven't found any concrete language on the terminal commands for installing python 3.1 on Leopard using MacPorts.
sudo port install python31 will install Python 3.1 (into /opt/local). In general, port install <portname> will install a port. You can find ports using port search <string> or search online.
I already have 2.5.1 on Leopard by way of Apple. I don't want to mess with this version & I think having the newer version of Python running from my opt/local file would be better.
MacPorts will install everything under /opt/local, and won't touch your Apple-supplied installs.
Do I need to download SQL3 again via MacPorts in order for it to work with Python 3.1?
MacPorts will install the dependencies you need. python31 depends on sqlite3, so SQLite 3 will automatically be downloaded and installed (under /opt/local -- Apple's version won't be touched).

Here's an alternative way to install all Python flavors wherever you want:
$ cd <wherever>
$ svn http://svn.plone.org/svn/collective/buildout/python
$ cd python
$ python2.6 bootstrap.py
$ bin/buildout
It uses the system shipped Python to bootstrap the process. You'll also need Subversion installed. Make sure to edit the buildout.cfg file to add/remove versions you don't need.
It also installs PIL, readline, setuptools, virtualenv and a few more goodies, it's worth a try.

Related

Install a Python package that built for Windows and MacOS on Linux

I have currently used the python Package Larch (https://pypi.python.org/pypi/larch) on Windows. It works nicely and I am really impressed with its performance. To use the package with some large models I want to install it on a Linux server (Ubuntu 14.04.4) where I do not have the root permissions. Though knowing that the OS requirements for the package are Window or MacOS and being a beginner with Linux, I still gave it a try.
I was able to install python locally using anaconda distribution but when I used pip to install larch, I got the following message
Could not find a version that satisfied the requirement larch (from version: )
No matching distribution found for larch
So it seems to me that I can not just deliberately try to install the package on linux with out any additional work. I then tried to find solutions for my issue but I could not find any. Therefore I would like to ask if there is any workaround for my problem?
Thank you so much for your help!
[Edit]
larch does not support python2.x, and only support Windows, MACOSX.
For installing in Linux, I suggest to use wine to run windows python program with larch.
For more information about wine in Ubuntu. You can search with keyword such as How To Run Windows Software on Ubuntu with Wine
For installing in macosx. Making sure your environment have python3. You can use which python3 to check that.
$ which python3
/usr/local/bin/python3
Then, without root permission, you can install package via virtualenv. (A workstation should provide this command)
$ virtualenv -p $(which python3) env
$ . env/bin/activate
(env) $ python -V
Python 3.x.x
And finally, you can install larch via pip.
(env) $ pip3 install larch
For more information about virtualenv
"Larch can be installed from source code. If not using Anaconda, this is necessary for Linux, and can be done for other systems as well.
The latest releases of the source code will be available from Larch releases (github.com). In addition, you can use git to grab the latest development version of the source code:git clone http://github.com/xraypy/xraylarch.git" After unpacking the source distribution kit, installation from source on any platform is:
python setup.py install
source:http://cars.uchicago.edu/xraylarch/installation/index.html
edit: See this for doing this without root access
How to install python modules without root access?

How many installations of macports do I need

Over the past couple of months I've set about using Wing IDE to do the vast majority of my programming. I chose Wing primarily because it works well with wxPython, allowing me to debug much more quickly than was the case when I was using TextWrangler alongside Terminal. A quirk of Wing however is that there is no satisfactory way to force universal builds of python to run in 32-bit mode. Since I'm using wxPython 2.8.x (32-bit only) I'm using a 32-bit-only version of python as the executable (2.7.1). So long as I'm only using the python standard library and wxPython I have no problems, my trouble begins when I start trying to install third-party modules to work with this 32-bit version of Python. I want to do all my installing using macports, but it appears that the macports I have downloaded installs modules for use only with a different version of python that happens to be universal. Essentially then this is a question about macports, and I'd appreciate clarification on the following two points:
If I want three versions of python on my computer (say 2.6, 2.7 and 3.2), and want to use macports to install modules for each of them, do I need three separate versions of macports - one for each python?
If I'm right about (1) how do I set about installing separate versions? I've looked on the macports website but can find no reference to alternative versions based on which version of python you want to use it with
Help much appreciated.
A Python installed at /Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 almost certainly has nothing to do with MacPorts. You probably installed it from a python.org installer. If you want to install packages to it, you should install separate versions of easy_install using the Distribute package and/or pip for it and directly install packages for that Python instance with them. Those versions will be installed in the framework bin directory, /Library/Frameworks/Python.framework/Versions/2.7/bin. You can't manage Python packages for it from MacPorts; that works only for MacPorts Pythons, i.e. at /opt/local/bin.
So it appears you have three versions of Python 2.7 installed. The Apple-supplied system Python at /usr/bin/python2.7, a MacPorts-installed version at /opt/local/bin/python2.7, and a third (possibly from python.org) at /Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 (for which there is likely a symlink at /usr/local/bin/python2.7). There's nothing inherently wrong about having all three installed and the three can easily co-exist. Just keep in mind which one you are using, either by managing your shell path or using an absolute path to each, and that any additional packages installed need to be installed to the correct Python's site-packages directory. If you use easy_install or pip, you need to install and/or use the correct one for each.
If your goal is just to use wx-python with Python 2.7, there is an outstanding MacPorts issue about building a 32-bit-only version of wx-python because of its dependency on deprecated OS X Carbon APIs. There appears to be a new MacPorts port of a Cocoa version of wxWidgets which should work in 64-bit mode. You might want to experiment with it:
sudo port selfupdate
sudo port install py27-wxpython-devel
No you don't need separate versions of macport, what you need is separate versions of python.
Clear steps to do it :
Install macports. You should be able to use port command after that. You should have /opt/local/bin first in your path automatically, if you are using the installer for Mac.
Install python 2.6 - sudo port install python26
Install python 2.7 - sudo port install python27
You can use python26 through /opt/local/bin/python2.6
You can use python27 through /opt/local/bin/python2.7
If you want to use the python27 as default then do a sudo port python-select python27. This will ensure that /opt/local/bin/python is linked to /opt/local/bin/python2.7.
Mac comes with default python installation which is not removed. It can be accessed from /usr/bin/python.
Macports installs it's tools under path /opt/local and binaries at /opt/local/bin. So now you will have multiple versions of python and located at different location so that you can choose which one to run.
The packages installed with a particular version of python will go in it's site-packages and will not be available to other versions of python installation.
[Edit: based on comments]
I have multiple versions of standard python installation.
~ $ /usr/bin/python
python python2.5 python2.6 pythonw pythonw2.6
python-config python2.5-config python2.6-config pythonw2.5
With python2.5, I get:
>>> print platform.architecture()
('32bit', '')
>>> sys.maxint > 2**32
False
With python2.6, I get:
>>> print platform.architecture()
('64bit', '')
>>> sys.maxint > 2**32
True
See the note at - http://docs.python.org/library/platform.html

ubuntu9.10 : how to use python's lib-dynload and site-packages directories?

In ubuntu 9.10, in usr/lib/ there are the directories python2.4, python2.5, python2.6 and python3.0
Only python 2.6 is actually working.
python2.4 has only a lib-dynload directory,
python2.5 has only lib-dynload and site-packages,
python3.0 has only a dist-packages directory.
Now i'm wondering what is the idea behind this?
Because when i install python2.5 with ./configure, make, make install | altinstall
this goes into usr/local/lib and not usr/lib/ so why were these directories added tu ubuntu, how am i supposed to install python to use them?
j3ll3, in Ubuntu (or any DPKG-based Linux OS) you can ask the question "What package provides XYZ" by typing
dpkg -S /path/to/XYZ
So, for example, in Ubuntu 9.10,
dpkg -S /usr/lib/python2.5/lib-dynload/gdbm.so
returns
python-gdbm: /usr/lib/python2.5/lib-dynload/gdbm.so
You can find out more about the python-gdbm package by typing
apt-cache show python-gdbm
which says that python-gdbm provides "GNU dbm database support for Python".
Perhaps more interestingly, if you type
dpkg --listfiles python-gdbm
you get to see a listing of all the files that python-gdbm installs:
...
/usr/lib/python2.4
/usr/lib/python2.4/lib-dynload
/usr/lib/python2.4/lib-dynload/gdbm.so
/usr/lib/python2.5
/usr/lib/python2.5/lib-dynload
/usr/lib/python2.5/lib-dynload/gdbm.so
/usr/lib/python2.6
/usr/lib/python2.6/lib-dynload
/usr/lib/python2.6/lib-dynload/gdbm.so
...
So it looks like this single package installs 3 .so libraries, one for each version of python.
Python2.6 is the default version of python in Ubuntu 9.10, but it is also possible to install
python2.4, 2.5 and/or 3.0. Unless you do so, only /usr/lib/python2.6/lib-dynload/gdbm.so is used, the others are just wasting space.
Since the unneeded files in python2.4, 2.5, 3.0 are not very large, the package maintainer probably felt it was easier to ship one package rather than one for each version of python.
However, unless you know how to fix future apt-get errors, I'd recommend not manually deleting any files that were installed by packages in Ubuntu.
Sounds like they're an accident from some package(s) you have installed.
The Python version in use determines the locations searched to find installed Python packages/modules, and the "system version" of Python in Ubuntu 9.10 is 2.6, so that's what practically everything should be using. If you were to install the python2.5 package (or it gets installed as a dependency of something else), then it would use /usr/lib/python2.5/*. Try running which python and python --version; also which python2.6 and which python2.5.
From what I understand, though I'm not sure exactly why at all, Debian (from which Ubuntu is derived) uses a dist-packages naming scheme instead of site-packages.
Terminology: Python has packages and Debian (and so Ubuntu) has packages. They aren't the same kind of package, though individual Debian packages will install specific Python packages.
The short answer to your question: when you install packages from source, you should use the packages' setup.py installer to install them automatically and correctly. This installer already knows where to properly install the modules so Python can find them. To use, simply call with the exact Python interpreter you want to use the package with.
A crash course in setup.py. First, run it with the exact Python executable that you want the package to be available to. If you want to use the package with /usr/bin/python2.5, you should use /usr/bin/python2.5 to run setup.py. Second, go to the directory where that package's setup.py is installed. Third, you must install as root, so it's easiest to do the whole tihng as root. Fourth, if you want to install to multiple Python interpreters, you should run setup.py with each, but you should clean it in between. So here's what I would do:
% cd /root/directory/of/untarred/source/package
% sudo su
# /path/to/first/python setup.py build install
# rm -rf build
# /path/to/second/python setup.py build install
# rm -rf build
# exit
%
If you're installing modules by hand... you shouldn't, you should use its setup.py. (If you wrote a new module, you should write a setup.py for it.) If you must install by hand, you'll need to figure out which is the proper directory to install into for each Python, either by exploration and experimentation, or by calling into the same libraries that the installer calls to determine the proper directory. Installers using distutils call distutils.sysconfig.get_python_lib(); installers using setup_tools look in setup_tools.command.easy_install.easy_install.INSTALL_SCHEMES[os.name]["install_dir"].
Regarding dist-packages: I had a conversation with the maintainer of the Python package for Debian earlier this year. He'd implemented this dist-packages in the beta packages picked up by Ubuntu 9.04, but the code had a bug wrt PYTHONUSERBASE which I tripped over. We wound up talking a little. IIRC the reason for dist-packages had something to do with forcing the user to install packages in a different directory from apt-get. I clearly don't really understand the motivation, though, because in practice both the user and apt-get still install into the same directory.
lib-dynload isn't a Debian thing; that's a directory Python itself installs. I believe it was a directory just for shared libraries implementing modules. I'm not sure Python still uses it.
Finally, I don't know what you mean by "only python2.6 is actually working". What about these differently-named directories is "not working"?
I'm not sure what you mean by "Only python 2.6 is actually working." Suppose you run the "terminal emulator" and get a command-line prompt. Is this what you mean:
% python -V
Python 2.6
In other words, when you run Python, you get version 2.6? Well, have you tried this:
% python2.4
If Python 2.4 is correctly installed on your system, it will run. Likewise python2.5 will run Python 2.5.
If these don't run, and that is what you meant by "Only python 2.6 is actually working.", then one thing to try is to make sure that you actually have Ubuntu packages installed for Python 2.4 and Python 2.5.
% sudo apt-get install python2.4 python2.5
If you didn't have them installed before, this should add them. My thought is that you might have various libraries to support the older versions of Python, but you just don't have the actual Ubuntu packages for those older versions.

switch versions of python

Story:
One of the app that i have works on python 2.4 and other on 2.6. I tried to do a sym link of python2.4 to python and things started to break loose on ubuntu jaunty.
Now i am downloading every dependency of 2.4 and installing it using python2.4 setup.py install. The dependencies seem to be endless.
Question1: How will i tell any framework that go and use version so and so pf python like day django to use 2.6 and say mjango to use 2.4? Something like we say use database databasename kinda syntax.
Question2: Is there more elegant way to switch between version as my hack of symlinking was a virtual disaster?
Question3: Can I download a deb for say hardy and make jaunty believe its for her?
Use Virtualenv.
There is more information here: Working with virtualenv.
Using virtualenv you can create a new virtual python environment with whatever version of Python you want for each project or application. You can then activate the appropriate environment when you need it.
To expand on my answer:
You can install multiple versions of Python on your computer (I have 2.4, 2.5, 2.6 and 3.1 on my machine - I install each from source). I use a Mac, and keep my system Python as whatever OS X sets as the default.
I use easy_install to install packages. On ubuntu you can get easy_install like this:
sudo apt-get install python-setuptools
To install virtualenv then do:
easy_install virtualenv
I tend to create a new virtualenv for each project I'm working on and don't give it access to the global site-packages. This keeps all the packages tight together and allows me to have the specific versions of everything I need.
virtualenv -p python2.6 --no-site-packages ~/env/NEW_DJANGO_PROJECT
And then whenever I am doing anything related to this project I activate it:
source ~/env/NEW_DJANGO_PROJECT/bin/activate
If I run python now it uses this new python. If I use easy_install it installs things into my new virtual environment.
So, virtualenv should be able to solve all of your problems.
Pythonbrew is a magical tool. Which can also be called as Python version manager similar to that of RVM-Ruby version manager but Pythonbrew is inspired by Perlbrew.
Pythonbrew is a program to automate the building and installation of Python in the users $HOME.
Dependencies – curl
Before Installing the Pythonbrew, Install “curl” in the machine, to install curl use the below command in the terminal, give the the password for the user when prompted.
$sudo apt-get install curl
After Installing the curl, Now Install Pythonbrew, copy and paste the following commands in the terminal and type the password for the user when prompted.
Recomended method of installation - Easy Install
$ sudo easy_install pythonbrew
To complete the installation, type the following command
$pythonbrew_install
Alternate method of installation:
Use curl command to download the latest version of pythonbrew from github.
curl -kLO http://github.com/utahta/pythonbrew/raw/master/pythonbrew-install
After downloading, change “pythonbrew-install” to “executable”
chmod +x pythonbrew-install
Then, run the pythonbrew-install in the terminal
./pythonbrew-install
Now the Pythonbrew has been installed in the “Home Directory” i.e., /home/user/.pythonbrew
Next, copy and paste the following line to the end of ~/.bashrc
*NOTE: change “user” to your user name in the system
source /home/user/.pythonbrew/etc/bashrc
Thats it! Close the terminal.
Steps to Install different versions of Python:
Open a new terminal, type the following command or copy and paste it.
$pythonbrew install 2.6.6
This will install Python 2.6.6 and to install Python 2.7 or Python 3.2, change the version number in the previous command.
$pythonbrew install 2.7
or
$pythonbrew install 3.2
Update: If you get error while Installing then Install using the below command.
$pythonbrew install --force 2.7
or
$pythonbrew install --force 3.2
How to manage different versions of Python installed in system
For instance, if Python 2.6.6, Python 2.7 and Python 3.2 is installed in your system, switching between the versions can be done as follows:
By default, Python 2.6.6 will be active and in order to switch to Python 2.7 use the below command
$pythonbrew switch 2.7
The default Python is changed to Python 2.7.
Now, to switch to Python 3.2 change the version number in the previous command.
$pythonbrew switch 3.2
Use the below command to check or list the installed Python versions
$pythonbrew list
Use the below command to check or list the available Python Versions to install
$pythonbrew list -k
To uninstall any of the installed Python version (for example to uninstall Python 2.7), use the below command.
$pythonbrew uninstall 2.7
Use the below command to update the Pythonbrew
$pythonbrew update
Use the below command to disable the Pythonbrew and to activate the default version
$pythonbrew off
Enjoy the experience of installing multiple versions of Python in single Linux / ubuntu machine!
I find http://github.com/utahta/pythonbrew much easier to install and use than any other solution.
Just install it and you'll have these options:
pythonbrew install 2.7.2
pythonbrew use 2.7.2 # use 2.7.2 for a current terminal session
pythonbrew switch 2.7.2 # use 2.7.2 by default system wide
pythonbrew uninstall 2.7.2
Note: if you're using a Linux-based operating system with preinstalled Python, switching (system wide) to another version can make things go wrong, so be careful.
A more grassroot approach than Virtualenv is the side-by-side installation of two Python versions.
If there is an existing installation, and you want a second installation into the same root path (e.g. /usr/local), use this target when making install:
make altinstall
When your second installation is Python 2.6, this will leave you with a /usr/local/bin/python2.6 alongside the old /usr/local/bin/python.
A simple way to switch between these two versions is using a shell alias (alias python=/usr/local/bin/python2.6) on the shell where you invoke the interpreter. But this won't work across sub-shells and she-bang invocations.
pyenv is yet another Python manager. The README.md at that link has a good set of instructions, but they basically are:
$ cd
$ git clone git://github.com/yyuu/pyenv.git .pyenv
Then set up your $PATH.
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
Install the desired versions of Python:
$ pyenv install 2.7.8
After installing you need to run this:
$ pyenv rehash
Then switch to the version of Python you want to run, for the shell:
$ pyenv shell 2.7.8
"Question1: How will i tell any framework that go and use version so and so pf python like day django to use 2.6 and say mjango to use 2.4?"
You simply run them with the specific python version they need. Run mjango with /usr/bin/python2.4 and django with /usr/bin/python2.6. As easy as that.
"Question2: Is there more elegant way to switch between version as my hack of symlinking was a virtual disaster?"
Yes, see above. Have two separate installs of Python, and run explicitly with the different versions.
"Question3: Can I download a deb for say hardy and make jaunty believe its for her?"
That generally works. If it doesn't, it's because it has dependencies that exist in Hardy, and does not exist in Jaunty, and then you can't.
And here is a Question 4 you didn't ask, but should have. ;)
"Is there an easier way to download all those Python modules?"
Yes, there is. Install setuptools, and use easy_install. It will not help you with library dependecies for those Python modules that have C code and need to be compiled. But it will help with all others. easy_install will download and install all the Python dependencies of the module in question in one go. That makes it a lot quicker to install Python modules.
Move to the project directory :
Create an environment :
virtualenv -p python2.7 --no-site-packages ~/env/twoseven
Then activate your source :
source ~/env/twoseven/bin/activate

How to install pycairo on osx?

I am trying to install the pycairo (Python bindings for the cairo graphics library) under OSX.
I started with
easy_install pycairo
and got:
Requested 'cairo >= 1.8.8' but version of cairo is 1.0.4
error: Setup script exited with Error: cairo >= 1.8.8 not found
So I went to cairo's site and downloaded the latest package (1.8.8) of cairo, and also the latest package of something called pixman (both source packages -- couldn't find osx binaries)
unzipped both, each in own directory.
for pixman, the regular ./configure ; make ; sudo make install worked just find
for cairo, ./configure seemed to work, but make failed with:
In file included from cairo-analysis-surface.c:37:
cairoint.h:71:20: error: pixman.h: No such file or directory
What am I doing wrong?
And why do I have to struggle so much to get a software library to work on an os that "just works"? Why isn't darwin more like linux?
If you already have homebrew, these two commands should be helpful:
$ brew install cairo --use-clang
$ brew install py2cairo
For a non-Homebrew installed Python, set the PYTHONPATH to find pycairo. You can set your PYTHONPATH in your .bashrc/.profile/.whatever to the following:
PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH.
I personally didn't need to use this last part but it might help you.
It appears you are mixing various install options here. The MacPorts package system port install command should automatically pull in all the dependencies needed for a particular package so the trick is to start with the right top-level project. For python packages, MacPorts has a general convention currently: packages that start with py- are for python 2.4, those with py25- are for 2.5, and py26- for 2.6. There are currently py-cairo, py25-cairo, and py26-cairo packages available in MacPorts.
By choosing py-cairo you picked the python2.4 version and you'll probably find that MacPorts built and installed a python2.4 for you (linked at /opt/local/bin/python2.4) and, if you launch it, you'll probably find that you can import cairo there. Now that may be OK for your needs but Python 2.4 is quite old and no longer supported so, if you're just starting, it might be better to start with Python 2.6, one of the two current versions of Python. To do so, all you should need to do is:
sudo port install py26-cairo
That should bring in any missing dependencies, mainly the MacPorts python2.6, which you can run from /opt/local/bin/python2.6. You may want to change your $PATH in your shell startup script, probably .bash_profile, to put /opt/local/bin early on the search path.
Because installing Cairo and its python bindings seems to be fairly complex, it should be easier and better to stick to using a complete MacPorts solution for this. That does mean you've needlessly (and harmlessly) installed a couple of Python instances that you won't need. But if you do want to clean things up a bit, you can easily remove the MacPorts python24 with:
sudo port uninstall py-cairo python24
Completely removing the python.org installed python is more complicated. I've explained the process here. But there's no pressing need to remove either as long as you keep your paths straight.
Ok. I solved it. Putting solution here for future reference, it might help someone.
Basically, the whole ports/fink system is a bit messed up, and osx doesn't really play nice with the linux-y world.
So, the steps I needed to install pycairo on OSX were:
download the latest source versions of pixman, cairo, pycairo
extract everything. Then:
cd PIXMAN_DIR ; ./configure ; make ; sudo make install
cd CAIRO_DIR ; cp PIXMAN_DIR/pixman/*.h . ; ./configure ; make ; sudo make install
cd PYCAYRO_DIR; locate cairo.pc
hopefully, several locations are returned. choose the most likely one (one with newest cairo). For me it was "/opt/local/lib/pkgconfig/cairo.pc" and do:
export PKG_CONFIG_PATH=/opt/local/lib/pkgconfig/
after this, still in PYCAIRO_DIR, do:
python setup.py install
This should do it...
The port command installs the library for the darwinports python installation, which is different to the framework build (so steps 2 and 3 shouldn't work). Try sudo easy_install pycairo instead (although your step 4 should be equivalent to this).
Look at which python too, to check that you are in fact running the python you think you are.
On Mac OS you can have multiple Python versions installed. You can have even more if you decide to install Python via Fink or MacPorts. When you compile libraries from the source, you should make sure they point to the correct installation.
I currently have Python 2.5.1 and Python 2.6.4 installed on my machine, which I can call via python2.5 and python respectively. They live in two different folders:
/System/Library/Frameworks/Python.framework/Versions/2.5and /Library/Frameworks/Python.framework/Versions/2.6
I was running into a similar problem when compiling pycairo 1.8.8 from the tarball. The INSTALL file in this case is your friend, as it contains the correct instructions to avoid potential version conflicts. You basically need to specify the correct prefix so that the package will be installed in the correct folder.
$ python -c "import sys; print sys.prefix"
# make a note of the python prefix
$ ./configure --prefix=[python_prefix]
$ make
$ make install # may require superuser access
Running these instructions with python2.5 and python you will be able to correctly install pycairo for both versions (or for any version installed via MacPorts / Fink).
Step 1: Run this from terminal ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
Step 2: brew install cairo
Step 3: pip install pycairo

Categories