Showing posts with label installation. Show all posts
Showing posts with label installation. Show all posts

Friday, November 21, 2008

Pyrex - mixing C and Python code

I have had a little optimization mania recently. After realizing that scipy.weave is ill suited for deployment on the computers of my non-programming colleagues I was looking for other options and tried the Pyrex extension. I recommend reading the Pyrex home page for details of what exactly Pyrex is. A title sentence of its home page explains it nicely:
Pyrex lets you write code that mixes Python and C data types any way you want, and compiles it into a C extension for Python.
This has the (for me) significant advantage that there is no need to install scipy and gcc on any computer that you want your code to run on (as compared to the scipy.weave model). Distributing the compiled extension file is enough.
To make Pyrex work on Windows follow these instructions (here seems to be a copy). As usual you have to change something a bit to make it work with gcc. The key step of these instructions is creation (or edit) of distutils.cfg and adding these lines into it:
[build]
compiler = mingw32
Aside from this I also use a modified python setup command:
python setup.py build-ext --inplace
It suits me better to have the compiled extension in the working directory and not in Python dir as happens with the 'install' command.
I am aware of the Cython language which has developed from Pyrex but I have not tried it. I guess I don't need to fix what ain't broken ;-) Pyrex works great for me right now.

Thursday, August 21, 2008

scipy.weave doesn't work - compiler troubles

The scientific python package SciPy contains a very powerful library called weave. Weave enables one to relatively easily embed C/C++ code into Python code. Thus, if you happen to have a computationally intensive code you can gain a lot of speed by rewriting it in C/C++. There are a lot of ways of how to accomplish this but weave makes this feat relatively easy even for an amateur like me.
There is however one caveate for Windows users. I commonly install all software into the 'C:\Program files\' directory. If you do this with Python and a weave requirement, MinGW compiler, weave will not work. The trouble is the space within directory name. Weave scripts and possibly also gcc are not written to deal with spaces within paths and will not find required files like gcc.exe. You will end up with error messages like:
error: command 'gcc' failed: No such file or directory
ValueError: The 'mingw32' compiler was not found.
At first I have made a hack in the first affected script, the 'platform_info.py', but this only resulted in another error:
Could not locate executable g++
Executable g++ does not exist
Traceback (most recent call last):
File "G:\Temp\tmpfgm8bn\_ev-uq.py", line 8, in
s,o = exec_command(cmd, _with_python=0, **{})
File "C:\Program Files\Python25\lib\site-packages\numpy\distutils\exec_command.py", line 253, in exec_command
use_tee=use_tee,**env)
File "C:\Program Files\Python25\lib\site-packages\numpy\distutils\exec_command.py", line 402, in _exec_command
so_dup = os.dup(so_fileno)
OSError: [Errno 9] Bad file descriptor
So, to make things short, just install Python and MinGW into C:\. This will save you from a lot of trouble.
UPDATE 08/10/22: It turned out today that your user name also may not have a space within it. I've just spent an hour trying to get weave working on a colleague's computer where the username is actually a "user name". No, renaming the user does not do the trick. I 'solved' it by creating a new user with 'valid' username.

Monday, July 28, 2008

Windows XP Home won't allow login after installation, domain error

I've recently installed Windows XP Home to a computer which was previously equipped with Win XP Professional. There was a minor glitch during the installation when the installer refused to delete the C: partition because there were some installation files present. This was possibly caused by inserting the install CD into running computer, the installer then copied some files into C: and expected to put Windows on a D: or E: partition. After reset a new installation started and run OK. Unfortunately, I couldn't log in into the machine although I haven't set any password for the only user account set up during installation. The message was "Domain does not Exist" with "smart" advice to contact system administrator. I've found several questions posted on the web regarding the same problem but no real answer to the problem. The trouble is, I have not set up any domain and Win XP Home officially does not even support domains!
My conclusion was that the installer somehow picked up some remnants of the previous Win XP Pro system (which does support domains but on this PC was not using them) and malfunctioned.

So I've done a reinstall with following steps:
1) format not only C: but also D: partitions;
2) full format on C: to NTFS before system installation begins (i.e. not the fast formatting option); it takes about 12 minutes on a 50 GB partition;
3) different user name from the previous (XP Pro) system.

I'm not sure whether these steps are all necessary or which one did the trick but after second installation everything works as it should.