Pythonista-Issues icon indicating copy to clipboard operation
Pythonista-Issues copied to clipboard

Missing ctypes.macholib breaks ctypes.util

Open dgelessus opened this issue 7 years ago • 22 comments

This is in Python 3.6 on beta build 311008.

>>> import ctypes.util
Traceback (most recent call last):
	File <string>, line 1, in <module>:
		# Source code unavailable

	File Pythonista3.app/Frameworks/Py3Kit.framework/pylib/ctypes/util.py, line 72, in <module>:
		from ctypes.macholib.dyld import dyld_find as _dyld_find

builtins.ModuleNotFoundError: No module named 'ctypes.macholib'

dgelessus avatar Jul 11 '17 19:07 dgelessus

Still valid in 311014.

zrzka avatar Oct 24 '17 13:10 zrzka

Still happening

scj643 avatar Nov 30 '17 17:11 scj643

As a temporary fix, you can copy the ctypes package from the Lib folder in the CPython repo and put it into your site-packages-3 folder.

Would still be nice to have this fixed in Pythonista, especially since it's nothing more than a missing file.

dgelessus avatar Nov 30 '17 17:11 dgelessus

I’m really new to this, how do I copy it and what do I copy it as?

zachsamuels avatar Jun 20 '18 01:06 zachsamuels

@CapnS

  1. Download the CPython 3.6.1 source code (this might take a short while - the file is only 20 MB, but Safari can be very slow at downloading): https://github.com/python/cpython/archive/v3.6.1.zip
  2. Import the file into Pythonista: Tap on "More...", select "Run Pythonista Script" in the bottom row of icons, then tap on "Import File".
  3. In Pythonista, extract the zip file (open it and then tap on "Extract Archive...").
  4. In the extracted folder, go to "Lib".
  5. Move the "ctypes" folder from "Lib" into "site-packages-3".
  6. Restart Pythonista, and type import ctypes.util in the Python console to confirm that it works.
  7. You can delete the downloaded zip file and the extracted folder, they are not needed anymore.

dgelessus avatar Jun 20 '18 11:06 dgelessus

This is still not fixed in the latest version

Stylite avatar Nov 22 '18 03:11 Stylite

Still happening in v3.3 (330025).

linusg avatar Mar 07 '20 12:03 linusg

@zrzka please remove the 3rd-party-module label, ctypes is from the standard library! This might be one of the reasons this issue still isn’t fixed as I imagine 3rd party module issues have a much lower priority from @omz‘s point of view.

linusg avatar Mar 07 '20 12:03 linusg

https://pypi.org/project/macholib is not documented in the Python docs.

It can be imported in Pyto.

@MadisonMay is the expert.

cclauss avatar Mar 07 '20 13:03 cclauss

@cclauss ctypes.util is documented though (https://docs.python.org/3.6/library/ctypes.html#finding-shared-libraries), and it internally requires ctypes.macholib.

dgelessus avatar Mar 07 '20 13:03 dgelessus

macholib is not mentioned. Given that it is pure Python, why not just pip install it from PyPI?

cclauss avatar Mar 07 '20 14:03 cclauss

@cclauss the macholib thing you found on PyPI is not the same as ctypes.macholib, and installing it from PyPI won't help here. We're talking about a package from the Python standard library that's missing in Pythonista - this one: https://github.com/python/cpython/tree/3.6/Lib/ctypes/macholib

And it's absence causes an ImportError when trying to import ctypes.util in Pythonista. What is it that you don't understand about that?

linusg avatar Mar 07 '20 14:03 linusg

@cclauss Because ctypes.util requires ctypes.macholib, which is not the same as macholib :) Even if I installed macholib from PyPI, ctypes.util wouldn't find and use it.

The only reason why I'm mentioning ctypes.macholib is because CPython's ctypes.util implementation (on Apple platforms) uses it, so the obvious fix is to just include those files (which are part of every normal CPython distribution for Apple systems). I don't want or need to use ctypes.macholib directly, but ctypes.util does, and I need ctypes.util.

dgelessus avatar Mar 07 '20 14:03 dgelessus

pypi.org/project/macholib is not documented in the Python docs.

It can be imported in Pyto.

@madisonmay is the expert.

Hi -- thanks for summoning me from the far corners of the internet, but I've unfortunately never heard of macholib, am most definitely not an expert in it, and am not even particularly macho. Best of luck resolving your issue.

madisonmay avatar Mar 07 '20 14:03 madisonmay

@cclauss wow, that's a blast from the past. I did write a patch for that short snippet of code but it was so long ago that I didn't even remember it. Unfortunately still can't be of much help here.

On Sat, Mar 7, 2020 at 9:47 AM Christian Clauss [email protected] wrote:

Wrong Madison May? https://bugs.python.org/issue18893

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/omz/Pythonista-Issues/issues/311?email_source=notifications&email_token=AAUF3ELNLGJV72YOPJF43NDRGJNB3A5CNFSM4DSS53U2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEOD3HVA#issuecomment-596095956, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUF3EN3JDWG5KQ3FLVHZATRGJNB3ANCNFSM4DSS53UQ .

madisonmay avatar Mar 07 '20 15:03 madisonmay

The solution provided by @dgelessus in June 2018, does not quite work anymore (v. 3.3 (330025)). I needed to add a step between step 5 and 6: Delete the the folder ctypes from Python Modules/Standard Library (3.6)/. Following a restart of Pythonista it now works as intended.

(As an alternative approach, I downloaded the 3.6.1 source file on a computer and just zipped the ctypes-folder (recursively), copied it into my Pythonista iCloud folder and extracted and copied it from there).

Also I second the comment from @linusg: @zrzka, this should not be tagged 3rd-party-module but bug.

boegh avatar Mar 21 '20 10:03 boegh

@boegh That's strange - the steps still work fine for me in Pythonista 3.3. It shouldn't make a difference whether ctypes still exists in the built-in standard library, because site-packages-3 comes before the stdlib in sys.path. Besides, you shouldn't be able to delete anything from the stdlib anyway - that's part of the app resources (rather than the user data) and should be read-only.

dgelessus avatar Mar 21 '20 11:03 dgelessus

@boegh That's strange - the steps still work fine for me in Pythonista 3.3.

After having reinstalled my Pythonista instance, they indeed they did... Sorry for the confusion :)

boegh avatar Mar 22 '20 08:03 boegh

Solution in https://github.com/omz/Pythonista-Issues/issues/311#issuecomment-398715503 still works (don't forget the "Restart"), but it should be fixed in Pythonista...

weidenrinde avatar Jun 20 '20 14:06 weidenrinde

@CapnS

  1. Download the CPython 3.6.1 source code (this might take a short while - the file is only 20 MB, but Safari can be very slow at downloading): https://github.com/python/cpython/archive/v3.6.1.zip
  2. Import the file into Pythonista: Tap on "More...", select "Run Pythonista Script" in the bottom row of icons, then tap on "Import File".
  3. In Pythonista, extract the zip file (open it and then tap on "Extract Archive...").
  4. In the extracted folder, go to "Lib".
  5. Move the "ctypes" folder from "Lib" into "site-packages-3".
  6. Restart Pythonista, and type import ctypes.util in the Python console to confirm that it works.
  7. You can delete the downloaded zip file and the extracted folder, they are not needed anymore.

@dgelessus i am a newbie to Python and Pythonista. I tried to follow your fix to install macholib but got stuck on step 2. Where is the “more” link to display the Run Pythonista Script icon? Any help would be appreciated. Thanks

rphtufts avatar Apr 13 '21 14:04 rphtufts

@rphtufts Yes, the instructions are a bit outdated - step 2 works differently now in newer iOS versions (since iOS 13 I think):

  • Open the link to the zip file. Safari should show a popup window that asks if you want to download the file. There you need to tap on Download.
  • Once the download is finished, go into the Files app and into your Downloads folder. There you should find the downloaded cpython-3.6.1.zip file.
  • Long-press on the cpython-3.6.1.zip file, then tap on Share. Then you should get the normal iOS share window.
  • In the list of share options, tap on "Run Pythonista Script". (You need to look in the vertical list, not in the horizontal row of app icons.)
  • In the Pythonista share window that opens, tap on "Import File".

Once you've done that, you can continue with the old instructions. All the remaining steps are done in Pythonista itself and haven't changed.

dgelessus avatar Apr 13 '21 16:04 dgelessus

Thanks for the quick response. I will try it.

From: dgelessus @.> Sent: Tuesday, April 13, 2021 12:47 PM To: omz/Pythonista-Issues @.> Cc: Hooper, Richard @.>; Mention @.> Subject: Re: [omz/Pythonista-Issues] Missing ctypes.macholib breaks ctypes.util (#311)

@rphtuftshttps://github.com/rphtufts Yes, the instructions are a bit outdated - step 2 works differently now in newer iOS versions (since iOS 13 I think):

  • Open the link to the zip file. Safari should show a popup window that asks if you want to download the file. There you need to tap on Download.
  • Once the download is finished, go into the Files app and into your Downloads folder. There you should find the downloaded cpython-3.6.1.zip file.
  • Long-press on the cpython-3.6.1.zip file, then tap on Share. Then you should get the normal iOS share window.
  • In the list of share options, tap on "Run Pythonista Script". (You need to look in the vertical list, not in the horizontal row of app icons.)
  • In the Pythonista share window that opens, tap on "Import File".

Once you've done that, you can continue with the old instructions. All the remaining steps are done in Pythonista itself and haven't changed.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/omz/Pythonista-Issues/issues/311#issuecomment-818885055, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AGKQIL5RUA5V4MXRUDAXIELTIRYRJANCNFSM4DSS53UQ.

rphtufts avatar Apr 13 '21 17:04 rphtufts