By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,885 Members | 1,267 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,885 IT Pros & Developers. It's quick & easy.

py2exe importing a package not in library.zip

P: n/a
Hi,
I'm sorry if this has been asked before, but I can't seem to find an
answer to this anywhere and so far, trial and error hasn't gotten me
far either.

Using python 2.4, I've created a testing application. When the app
starts up, I do a
Expand|Select|Wrap|Line Numbers
  1. from tests import *
and it looks at
the /tests directory and loads up all the tests it finds at that
time. This works fine when interpreting the python code directly.
The problem I'm having is trying to create an executable for
distribution.

What I'd like to be able to do is to include everything in the
library.zip *except* the tests directory and then as I (or whoever)
creates more and more tests, have the ability to simply drop them into
the directory and the next time the app starts, it'll pick them up.
However, if I don't include the tests in library.zip, then when I hit
the
Expand|Select|Wrap|Line Numbers
  1. from tests import *
, it complains "AttributeError:
'module' object has no attribute 'test1'" when it gets to the first
test. And If I do include the tests in the library.zip, it works with
the tests that I have now, but then I still can't add any new ones
without the attribute error unless I regenerate the exe every time.

Basically, it seems like it comes down to importing a package outside
the library.zip. So, is there any way to do this with py2exe? Or
even another exe creating application?

Thanks,
MyPetSlug
Aug 20 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Aug 20, 4:48*pm, mypets...@gmail.com wrote:
Hi,
I'm sorry if this has been asked before, but I can't seem to find an
answer to this anywhere and so far, trial and error hasn't gotten me
far either.

Using python 2.4, I've created a testing application. *When the app
starts up, I do a
Expand|Select|Wrap|Line Numbers
  1. from tests import *
and it looks at
the /tests directory and loads up all the tests it finds at that
time. *This works fine when interpreting the python code directly.
The problem I'm having is trying to create an executable for
distribution.

What I'd like to be able to do is to include everything in the
library.zip *except* the tests directory and then as I (or whoever)
creates more and more tests, have the ability to simply drop them into
the directory and the next time the app starts, it'll pick them up.
However, if I don't include the tests in library.zip, then when I hit
the
Expand|Select|Wrap|Line Numbers
  1. from tests import *
, it complains "AttributeError:
'module' object has no attribute 'test1'" when it gets to the first
test. *And If I do include the tests in the library.zip, it works with
the tests that I have now, but then I still can't add any new ones
without the attribute error unless I regenerate the exe every time.

Basically, it seems like it comes down to importing a package outside
the library.zip. *So, is there any way to do this with py2exe? *Or
even another exe creating application?

Thanks,MyPetSlug
Hi Again,
So, someone responded with some tips about paths, so my paths are
correct in the exe and I verified this by printing them out. So, my
problem is not that, I guess. And in my original email, I simplified
my scenario because I thought it was a problem with paths. So, let me
back up a little.

My tests directory actually has several sub-directories, so it's laid
out like this: tests/testCategory1, tests/testCategory2, tests/
testCategory1/subCategory1/test1, and so on. With potentially
hundreds of tests, I needed some organization. Anyway, in my tests
directory, I have an __init__.py with " __all__=["testCategory1",
"testCategory2"]" and it's this that the exe keeps choking on. Even
though I append the path directly above the __all__ via "
sys.path.append(os.path.abspath('') + '\\tests')" and
"sys.path.append(os.path.abspath('') + '\\tests\\testCategory1')" (the
second one just to be safe), when I execute the import *, it still
tells me "AttributeError: 'module' object has no attribute
'testCategory1'"

Again, this works fine when just executing the python code without the
exe. What am I doing wrong? Or can anyone even point me to the right
place to possibly find an answer?

Thanks,
MyPetSlug
Aug 25 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.