Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-use already existing functionality to determine the library path according to the shared library. #117

Merged
merged 1 commit into from
Aug 31, 2019

Conversation

arizvisa
Copy link
Contributor

Hi there. I'm not sure if this PR will interest you guys, especially because it's windows-specific. On my system, I have multiple versions of Python (due to embedding) and with my recent transition to Tauthon this includes yet another. This PR allows the interpreter to locate its PYTHONHOME by getting the path of its shared object (DLL) when it's unable to depend on the registry, or environment variables. Similar to the original implementation, the registry and environment variables will still get priority, just when there is nothing defined or available the DLL path will be used.

Details:
Anyways on the Windows platform, Python 2.x has implemented a couple of hacks in order to locate the base python directory which contains all of the libraries that are searched. On these platforms, you'll typically use PYTHONHOME, PYTHONPATH, etc. to inform PC/getpathp.c where to search. The method that is actually used (due to the installer), though, is an option in the registry at Software\Python\PythonCore.

However, to assist with applications embedding the library, the default Python installer literally drops the Python27 DLL into the System32 directory. This unfortunately prevents more than one instance of the language to be installed since it is installed globally (overwritten) and unversioned. This was done to guarantee that the DLL is in the library search path so that LoadLibrary will always see it. In all actuality, the library can be included in the PATH variable which the installer does anyways.

To workaround this limitation, things like virtualenv include an "activation" script that explicitly sets these environment variables and makes a copy of the executable and DLL in the same directory since the platform will give priority to the current directory. This patch allows one to simply make a copy of their Python directory to get the same effects as virtualenv.

Fix:
So to deal with this, it turns out that PC/getpathp.c actually had already attempted to accomplish this but over time was broken. I simply re-enabled it by copying the dllpath into pythonhome, and re-organized it so that it's only used as a fallback if nothing else works (giving priority to registry and environment).

@arizvisa
Copy link
Contributor Author

If there's interest in these types of fixes such as building for later versions of VS as described in #46, or updating the installer (in order to simplify access for more users). I don't mind contributing towards them since my primary Python platform is Windows and Python2/Tauthon. Lmk if that's the case.

@stefantalpalaru stefantalpalaru merged commit 412679c into naftaliharris:master Aug 31, 2019
@stefantalpalaru
Copy link
Collaborator

Thanks! I made this small modification: 03cdf76

Yes, we're interested in these Windows-specific fixes.

@arizvisa
Copy link
Contributor Author

arizvisa commented Sep 1, 2019

Cool. I'll include a few more in the future then.

@arizvisa arizvisa mentioned this pull request Sep 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants