forum.vmspython.org Forum Index forum.vmspython.org
Forum system
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Import from subdirectory not working

 
Post new topic   Reply to topic    forum.vmspython.org Forum Index -> Python for OpenVMS
View previous topic :: View next topic  
Author Message
douglasrupp



Joined: 24 Jul 2012
Posts: 15

PostPosted: Tue Jul 24, 2012 4:58 pm    Post subject: Import from subdirectory not working Reply with quote

[edited to remove typos]

The following runs without error on Linux Python 2.7.2, but fails on IVMS 8.4 w/ latest Python 2.7.3. I'm new to Python, but my understanding is that the existence of an "__init_.py" file in a subdirectory should make it searchable and it does on Linux. Printing the search path after the call to append shows a list of Unix style rooted directories and the string 'public', so it's not expecting VMS style directory syntax. What else?

I've written a few simple Python scripts to test the PTD package, which works well so I believe its installed correctly.

Please advise.

Program invocation and output:
$ python setup.py
Traceback (most recent call last):
File "setup.py", line 5, in <module>
from mypython import __version__
ImportError: No module named mypthon

---------------------

setup.py:
#!/usr/bin/env python

import sys
sys.path.append('public')
from mypython import __version__

...

__init__.py:
"""Root module of the Mypython package."""

__version__ = "1.0z"

---

Directory structure:
<current dir>:
setup.py
public/
mypthon/
__init__.py


Last edited by douglasrupp on Tue Jul 24, 2012 9:39 pm; edited 1 time in total
Back to top
View user's profile Send private message
RonPeters



Joined: 18 Sep 2008
Posts: 9

PostPosted: Tue Jul 24, 2012 8:50 pm    Post subject: Reply with quote

Make sure the file is called "__init__.py" not "__init__py"

Also you have an problem in __init__.py When you define __version___ you have 3 underscores at the end but when importing in setup.py you have a double underscore at the end .
Back to top
View user's profile Send private message
douglasrupp



Joined: 24 Jul 2012
Posts: 15

PostPosted: Tue Jul 24, 2012 9:36 pm    Post subject: Reply with quote

The issues you pointed out are all typos from my lack of attention to detail in typing my post. Next time I'll cut and paste.

I've verified the actual code is correct and runs on Linux but not VMS. I've done some further experiments and found it seems to be only the contents of __init__.py that's problematical. If I hardcode __version__ into setup.py, the other modules (not shown in my testcase) are found and processed.

--Doug
Back to top
View user's profile Send private message
jfp



Joined: 12 Jul 2004
Posts: 632

PostPosted: Wed Jul 25, 2012 6:02 pm    Post subject: Reply with quote

I was unabled to reproduce your problem:
Code:
$ dir [...]

Directory DISK$TOOLS:[pbi]

public.DIR;1        setup.py;2

Total of 2 files.

Directory DISK$TOOLS:[pbi.public]

mypython.DIR;1

Total of 1 file.

Directory DISK$TOOLS:[pbi.public.mypython]

__init__.py;2

Total of 1 file.

Grand total of 3 directories, 4 files.
$ ty [...]*.py

DISK$TOOLS:[pbi]setup.py;2

#!/usr/bin/env python

import sys
sys.path.append('public')
from mypython import __version__

print __version__

DISK$TOOLS:[pbi.public.mypython]__init__.py;2

"""Root module of the Mypython package."""

__version__ = "1.0z"
$ python setup.py
1.0z
$


You can try to use "python -v setup.py" or "python -vv python.py"
to see where Python try to find your module.

JF
Back to top
View user's profile Send private message Send e-mail Visit poster's website
douglasrupp



Joined: 24 Jul 2012
Posts: 15

PostPosted: Fri Jul 27, 2012 5:58 pm    Post subject: Reply with quote

The problem was related to vmspython having case sensitive filename behavior by default. That's fine, but not what I'm accustomed to using on VMS. It all works now as expected.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forum.vmspython.org Forum Index -> Python for OpenVMS All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group