Python __path__ help

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
spikethehobbit
Space Squid
Posts: 66
Joined: Mon Aug 27, 2012 7:24 pm

Python __path__ help

#1 Post by spikethehobbit »

Some proposed changes to the python interface use the `__path__` variable, but I am unsure how this variable works on different platforms. It would be helpful if a Windows and a Mac user could each post the output of this script:

import ctypes
print ctypes.__path__

On Linux, it produces
['/usr/lib/python2.7/ctypes']
All contributions are submitted under GPL or LGPL v2 or later, or under appropriate Creative Commons licence, consistent with project guidlines.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Python __path__ help

#2 Post by Geoff the Medio »

Code: Select all

C:\Users\Geoff\Desktop\FreeOrion_VS2013_SDK\FreeOrionTemp>python
Python 2.7.9 (default, Apr 18 2015, 13:30:31) [MSC v.1800 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Geoff\Desktop\FreeOrion_VS2013_SDK\FreeOrionTemp\python27.zip\ctypes\__init__.py",
line 10, in <module>
ImportError: No module named _ctypes
>>> print ctypes.__path__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'ctypes' is not defined
>>>

spikethehobbit
Space Squid
Posts: 66
Joined: Mon Aug 27, 2012 7:24 pm

Re: Python __path__ help

#3 Post by spikethehobbit »

Ouch. That looks like a broken python install. Ah, it is in a .zip file, so it can't load the .dll. If it isn't too much trouble, could you try:

Code: Select all

import xml
print xml.__path__
That one should work even loading from a .zip file.

Mine gives

Code: Select all

['/usr/lib/python2.7/xml']
Thanks.
All contributions are submitted under GPL or LGPL v2 or later, or under appropriate Creative Commons licence, consistent with project guidlines.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Python __path__ help

#4 Post by Geoff the Medio »

spikethehobbit wrote:Ouch. That looks like a broken python install.
It's not an install... it's the python.exe in the FreeOrion SDK.

Code: Select all

>>> import xml
>>> print xml.__path__
['C:\\Users\\Geoff\\Desktop\\FreeOrion_VS2013_SDK\\FreeOrionTemp\\python27.zip\\xml']

spikethehobbit
Space Squid
Posts: 66
Joined: Mon Aug 27, 2012 7:24 pm

Re: Python __path__ help

#5 Post by spikethehobbit »

Geoff the Medio wrote:
spikethehobbit wrote:Ouch. That looks like a broken python install.
It's not an install... it's the python.exe in the FreeOrion SDK.

Code: Select all

>>> import xml
>>> print xml.__path__
['C:\\Users\\Geoff\\Desktop\\FreeOrion_VS2013_SDK\\FreeOrionTemp\\python27.zip\\xml']
I've never tried the windows version, so there is much I haven't seen before.
That path is both what I expected, and was afraid of. I can work with this.

Thank you.
All contributions are submitted under GPL or LGPL v2 or later, or under appropriate Creative Commons licence, consistent with project guidlines.

User avatar
Vezzra
Release Manager, Design
Posts: 6095
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: Python __path__ help

#6 Post by Vezzra »

Mac OSX:

Code: Select all

Python 2.7.10 (v2.7.10:15c95b7d81dc, May 23 2015, 09:33:12) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>> print ctypes.__path__
['/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes']
>>> 
However, this is what you get when launching the system installed Python. On Mac (as on Windows) FO ships with its own Python runtime environment, so the paths you'll get when FO runs its Python scripts are of course different.

spikethehobbit
Space Squid
Posts: 66
Joined: Mon Aug 27, 2012 7:24 pm

Re: Python __path__ help

#7 Post by spikethehobbit »

My main concern was the formatting. Mac and Linux use Unix format paths, while Windows uses it's own. That has implications for my planned python modularization scheme, since the proper path to the 'default/python' folder needs to be passed in through `freeorion.__path__`. Windows will need special handling (as expected) but Mac looks like it won't.

The other sticky issue is the current `--ai-path` option. I can jury-rig it into the new framework, or change it to a '--script-path' option for the whole python tree, but I'm not sure which the ai-devs would prefer, and I'm not sure where to ask.
All contributions are submitted under GPL or LGPL v2 or later, or under appropriate Creative Commons licence, consistent with project guidlines.

LGM-Doyle
Programmer
Posts: 219
Joined: Mon Feb 29, 2016 8:37 pm

Re: Python __path__ help

#8 Post by LGM-Doyle »

spikethehobbit have you looked in freeorion/utils/Directories.cpp?

It uses boost/filesystem which handles all of the differing OS path formatting issues internally.

Make keeping up with the vagaries of OS's filesystems someone else's maintenance problem.

spikethehobbit
Space Squid
Posts: 66
Joined: Mon Aug 27, 2012 7:24 pm

Re: Python __path__ help

#9 Post by spikethehobbit »

That is what I will wind up using, but I needed to be sure that native paths were actually being used. Thanks for the link to the proper file, though. I was just looking for it when I saw your post.
All contributions are submitted under GPL or LGPL v2 or later, or under appropriate Creative Commons licence, consistent with project guidlines.

User avatar
Cjkjvfnby
AI Contributor
Posts: 539
Joined: Tue Jun 24, 2014 9:55 pm

Re: Python __path__ help

#10 Post by Cjkjvfnby »

spikethehobbit wrote:Some proposed changes to the python interface use the `__path__` variable, but I am unsure how this variable works on different platforms. It would be helpful if a Windows and a Mac user could each post the output of this script:

import ctypes
print ctypes.__path__

On Linux, it produces
['/usr/lib/python2.7/ctypes']
FYI freeorion have interactive python console for AI code:
  • start game
  • print help in chat
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

spikethehobbit
Space Squid
Posts: 66
Joined: Mon Aug 27, 2012 7:24 pm

Re: Python __path__ help

#11 Post by spikethehobbit »

print help in chat
Thank you.
All contributions are submitted under GPL or LGPL v2 or later, or under appropriate Creative Commons licence, consistent with project guidlines.

Post Reply