How many installations of macports do I need - python

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

Related

Uninstalling Python3.5 from Linux RHEL

I installed Python3.5 in Linux machine using configure, make, make install and made it default over existing Python2.6 . Now I want to uninstall Python 3.5 as it is not supporting zlib. How do I uninstall default Python 3.5. Linux is RHEL6.7.
you probably can remove the directory that contain the new installation.
but the main thing is to remove it from the $PATH.
To re-add Python 3.x, go here to use a software collection which installs "along side" the original 2.6 - so no collisions/corruption. http://developers.redhat.com/products/softwarecollections/get-started-rhel6-python/
This is for 3.4, but you can use these instructions for 3.5 too.
Because python is integral into the RHEL OS, please explain what you mean by:
"and made it default over existing Python2.6 ." Otherwise attempts to "uninstall" your working python install might leave you with a broken RHEL install.

Python installation in Mac OS X virtual environment that includes a framework that I can include into Xcode?

I like to use Python with numpy, scipy and some other packages. I am an absolute Python beginner and have some issues with the installation under Mac OS X.
I am following these two tutorials to install python: 1 and 2.
Here, HomeBrew is used to install Python (with pip) and virtualenv. I do not have an opinion about what is better, MacPorts, HomeBrew, Fink... I just found this tutorial inspiring confidence.
If I understand things correctly, OS X system Python, which I should never touch, is under /System/Library/Frameworks/Python.Framework. And I cannot use this one in Xcode because it does not have my wanted packages. The HomeBrew Python will be installed somewhere in /usr/local/. I found a framework there but as the system framework it does not have the additional packages. The tutorial explains that it might be better to install additional packages in virtual environments only which is done via pip. But I cannot find a framework there.
So my question is: How can I get a Python installation in a virtual environment that includes a framework that I can include into Xcode?
The Apple Python is functional and the normal site-packages folder is /Library/Python/2.7/site-packages (and not /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages). You can use it without problem.
I never had any problem to install all modules (numpy, scipy, matplotlib, pandas, shapely, and others...) that I wanted as frameworks, or with pip or easy_install, including virtualenv (simply install them in the conventional way in Python) or creating virtual environments.
when you install a framework module, It is placed in in the normal site-packages folder.
the only problem is possibly the "old" Python version (not a problem for me, using 2.6.x, 2.7.x and 3.3.x versions)
But if you want, you can install others versions of Python (in 64-bits, not 32 !):
a) the way prescribed by Apple: as a framework
the official versions of Python.org are installed in /Library/Frameworks/Python.framework with site-packages folder in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
same for the Enthought scientific version of Python (scientific distribution with many modules preinstalled, numpy, scipy, matplotlib,...),
(you can also install the Homebrew Python version as a framework, see below)
You must change the PATH of the Python executable in /usr/bin (usually, this is done automatically by the distribution by symlinks or in the /Users/me/.bash_profile file ).
The modules installed in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages do not interfere with those installed in /Library/Python/2.7/site-packages if you use the appropriate Python executable and viceversa.
b) the package management system way
MacPorts install its own version of Python in the folder /opt/;
sudo port -v install python27
Fink install its own version of Python in the folder /sw/;
fink install Python27
Homebrew installs Python in /usr/local/Cellar with symlinks in /usr/local/bin.
brew install python
or
brew install python --framework
To use them, you must add /sw/bin, /sw/lib/ or /opt/bin, /opt/lib/ to the PATH and change the PATH of the Python executable
For me, the main problem with Fink and MacPorts is that they do not take into account what is already installed and install all in their respective folders which can create real problems in the management of library paths.
The Homebrew solution is "cleaner" (in /usr/local) and is based on existing libraries if they are up to date, otherwise it installs its own versions of the libraries
c) the "autonomous" way
the perfect solution is Anaconda (another scientific distribution with many modules preinstalled, ),
Installs cleanly into a single directory (where you want as /Users/me/anaconda)
doesn’t require root privileges
doesn’t affect other Python installs on your system, or interfere with OS X Frameworks
switch to/from Anaconda just by setting $PATH or creating an alias in /Users/me/.bash_profile
alias anaconda='/Users/me/anaconda/bin/python'
alias anaconda3='/Users/me/anaconda/envs/py33/bin/python3'
you can install Python versions from 2.6.x to 3.3.x
Innovative package and environment manager for Python, named conda, but you can use pip or easy_install without problem
for me now, it is the best solution to install virtual environments (as /Users/me/anaconda/envs/py33 )
d) the "hard" way
you can compile your own version of Python in a classical form (results in /usr/) or as a framework. It takes time but it is not difficult.
So your question:
How can I get a Python installation in a virtual environment that includes a framework that I can include into Xcode?
Unless you are a Unix specialist (PATHs management) , you must use the Apple's recommended solution, a frameworks distribution (including the Apple Python)

Installing to the correct version of python on OSX

My Mac (which I am just starting to use for a development machine to stretch my wings a little from the Windows world) has 2 system-installed versions of Python (python25-apple and python26-apple) as well as 2.7 which I installed and want to use.
I have successfully run port select python python27 and when I list the versions, python27 shows as active and when I run python --version I get 2.7.3.
I'm now trying to install oauth2 using either easy_install or pip. Having run the appropriately labeled setuptools.egg file: setuptools-0.6c11-py2.7.egg (for example as noted at https://stackoverflow.com/a/5792150/8151) in my shell, I expected to have easy_install point at the correct python version, but when I run either easy_install pip -n or easy_install oauth2 -n`, both are using the 2.6 versions of the file, for for some reason the setup tools does not seem to have updated easy_install to the 2.7 version. Or at least that's what I think seems to be wrong. In addition, there's now an easy_install-2.6 in my path, so it would seem as though easy_install is pointed at the correct version, but it still always tried to install the 2.6 versions of pip or oauth2.
Did I miss a step in here somewhere, or is there another way to do what I need to do?
EDIT
I should probably note that I installed python from MacPorts.
The best way to be sure is to use the specific commands for the version you want, e.g: easy_install-2.7, pip-2.7, etc...

MacPorts for Python on Leopard

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.

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.

Categories