Archive

Archive for the ‘Programming’ Category

“Python Version 2.7 required which was not found in the registry”

January 15th, 2012 No comments


Introduction
Any module installer that is created using distutils (bdist_wininst) is very likely to produce this error. The problem is that it only detects 32bit installations of Python on 64bit Windows machines. Or more technically, 32bit versions of Python create the following registry path

HKEY_LOCAL_MACHINE\Software\Wow6432Node\Python\PythonCore

while 64bits versions create a slightly other registry path which is

HKEY_CURRENT_USER\Software\Python\PythonCore

When any 32-bit module setup is started (with a Python 64-bit on your system), it first checks whether the first path exists, while instead it should check the second (which does exist).

There are basically three ways of solving this:

  • You can install a 32-bit Python version
  • or install a 64-bit version of your module
  • or adjust the registry such that it really sees that a 64bit Python is installed

I will of course elaborate on the last two options.

Install a 64-bit version of your module

You can find many module binaries here. Choose a 64-bit version and install it. This is the most clean way of fixing the problem.

If your module is not in the list, then try the alternative below.

Fix by adjusting the registry

So the dirty way is to do the following adjustments in the registry:

  1. Run regedit.
  2. Locate the path: HKEY_CURRENT_USER\Software\Wow6432Node\
  3. Create keys in this path: Python\PythonCore\2.7\InstallPath
  4. Modify the “(Default)“, which is initially empty, to the path where Python is located, for example “C:\Python27\”.
  5. You are done. Exit and retry the setup that gave the error.

You can alternatively create a .reg file (for example fix.reg) that will do the above steps automatically. Put exactly the following in it:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\InstallPath]
@="C:\\Python27\\"

If you are lazy, then you can also download this file, unpack the registry file and just run it.

 

Categories: Fixes, Python Tags:

“Unable to find vcvarsall.bat” error when trying to install lxml

January 15th, 2012 No comments

I needed the lxml library on a machine for some python script that I coded earlier. I tried using easy_install by doing

easy_install lxml

but then I got the following error:

Searching for lxml
Reading http://pypi.python.org/simple/lxml/
Reading http://codespeak.net/lxml
Best match: lxml 2.3.3
Downloading http://lxml.de/files/lxml-2.3.3.tgz
Processing lxml-2.3.3.tgz
Running lxml-2.3.3\setup.py -q bdist_egg --dist-dir c:\users\edin\appdata\local\
temp\easy_install-9sxhlm\lxml-2.3.3\egg-dist-tmp-pjbtkm
Building lxml version 2.3.3.
Building without Cython.
ERROR: 'xslt-config' is not recognized as an internal or external command,
operable program or batch file.

** make sure the development packages of libxml2 and libxslt are installed **

Using build configuration of libxslt
warning: no files found matching 'lxml.etree.c' under directory 'src\lxml'
warning: no files found matching 'lxml.objectify.c' under directory 'src\lxml'
warning: no files found matching 'lxml.etree.h' under directory 'src\lxml'
warning: no files found matching 'lxml.etree_api.h' under directory 'src\lxml'
warning: no files found matching 'etree_defs.h' under directory 'src\lxml'
warning: no files found matching 'pubkey.asc' under directory 'doc'
warning: no files found matching 'tagpython*.png' under directory 'doc'
warning: no files found matching 'Makefile' under directory 'doc'
error: Setup script exited with error: Unable to find vcvarsall.bat

I tried installing libxml2 and libxslt, but it resulted in similar errors.

Searching for libxml2
Reading http://pypi.python.org/simple/libxml2/
Couldn’t find index page for ‘libxml2′ (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading http://pypi.python.org/simple/
No local packages or download links found for libxml2
Best match: None
Traceback (most recent call last):
File “C:\Python27\Scripts\easy_install-script.py”, line 8, in
load_entry_point(‘setuptools==0.6c11′, ‘console_scripts’, ‘easy_install’)()
File “C:\Python27\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\com
mand\easy_install.py”, line 1712, in main
File “C:\Python27\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\com
mand\easy_install.py”, line 1700, in with_ei_usage
File “C:\Python27\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\com
mand\easy_install.py”, line 1716, in
File “C:\Python27\lib\distutils\core.py”, line 152, in setup
dist.run_commands()
File “C:\Python27\lib\distutils\dist.py”, line 953, in run_commands
self.run_command(cmd)
File “C:\Python27\lib\distutils\dist.py”, line 972, in run_command
cmd_obj.run()
File “C:\Python27\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\com
mand\easy_install.py”, line 211, in run
File “C:\Python27\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\com
mand\easy_install.py”, line 434, in easy_install
File “C:\Python27\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\pac
kage_index.py”, line 475, in fetch_distribution
AttributeError: ‘NoneType’ object has no attribute ‘clone’

In one of my previous posts I pointed out how you can solve a similar problem with a missing vcvarsall.bat error, but unfortunately that approach did not solve my problem. Compiling the sources from the ground up was a too intensive job (which I might try to figure out in the future), so I chose the easy path.

The issue was solved by installing these packages from this site which lists a lot of (unoffical) Windows binaries for Python. Everything suddenly started to work as it should. :)

Categories: Fixes, Python Tags:

Store WordPress content in PHP variables

May 28th, 2011 No comments

WordPress is a great tool for blogging, but can also be integrated in a website to provide a simple content management system. In this post I’m going to address the issue of the WordPress functions where they print the output directly and show how to catch this output in a variable.

Read more…

Categories: PHP, Programming, Tutorials, WordPress Tags:

Viewstack Transitions in Flex 4

November 30th, 2010 1 comment

So I’m busy with a project building an Adobe AIR application where at this point I’m working out the layout of the application.

Transitions are usually very simple to accomplish with state transitions, but in my framework of the application I wanted to avoid using states between the different pages that were to be shown. Using transitions on a page defined in a NavigatorContent item within the ViewStack showed to be a syntactically slightly different world.

To cut the story telling, here’s a snippet of code from my project that one can use to accomplish some fading effects on the NavigatorContent within a ViewStack.

The declarations:

<fx:Declarations>
    <mx:Fade id="Show" duration="500" alphaFrom="0.0" alphaTo="1.0"/>
    <mx:Fade id="Hide" duration="500" alphaFrom="1.0" alphaTo="0.0"/>
</fx:Declarations>

and the ViewStack:

<mx:ViewStack id="views">
    <s:NavigatorContent id="intro" showEffect="{Show}" hideEffect="{Hide}">
        <components:PageIntro id="pageIntro"/>
    </s:NavigatorContent>
    <s:NavigatorContent id="projects" showEffect="{Show}" hideEffect="{Hide}">
        <components:PageProjects id="pageProjects"/>
    </s:NavigatorContent>
</mx:ViewStack>

where, of course, PageIntro and PageProjects are some defined components not included in this code.

Pretty obvious, isn’t it? :)

Categories: Flex, Programming Tags:

Calling external programs from Python

October 3rd, 2010 No comments

The story
I’m currently automating a certain process with a Python script that needs to call external programs with some specific parameters. An additional problem is with this letter s in the word parameters, for my external call requires an execution with more than one argument.

I tried the os.system call but unfortunately it didn’t work on my system because the function was apparently not present. This conclusion followed after I got the error “ImportError: No module named system”. Instead of resolving this error, I  decided to dig into google for some alternatives.  And I did succeed, when I met the lovely miss subproccess. :)

Let subprocess do all the calls
To keep it short and skip the syntax explanation, learn from the following example:

import subprocess
subprocess.call(‘expand catalog-web.cab -F:* -r’, shell=True)

As you can see, the magic only happens when you pass the string (your complete command) together with the shell=True option.

Happy Python calling. :)

Categories: Fixes, Programming, Python Tags:

Number converter

September 26th, 2010 No comments

Once in a while a man wants to convert a hexadecimal number to a decimal one, or even maybe a binary number to a decimal one. Google always helps if you ask “hex 2 bin”, but instead I decided to write an online application of my own.

The converter is implemented as very simple web page and can be found here. On the web page, on the fly conversions are possible between a decimal, hexadecimal and a binary number. So all conversions dec2hex, dec2bin, hex2dec, hex2bin, bin2dec and bin2hex are included in this basic form. See the complete junk of html and javascript code below.

<html>
<script type="text/javascript">
  function d2h(d) { return d.toString(16); };
  function h2d(h) { return parseInt(h,16); };
  function d2b(d) { return d.toString(2); };
  function b2d(b) { return parseInt(b,2); };

  function idec(d) {
    // pre: d is int
    document.cform.hex.value = d2h(parseInt(d));
    document.cform.bin.value = d2b(parseInt(d));
  };

  function ihex(h) {
  // pre: h is string
  var d = h2d(h);
  document.cform.dec.value = d;
  document.cform.bin.value = d2b(d);
  };

  function ibin(b) {
    // pre: b is string
    var d = b2d(b);
    document.cform.dec.value = d;
    document.cform.hex.value = d2h(d);
  };

</script>
<body>
<h1>Number converter</h1>
<p>Insert a decimal, hexadecimal or a binary number to convert it.</p>
<form name="cform">
Decimal: <input name="dec" onkeyup="idec(this.value)" />
Hexadecimal: <input name="hex" onkeyup="ihex(this.value)" />
Binary: <input name="bin" onkeyup="ibin(this.value)" />
</form>

</body>
</html>

Categories: HTML, JavaScript, Programming, Tools Tags:

How to use cookies with CherryPy

May 27th, 2010 No comments

Introduction

CherryPy uses the Cookie module from Python and in particular the SimpleCookie object type to handle cookies.

Sending a cookie to a browser is accomplished by using cherrypy.response.cookie and receiving a cookie from the browser by cherrypy.request.cookie.

Example

This is demonstrated in the following example code where we use a login and logout procedure :

import cherrypy

class Root(object):
  @cherrypy.expose
  def index(self):
    return """
              <form id="
login" action="/doLogin/" method="post">
              <label>
              Username:
              <input name="
username" type="text" />
              </label>
              <label>
              Password:
              <input name="
password" type="password" />
              </label>
              <input type="
submit" value="Login" />
              </form>
           "
""

  @cherrypy.expose
  def doLogin(self, username, password):
    # Set cookie to send
    cookie = cherrypy.response.cookie

    cookie[‘user’] = username
    cookie[‘user’][‘path’] = ‘/’
    cookie[‘user’][‘max-age’] = 3600

    cookie[‘pass’] = password
    cookie[‘pass’][‘path’] = ‘/’
    cookie[‘pass’][‘max-age’] = 3600

    return ‘Cookie set. You can now <a href="/doLogout/">logout</a>.’

  @cherrypy.expose
  def doLogout(self):
    # Request cookie that is already set
    reqcookie = cherrypy.request.cookie

    # Response cookie that overwrites the old one and expires
    rescookie = cherrypy.response.cookie
    for name in reqcookie.keys():
      rescookie[name] = name
      rescookie[name][‘path’] = ‘/’
      rescookie[name][‘max-age’] = 0 # or: rescookie[name]['expires'] = 0

    return ‘Logged out succesfully. You can now <a href="/">login</a> again.’

cherrypy.quickstart(Root())
 

Download source code

Creating a cookie

It is important to note that

  • cookie[name]
  • cookie[name]['path']
  • cookie[name]['max-age']

are a bare minimum of attributes that you have to set in order to get this working. If you do not set one of these three attributes, the cookie will simply not be set.

Deleting a cookie

Instead of cookie[name]['max-age']=0 you can also use cookie[name]['expires']=0, which results in the same effect of deleting the cookie.

Categories: Cherrypy, Programming, Python, Tutorials Tags:

“Unable to find vcvarsall.bat” error when trying to install rdflib

May 19th, 2010 11 comments

Some things just don’t work out like you expect them to do. During my quest with a new web application that I’m about to develop, the very first and basic thing went wrong. The setup of the rdflib python library (version 2.4.2) gave me the following error (on Windows):

“error: Setup script exited with error: Unable to find vcvarsall.bat”

After a lot of useless spent hours on trying to come up with some solution, the answer was found. There is a good solution on the project page of the library too, but I found a slightly quicker solution:

  1. First of all download MinGW. You need g++ compiler and MingW make in setup.
  2. If you installed MinGW for example to “C:\MinGW” then add “C:\MinGW\bin” to your PATH in Windows.
  3. Now start your Command Prompt and go the directory where you have your setup.py residing.
  4. Last and most important step:
    setup.py install build --compiler=mingw32

Note: This is all about rdflib version 2.4.2! Version 3.x for example has some major differences with 2.4.2 and so I’m not aware whether the problem there exists and even if it does, i’m not sure if it can be solved by the above solution.

If you have a similar problem but with some other module and you can’t fix it in this way, then you should try this.

Categories: Fixes, Python, RDF Tags:

Large file sizes after compiling with Lazarus

December 26th, 2009 No comments

In the previous post when I was building the WLM Uninstaller tool, my choice was to write the app in Pascal (Lazarus).

When you compile a project in Lazarus, you might end up with large executables. In my case, it was about 100 lines of code but compiled to a 12MB executable!

Luckily, I found out how to significantly compress the file. In Lazarus there is a file called strip.exe that, as the name suggests, strips the file from any unnecessary mess. The file on my installation is located in C:\lazarus\fpc\2.2.2\bin\i386-win32. You can simply use it as follows: “strip file.exe”. The file I compiled went from 12MB to 1.77MB!

A further decrease can be accomplished by using a packer like UPX ( “upx -9 -o outputfile.exe inputfile.exe” ). In my case this was a further jump from 1.77MB to 668kB (5,4% of the original size!).

Categories: Lazarus, Pascal, Programming Tags:

Windows Live Messenger Uninstaller v0.01

December 26th, 2009 145 comments

This is the first public version of the Windows Live Messenger Uninstaller (v0.01).

What the tool does is basically remove a broken Windows Live Messenger installation. It really uses only the windows installer (msiexec.exe) to do the job combined with the CLSID of the installation that uniquely identifies the WLM version.
The symptoms might be that when you want to reinstall the application it might say that it is already installed, while actually it is not. When trying to remove it with the usual Configuration – Add/Remove software steps, it might not even appear in the list, while the setup of the WLM says it is really installed.

I decided to build this tool since there are a lot of people strugling with this problem [1][2][3][4]. All these existing solutions presented by people on these sites use the single command with a CLSID key (eg. msiexec /x {B1403D7D-C725-4858-AACC-7E5FA2D72859}), but since the key is different for each WLM version such a solution might only be useful if you have that exact version. It can also be done manually by changing the registry keys, but I thought this would speed up the work significantly since there might be a lot of keys to search in (The location we are talking about here is: [HKEY_CLASSES_ROOT\Installer\Products\])

I heard of people formatting the entire hard drive because of not being able to resolve this, so I really hope this gets around and avoids a lot of headaches.

You can download this first version of the tool below.

Download binary | Download source code (pascal)

MD5 hash binary: 7525a442da4b4515c8166debfc4a4d01
MD5 hash source code: 28efa8f882c5354c6c4845393724e99a

 

Requirements
The tool is tested on Windows 7, but should also work on XP and Vista.

Usage
The tool is very simple to use. If it finds an installation it will give you the uninstall command that you can use to manually remove it. You can also press RUN and it will run the command automatically for you.

Note: This software comes with absolute no warranty! By using this program you agree that I am not responsible for anything caused by this software whatsoever.

Future releases
If you have any comments, suggestions or bugs, please put them here in the comments. If it is useful I might add/fix it in the next release.

Currently I’m planning to build a more general remover for the Windows Live series, since there are also other components that could get broken.

References
[1] http://ask-leo.com/how_do_i_uninstall_windows_messenger.html#comments
[2] http://ayumilove.wordpress.com/2009/03/14/how-to-install-remove-windows-live-messenger-2009/
[3] http://www.mydigitallife.info/2006/02/11/remove-and-uninstall-windows-messenger/
[4] http://www.vistax64.com/live-messenger/185883-cannot-uninstall-windows-live-messenger-beta-2009-a.html

Untrue descriptions on other sites linking to this page
The link to this topic is already published on several sites, but unfortunately the presented description of the tool is misleading. For it says that I’m claiming to have a better tool than all the other existing solutions, which is of course not true. This is only another alternative that may solve the problem.
In my description I was only referring to the existing solutions presented on the topics and comments on these that I used as references (see above [1][2][3][4]) and not on any other existing tool that probably uses other methods.

Softpedia certification

The tool can now also be downloaded from Softpedia.

Windows Live Essentials Uninstaller
If you also want to remove other Windows Live Essentials components like Windows Live Mail or Windows Live Movie Maker, then try a similar tool that I have built called Windows Live Essentials Uninstaller. This tool can remove any component installed by Windows Live Essentials.