Question

I have figured two ways to create a package / compile python scripts:

  1. Using Compileall:

    import re
     compileall.compile_dir('Lib/', rx=re.compile(r'[/\\][.]svn'), force=True)
    
  2. Using SetupTools

Though SetupTools creates a .egg file, it creates a dependency on the users to have setuptools installed if

pkg_resources

is being used.

So how do i either remove the dependency on setuptools or use compieall to create a binary like an .egg file ?

Était-ce utile?

La solution

To remove the dependency on pkg_resources, i did the following...

pkg_resources was needed to access the files within the .egg.

  import pkg_resources
  accessfiles = pkg_resources.resource_listdir(...)

Hence accessed the contents of the .egg using zipfile module...

path =  os.path.dirname(os.path.realpath(__file__))  
import zipfile
z = zipfile.ZipFile(file(path.rsplit("/", 3)[0]))
accessfiles  = filter(lambda zipList: zipList.startswith("<pattern>"), z.namelist())

This way dependency on pkg_resources was removed.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top