Python __path__ help
Moderator: Committer
-
- Space Squid
- Posts: 66
- Joined: Mon Aug 27, 2012 7:24 pm
Python __path__ help
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']
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.
- Geoff the Medio
- Programming, Design, Admin
- Posts: 13603
- Joined: Wed Oct 08, 2003 1:33 am
- Location: Munich
Re: Python __path__ help
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
>>>
-
- Space Squid
- Posts: 66
- Joined: Mon Aug 27, 2012 7:24 pm
Re: Python __path__ help
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:
That one should work even loading from a .zip file.
Mine gives
Thanks.
Code: Select all
import xml
print xml.__path__
Mine gives
Code: Select all
['/usr/lib/python2.7/xml']
All contributions are submitted under GPL or LGPL v2 or later, or under appropriate Creative Commons licence, consistent with project guidlines.
- Geoff the Medio
- Programming, Design, Admin
- Posts: 13603
- Joined: Wed Oct 08, 2003 1:33 am
- Location: Munich
Re: Python __path__ help
It's not an install... it's the python.exe in the FreeOrion SDK.spikethehobbit wrote:Ouch. That looks like a broken python install.
Code: Select all
>>> import xml
>>> print xml.__path__
['C:\\Users\\Geoff\\Desktop\\FreeOrion_VS2013_SDK\\FreeOrionTemp\\python27.zip\\xml']
-
- Space Squid
- Posts: 66
- Joined: Mon Aug 27, 2012 7:24 pm
Re: Python __path__ help
I've never tried the windows version, so there is much I haven't seen before.Geoff the Medio wrote:It's not an install... it's the python.exe in the FreeOrion SDK.spikethehobbit wrote:Ouch. That looks like a broken python install.Code: Select all
>>> import xml >>> print xml.__path__ ['C:\\Users\\Geoff\\Desktop\\FreeOrion_VS2013_SDK\\FreeOrionTemp\\python27.zip\\xml']
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.
Re: Python __path__ help
Mac OSX:
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.
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']
>>>
-
- Space Squid
- Posts: 66
- Joined: Mon Aug 27, 2012 7:24 pm
Re: Python __path__ help
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.
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.
Re: Python __path__ help
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.
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.
-
- Space Squid
- Posts: 66
- Joined: Mon Aug 27, 2012 7:24 pm
Re: Python __path__ help
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.
Re: Python __path__ help
FYI freeorion have interactive python console for AI code: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']
- 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
-
- Space Squid
- Posts: 66
- Joined: Mon Aug 27, 2012 7:24 pm
Re: Python __path__ help
Thank you.print help in chat
All contributions are submitted under GPL or LGPL v2 or later, or under appropriate Creative Commons licence, consistent with project guidlines.