Pythonista-Issues
Pythonista-Issues copied to clipboard
Missing ctypes.macholib breaks ctypes.util
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'
Still valid in 311014.
Still happening
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.
I’m really new to this, how do I copy it and what do I copy it as?
@CapnS
- 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
- Import the file into Pythonista: Tap on "More...", select "Run Pythonista Script" in the bottom row of icons, then tap on "Import File".
- In Pythonista, extract the zip file (open it and then tap on "Extract Archive...").
- In the extracted folder, go to "Lib".
- Move the "ctypes" folder from "Lib" into "site-packages-3".
- Restart Pythonista, and type
import ctypes.util
in the Python console to confirm that it works. - You can delete the downloaded zip file and the extracted folder, they are not needed anymore.
This is still not fixed in the latest version
Still happening in v3.3 (330025).
@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.
https://pypi.org/project/macholib is not documented in the Python docs.
It can be imported in Pyto.
@MadisonMay is the expert.
@cclauss ctypes.util
is documented though (https://docs.python.org/3.6/library/ctypes.html#finding-shared-libraries), and it internally requires ctypes.macholib
.
macholib
is not mentioned. Given that it is pure Python, why not just pip install it from PyPI?
@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?
@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
.
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.
@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 .
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 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.
@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 :)
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...
@CapnS
- 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
- Import the file into Pythonista: Tap on "More...", select "Run Pythonista Script" in the bottom row of icons, then tap on "Import File".
- In Pythonista, extract the zip file (open it and then tap on "Extract Archive...").
- In the extracted folder, go to "Lib".
- Move the "ctypes" folder from "Lib" into "site-packages-3".
- Restart Pythonista, and type
import ctypes.util
in the Python console to confirm that it works.- 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 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.
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.