Closed GoogleCodeExporter closed 8 years ago
"from . import ..." imports are supported starting from python 2.5.
Since we support python 2.4 this is not gonna happen.
Also, I'm not sure how exactly you intend to (sub) package psutil.
It generally sounds like a bad idea, assuming it is even possible in practice
in the first place.
Original comment by g.rodola
on 30 May 2011 at 4:35
You could use a try block to use relative imports and fall back to the way it
works for python 2.4 I guess. I didn't think about 2.4 support.
Maybe I used the wrong terminology... here is an example using directory
structure:
my_app/
foo/
__init__.py
psutil/
__init__.py
bar/
__init__.py
__init__.py
I don't see why that is a "bad" idea. It is commonly done... and it would
prevent requiring psutil to be installed on the pythonpath which is very useful.
Original comment by wgordo...@gmail.com
on 30 May 2011 at 5:08
> You could use a try block to use relative imports and fall back
> to the way it works for python 2.4 I guess.
No, you can't, the same way you can't use b"", print() or "with" statement
syntax on python versions < 2.6.
On python 2.4 and 2.5 all those statements fail with a SyntaxError exception.
> I don't see why that is a "bad" idea. It is commonly done
> and it would prevent requiring psutil to be installed on
> the pythonpath which is very useful.
It is usually done if:
- the module consists of a single py file
- the module does not contain C extensions
psutil consists of different py files and also C extension modules so you need
to install it first, regardless of whether absolute or relative imports are
used in py files.
A common way to solve this is problem is to use setuptools in your app's
setup.py, as such:
from setuptools import setup
setup(...
requires=["psutil"],
...
)
Original comment by g.rodola
on 30 May 2011 at 5:34
Okay. Good to know. I never used python 2.4 and didn't realize this project
supported it. Thanks for the explanation... I'll go the setuptools route for
this one.
Original comment by wgordo...@gmail.com
on 30 May 2011 at 5:40
Original issue reported on code.google.com by
wgordo...@gmail.com
on 30 May 2011 at 3:23