Python linking using – LDFLAGS doesn't work - python

I'm having the trouble: "Could not link test program to Python."
I have versions 2.7+ installed in /Library/Frameworks/.
I've tried this solution, but because it was posted more than 6 years ago it doesn't consider SIP (System Integrity Protection), which makes it impossible for many users to change System/Library files. Additionally, in later versions of Python the PYTHONFRAMEWORKDIR to PYTHONFRAMEWORKINSTALLDIR in Python's make file has been fixed (but the problem persists).
I've tried:
./configure PYTHON_LDFLAGS="-l2.7.13_1"
./configure LDFLAGS="-L/usr/local/Cellar/python/2.7.13_1/lib"
…But no combination of LDFLAGS seem to work.
Here's the error:
Could not link test program to Python. Maybe the main Python library has been
installed in some non-standard library path. If so, pass it to configure,
via the LDFLAGS environment variable.
Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib"
============================================================================
ERROR!
You probably have to install the development version of the Python package
for your distribution. The exact name of this package varies among them.
============================================================================
And here's the log description:
PKG_CONFIG=''
PYTHON='/Library/Frameworks/Python.framework/Versions/2.7/bin/python'
PYTHON_CPPFLAGS='-I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7'
PYTHON_EXEC_PREFIX='${exec_prefix}'
PYTHON_EXTRA_LDFLAGS='-u _PyMac_Error Python.framework/Versions/2.7/Python'
PYTHON_EXTRA_LIBS='-ldl -framework CoreFoundation '
PYTHON_LDFLAGS='-L/Library/Frameworks/Python.framework/Versions/2.7/lib -lpython2.7'
PYTHON_PLATFORM='darwin'
PYTHON_PREFIX='${prefix}'
PYTHON_SITE_PKG='/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages'
PYTHON_VERSION='2.7'
How can I just rip Python out of my system? Is that necessary? Or is there a fix to this error?

Had the same bit of error output on my machine and for me it helped to install python-dev, so
sudo apt-get install python-dev
did it for me.

Related

Installing QuTIP 2.2.0 with existing Python distribution on Windows

Has anyone managed to install QuTIP 2.2.0 with an existing Python 2.7.5 distribution (on Win7)? The instruction manual suggests that I need to install Python(x,y) first, but the instructions are pretty vague. I'm still a Python newbie.
Understanding installation instructions
The installation instructions are pretty clear, but I remember the times, I got lost in those short lines assuming I know something obvious.
I will try translating it
install Python(X,Y) - do it. Follow the link, download the exe file and run it.
Do not forget to set the options, following defaults will fail, Cython option must be included.
edit the distutils.cfg file as instructed
download tar.gz archive for QuTIP from PyPi, unpack it in some directory, cd into it to be in the directory, where you see setup.py, and run $ python setup.py install
The distutils.cfg refers to mingw32, this is needed for compilation. If it is not installed with Python(X,Y), you would have to install it separately. Be careful and install proper version, even on 64 bit systems use 32 bit one (this I assume from proposed name of compiler in config).
Good luck. I am not on Windows for about 2 years, so I cannot confirm, it works, but I hope, it will move you on.
I also had a lot of problems installing it correctly.
Here is my working solution.
As the installation instructions suggest:
Install PythonXY (I am using 2.7.6.1) (including Cython package) (Edit: The newer versions of PythonXY do not include a compiler. Try installing from here instead: https://code.google.com/p/pythonxy/wiki/AdditionalPlugins)
Edit C:\Python27\Lib\distutils\distutils.cfg to include:
[build]
compiler = mingw32
[build_ext]
compiler = mingw32
Add C:/MinGW32-xy/bin to your PATH. It has to be before other paths with e.g. gcc in them. You can do this:
set PATH=C:/MinGW32-xy/bin;%PATH%
for a temporary add (in that console) or use the answer here.
For a permanent change go properties of your Computer. Go to advanced system settings --> Environment Variables. Change the System Variable to have the MinGW path as the first entry. It doesn't work if it is last or in the user path!
Run a Python interpreter:
import qutip; qutip.testing
qutip.testing.run()
If it doesn't crash on the 7th test you probably have a working copy of qutip.
I get 320 test in 2194.236s and SKIP=7, errors=5.
Details of which tests failed for my can be seen here.
I would use Anaconda 2.7 with the added mingw and libpython libraries and then edit the distutils.cfg as stated. The skipped tests mentioned are fortran tests that you cannot run on windows, while the errors are time dependent tests that generate cython code at run time. If you follow the above suggestions then those tests will pass.
I've tried to install qutip for several hours, unsuccessfully. Fortunately, kind people from University of California have a solution:
wheels for lots of packages for python computing
This resource is not official, 'as is', but works better!
Type 'pip install package.whl' to download and build.

cannot call python3 on solaris 11

I am working on compiling Python package on Solaris 11.
I compiled Python 3.3.2 from source but when I call for Python3 in the terminal it says that the package is not found.
I used wget and ./configure, make, and altinstall for compiling.
I ls the /opt directory where I installed it and the Python 3.3.2 is there.
I have search the answer but could not find anything relevant.
thank you for your help.
I was not correct with my output,
here is what I type and the output I get
root#T2000-1:opt#Python3
bash: Python3: command not found
when I type
cd Python-3.3.2
I can get into Python directory and ls all the files there are.
While compiling, it didn't give me any errors.
I installed the same packages in Debian 7.1 - no problem.
I need to compile from source scipy, numpy, and matplotlib which would work with Python3.
In some of the comments on this very website I read that before you compile python X.X you need to install build-dep Python3 using apt-get, but in Solaris apt-get does not work.
I am kind of stuck and don't know what I need to do.

Unable to Install Python Packages on a Mac (gcc-4.0 error) [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to use/install gcc on Mac OS X 10.8 / Xcode 4.4
I cannot install any Python packages using easy_insall or pip, because of the following error. I've looked everywhere, and seen several variations of this error, but have not found a solution that is easy to understand/follow. Any help is much appreciated!
I'm running on Mac OS 10.8.1
Python version 2.7.3
Xcode version 4.5.2 (with Command Line Tools installed)
...if you need any more information in order to figure out the problem, please ask!
$ easy_install pil
Searching for pil
Reading http://pypi.python.org/simple/pil/
Reading http://www.pythonware.com/products/pil
Reading http://effbot.org/zone/pil-changes-115.htm
Reading http://effbot.org/downloads/#Imaging
Best match: PIL 1.1.7
Downloading http://effbot.org/media/downloads/PIL-1.1.7.tar.gz
Processing PIL-1.1.7.tar.gz
Writing /var/folders/9q/bvqtzkbx1hg1934b36zgk0y40000gn/T/easy_install-wfZs_Y/PIL-1.1.7/setup.cfg
Running PIL-1.1.7/setup.py -q bdist_egg --dist-dir /var/folders/9q/bvqtzkbx1hg1934b36zgk0y40000gn/T/easy_install-wfZs_Y/PIL-1.1.7/egg-dist-tmp-DXWOmC
WARNING: '' not a valid package name; please use only.-separated package names in setup.py
--- using frameworks at /System/Library/Frameworks
unable to execute gcc-4.0: No such file or directory
error: Setup script exited with error: command 'gcc-4.0' failed with exit status 1
Not sure if this helps, but when I run sudo port select --list gcc, I get the following:
Available versions for gcc:
llvm-gcc42
mp-gcc45
none (active)
This is just a guess, based on the fact that you must have MacPorts installed (or sudo port select --list gcc would just give you a port: command not found error), but I suspect you've installed a MacPorts Python 2.7.3, and you're trying to install PIL for that.
If you want to add packages to a MacPorts Python installation, you should always first check to see if there's a port for it, and, if so, use it:
port search pil
In this case, you'll find there is a py27-pil. Install that.
Meanwhile, when this doesn't apply, you should almost always use pip instead of easy_install (there are a few exceptions, notably readline), and you need to make sure your path is set up properly so you're running the one you think you are, or you may end up running scripts set up for MacPorts python with Apple python.
However, I also suspect you have an out-of-date MacPorts installation that you installed for an earlier version of OS X, and didn't follow the upgrade instructions when upgrading to Mountain Lion. If this is true, the only decent fix is to get a list of installed ports, sudo rm -rf /opt/local, run the latest MacPorts installer, then sudo port install all of the previously-installed ports.
On top of that, last time I used MacPorts Python (which is quite a long time ago, so it may not be current information), it didn't install things into /Library (IIRC, it set up /opt/local/Library as an extra library directory instead), which implies that you actually have at least three Python 2.7 installations: Apple's (in /System/Library and /usr), MacPorts (in /opt/local), and some other version (in /Library and probably /usr/local), and you're using the second one's easy_install when you meant to use the third.
If you don't know how to deal with this kind of multiple-copies-of-the-same-thing insanity, and you don't have a very, very good reason to invite it, the right answer is to not install these other Pythons (and uninstall any you already have). Do you actually need MacPorts python at all? Can you just use the built-in Python? If not, why not? And can you at least use the python.org Python?
If you don't want to fix any of the base problems, and you really want to install things into a MacPorts Python that expects you to have gcc-4.0 around, you might be able to install the macports gcc4.0 port, although you may have to trick things into believing that macports-gcc-4.0 is really gcc-4.0. (There might be a way to do that properly with MacPorts; if not, a symlink might work.) But this is probably a bad idea, and I wouldn't be surprised if you came back with "That seemed to work but then I got this other error 348 minutes into rebuilding stuff", and nobody would be able to help you.

Why does the pip installer expect gcc-4.2 to be the name of the gcc compiler in OS X Lion?

When installing packages in Python using pip, I came across the following error:
unable to execute gcc-4.2: No such file or directory
Clearly, pip is trying to use gcc-4.2 which is not in any of the binary directories, namely /usr/bin. After looking around this site and others, I have found that many others are suffering from the same issue. However, gcc is updated to version 4.2 in OS X Lion and this is not a version problem, rather, gcc is just called gcc, not gcc-4.2, under /usr/bin, and is symlinked to llvm-gcc. After adding gcc-4.2 in /usr/bin as a symlink to gcc, pip was able to install everything successfully. Why is it then, that pip is looking for gcc-4.2 and not gcc? Is this the fault of pip, OS X Lion, or the packages within pip that are trying to install themselves with gcc-4.2?
Finally, is my symlink hack the right thing to do in this situation, or should I have fixed this some other way?
Your simlink hack is the right solution for now. Ultimately the people who support pip for the platform need to stop using explicit versions of the compiler that way. It was a bad idea to begin with and will only be worse as compilers on the platform change.
Contrary to Milad's answer there are other solutions to determining version in the host compiler and your solution will work until the people who support pip on the platform fix their code.
You symlink hack is the right solution for you. pip is just trying to ensure that it is being installed using the right version of GCC. Since your computer is equipped with that version, it is safe for you to point it to your available gcc as the one it is looking for. But if, say, you had gcc-4.1 your installation might have gone places it shouldn't have.

How do you install pycairo on Mac OS X? [duplicate]

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

Resources