4

I've always taught myself how to write programs, with very little formal education, so I always feel like I'm missing some things that formal education may offer. In this case, I want to install a new module for Python. It's the pyhk hotkey module. I'm helping a coworker work with hot keys. The problem I have with modules is, they completely baffle me on how to install on my computer for use.

Rarely do i get an executable, which is easy, but sometimes I think you have to copy and paste .dll's or run command prompt and import .dll's but I never really know how to do this and I just find it's strange that there is very little documentation out there to help with with this....therefore I believe i may be missing something. Can anyone help me out and explain how to install python modules?

Thanks, Mike

Mike
  • 4,099
  • 17
  • 61
  • 83
  • If you're not planing into using it in more than one program, you can simply add the module to your program path (e.g. your application source directory) – asermax Mar 01 '13 at 18:13

2 Answers2

5

Let setup tools worry about directories and python path for you. Avoid copying things by hand, doing things the proper way in python for this is actually simpler than improvising and copying things by hand.

First, what about improving this useful module by using setuptools? The author helped you with useful code, now you can also contribute back by helping him with packaging!

Create a better directory structure, put the single source file inside a module to minimize the chance of namespace conflicts and create the setup.py

All you're going to need can be found here: http://pythonhosted.org/an_example_pypi_project/setuptools.html

An here follows an example:

import os
from setuptools import setup


setup(
    name = "pyhk",
    version = "0.0.4",
    author = "Someone",
    author_email = "someone@gmail.com",
    description = ("Some desc"),
    license = "Some license",
    packages=['pyhk'],
    classifiers=[
        "Development Status :: 3 - Alpha",
        "Topic :: Utilities",
    ],
)
  • thanks for this. I'm going through the link you sent. I'll see if this works for me :) – Mike Mar 01 '13 at 21:06
4

Update

First install pywin32 and pyHook...


  1. Extract the contents of the archive
  2. Copy the file pyhk.py to your python Lib directory.

In Windows, the Lib directory will be

<PATH TO PYTHON>\Lib

Example:

c:\python\Lib

In Linux, it will normally be at

/usr/lib/python2.7/
ATOzTOA
  • 34,814
  • 22
  • 96
  • 117
  • Thanks ATOzTOA. I did the copy/paste. I opened up my editor and ran Import pyhk and it threw this error: Traceback (most recent call last): File "", line 1, in import pyhk File "C:\Python27\ArcGIS10.1\lib\pyhk.py", line 47, in import pythoncom, pyHook, ctypes, thread ImportError: No module named pythoncom – Mike Mar 01 '13 at 18:10
  • This drag and drop method does not check for dependencies. If you use setup.py it will fail if the dependencies are not installed. – Octipi Mar 01 '13 at 18:12
  • 1
    Mike: http://stackoverflow.com/questions/4145079/importerror-no-module-named-pythoncom @Eric Roper except that there's no setup.py file... – asermax Mar 01 '13 at 18:12