Python and PyQt (Windows) - AttributeError: 'module' object has notattribute run

A

alesssia

I developed a python3-PyQt4 application (I’m a newbie!) on a 32-bit Linuxplatform, and I’m experiencing some problems when testing it on Windows platforms (Windows 7 and 8, both 64-bit).

I have a module called Pmc.py that contains two methods: run and main, but only the former is used in the PyQt main class. I import the module using the following statement:

import Pmc

and I call the function run with the following instruction:

self.results = Pmc.run(self.p, self.m)

obtaining this error:

AttributeError: 'module' object has not attribute run

After some tests, I discovered that renaming Pmc.py in pmc.py solves my issue. No problems are present when using Linux both 32 and 64 bit.
I’m using python 3.3 and PyQt 4.

What am I missing?

Thanks in advance,
Alessia
 
D

Dave Angel

alesssia said:
I developed a python3-PyQt4 application (I¢m a newbie!) on a 32-bit Linux platform, and I¢m experiencing some problems when testing it on Windows platforms (Windows 7 and 8, both 64-bit).

I have a module called Pmc.py that contains two methods: run and main, but only the former is used in the PyQt main class. I import the module using the following statement:

import Pmc

and I call the function run with the following instruction:

self.results = Pmc.run(self.p, self.m)

obtaining this error:

AttributeError: 'module' object has not attribute run

When quoting something from your tests, please don't paraphrase or
shorten. The actual error traceback starts with a line "Traceback (..."
and is several lines long, and the line you did quote is missing some
quotes and uses the word 'not' when i.t was originally 'no'.

In this case, it doesn't matter, but frequently it will.
After some tests, I discovered that renaming Pmc.py in pmc.py

I don't know what that means. Strictly speaking I think that means you
edited the content of pmc.py and renamed its use of the string to
something else. But I think you're trying to say you renamed Pmc.py to
pmc.py. That seems backwards to me. The reverse is more likely to fix
the problem.
solves my issue. No problems are present when using Linux both 32 and
64 bit.
I¢m using python 3.3 and PyQt 4.

What am I missing?

Linux is sensitive to case, while Windows is not. Windows does, however
preserve the case when you look a the directory, either manually with
DIR, or via some Python function.

My guess is that somehow when the zip file was extracted, the case of
this file was not preserved, and it came out pmc.py.

My suggestion is to simply use all lower-case for your filenames, and
change the references within your source to

import pmc
self.results = pmc.run

Pep-8 recommends that you use an uppercase leading letter to indicate a
class name. So a class of the "same" name as the file would be
obj = pmc.Pmc(args)

Another possibility is that you have both a pmc.py AND a Pmc.py.
That's not legal in Windows, at least if they're in the same directory.
And it's not advisable in Windows, if they're even in the same project.
 
A

alesssia

After some tests, I discovered that renaming Pmc.py in pmc.py
I don't know what that means.

I simply renamed Pmc.py to pmc.py, using a lower case instead of an upper case. Of course, I also changed lines referencing to 'Pmc' (upper case) to 'pmc' (lover case) in the source code. This allows my program to work.
My guess is that somehow when the zip file was extracted, the case of
this file was not preserved, and it came out pmc.py.

The zip was not extracted because there was no zip. I copied the code from my computer to a USB pen drive and ran the code from there.

My suggestion is to simply use all lower-case for your filenames

What surprised me is that Windows was unable of holding upper case, so I thought there was something else. Yet, it seems that this behaviour does not surprise anyone else. Then, I'll simply changes all my source file names, despite I felt it silly...

Thanks,
Alessia
 
D

Dave Angel

alesssia wrote:

The zip was not extracted because there was no zip. I copied the code from my computer to a USB pen drive and ran the code from there.

That's probably where you lost the case distinction. The FAT file
system doesn't really support lowercase, except with 'extended
attributes', and probably your Linux system didn't create those in a way
that Windows was happy with.

If I had to get files between the two, I'd either use Linux tools to do
the transfer (eg. scp or ftp), or I'd zip the files and just transfer
the zip.
What surprised me is that Windows was unable of holding upper case, so I thought there was something else. Yet, it seems that this behaviour does not surprise anyone else. Then, I'll simply changes all my source file names, despite I felt it silly...

It can hold uppercase; in fact, it's lower case that's "new". But
because it's "case - preserving" rather than "case -sensitive",
sometimes it's a mess.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,037
Latest member
MozzGuardBugs

Latest Threads

Top