Pythonista 3 3.4 (340006) beta: Import pandas throws error
ihf last edited by ccc
After recovering from the shock and delight of seeing v3.4 I tried doing an import of pandas and got:
>>> import pandas as pd Traceback (most recent call last): File "/private/var/mobile/Containers/Shared/AppGroup/228D1F3E-E592-4896-BBF5-D6EA74943D0D/Pythonista3/Documents/site-packages-3/pandas/__init__.py", line 30, in <module> from pandas._libs import hashtable as _hashtable, lib as _lib, tslib as _tslib File "/private/var/mobile/Containers/Shared/AppGroup/228D1F3E-E592-4896-BBF5-D6EA74943D0D/Pythonista3/Documents/site-packages-3/pandas/_libs/__init__.py", line 14, in <module> from pandas._libs.tslibs import ( File "/private/var/mobile/Containers/Shared/AppGroup/228D1F3E-E592-4896-BBF5-D6EA74943D0D/Pythonista3/Documents/site-packages-3/pandas/_libs/tslibs/__init__.py", line 32, in <module> from .nattype import NaT, NaTType, iNaT, is_null_datetimelike, nat_strings ImportError: cannot import name 'is_null_datetimelike' from 'pandas._libs.tslibs.nattype' (unknown location) The above exception was the direct cause of the following exception: Traceback (most recent call last): File "<string>", line 1, in <module> File "/private/var/mobile/Containers/Shared/AppGroup/228D1F3E-E592-4896-BBF5-D6EA74943D0D/Pythonista3/Documents/site-packages-3/pandas/__init__.py", line 34, in <module> raise ImportError( ImportError: C extension: 'is_null_datetimelike' from 'pandas._libs.tslibs.nattype' (unknown location) not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first.
Olaf last edited by
@ihf I cannot reproduce,
import pandasworks for me.
pandas.__file__I then get:
…/pylib/site-packages/pandas/__init__.pyseems to differ from the error messages you get
Could it be you’re not using the built-in
@Olaf other than doing a simple search for “pandas”, how would I know? I don’t find any other Pandas modules when I do that search.
Is this what you get as pandas location:
ihf last edited by ihf
I tried on another device and got this:
import pandas Traceback (most recent call last): File "<string>", line 1, in <module> File "/var/containers/Bundle/Application/2ED6F7E9-20E0-4979-9558-F1FDD9658AEB/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/pandas/__init__.py", line 23, in <module> from pandas.compat import is_numpy_dev as _is_numpy_dev ImportError: cannot import name 'is_numpy_dev' from 'pandas.compat' (/private/var/mobile/Containers/Shared/AppGroup/228D1F3E-E592-4896-BBF5-D6EA74943D0D/Pythonista3/Documents/site-packages-3/pandas/compat/__init__.py)
@ihf you apparently have tried to install pandas before, hence the site-packages-3 error.
You need to delete the Documents/site-packages-3/pandas folder. This is somewhat complicated by the fact that it is hidden in the beta.
@JonB I thought I would use stash to find and delete the folder but when I tried that I got:
Traceback (most recent call last): File "/private/var/mobile/Containers/Shared/AppGroup/228D1F3E-E592-4896-BBF5-D6EA74943D0D/Pythonista3/Documents//launch_stash.py", line 28, in <module> from stash import stash File "/private/var/mobile/Containers/Shared/AppGroup/228D1F3E-E592-4896-BBF5-D6EA74943D0D/Pythonista3/Documents/site-packages/stash/__init__.py", line 2, in <module> from . import core as stash File "/private/var/mobile/Containers/Shared/AppGroup/228D1F3E-E592-4896-BBF5-D6EA74943D0D/Pythonista3/Documents/site-packages/stash/core.py", line 23, in <module> from .system.shcommon import (_EXTERNAL_DIRS, _STASH_CONFIG_FILES, _STASH_ROOT, _SYS_STDOUT, IN_PYTHONISTA, ON_IPAD) File "/private/var/mobile/Containers/Shared/AppGroup/228D1F3E-E592-4896-BBF5-D6EA74943D0D/Pythonista3/Documents/site-packages/stash/system/shcommon.py", line 20, in <module> _properties = plistlib.readPlist(os.path.join(os.path.dirname(sys.executable), 'Info.plist')) AttributeError: module 'plistlib' has no attribute 'readPlist'
@ihf yes... You have to manually make some changes to stash to get it to run. There are details in a PR on the GitHub page. Or if you have working copy, maybe you can update that way.
You could look at modules->site-packages>stash>bin>rm to look at the code being use to run rm -rf, then manually do that at the console. Actually it would be sufficient to rename the pandas folder to something else.
import shutil shutil.mv(‘/private/var/mobile/Containers/Shared/AppGroup/228D1F3E-E592-4896-BBF5-D6EA74943D0D/Pythonista3/Documents/site-packages-3/pandas’, /private/var/mobile/Containers/Shared/AppGroup/228D1F3E-E592-4896-BBF5-D6EA74943D0D/Pythonista3/Documents/site-packages-3/pandasfailed’) That should rename the pandas folder, then force quit and try again.
@JonB There was no pandas folder in site-packages-3 but there was dataclasses.py which was probably left over from an attempt to install pandas many moons ago and it was being called by the current working pandas. It works now. Thanks for your help! Now on to getting Stash to work and converting all my old 2.7 code to 3.11. What is the easiest way to do that?
@jonb Is there an easy way to patch Stash with the modified files?
Olaf last edited by
@ihf I’m not sure if @bennr has committed the PR, which would allow you to delete stash then install it fresh.
Maybe I will write a patch script next week.
In short, you can do it manually, using this as your guide
First, you hav to change lines 20-21 in stash/system/shcommon.py, so that it uses plistlib.load instead of readPlist. See the patch in the PR.
Next, in system/shui/pythonista _ui.py, you search and replace SUITextBox with SUITextbox_PY3. The PR used UITextBox, but the underscore PY3 should work better.
Also, find isAlive and replace with is_alive in that same file.
Finally, do the same isAlive replacement in shthreads.py.
For me, I also had to make the following change in launch_stash.py, instead of _stash.launch():
import ui @ui.in_background def launch_stash(): _stash.launch() launch_stash()
@jonb Thanks! I managed to copy and modify the patched files and now stash will launch. I tried invoking scp in stash and got:
[~/Documents]$ scp nw-chg.py firstname.lastname@example.org:/Users/john stash: <class 'SyntaxError'>: invalid hexadecimal literal (number.py, line 398)
Then I tried:
[~/Documents]$ pip install scp Querying PyPI ... Downloading package ... Opening: https://files.pythonhosted.org/packages/7c/85/595a938d24bf4c88fe3ca4424ec9d934175fee800278769c7d4257dcf11a/scp-0.14.4-py2.py3-none-any.whl Invalid url: https://files.pythonhosted.org/packages/7c/85/595a938d24bf4c88fe3ca4424ec9d934175fee800278769c7d4257dcf11a/scp-0.14.4-py2.py3-none-any.whl Error: failed to download package from https://files.pythonhosted.org/packages/7c/85/595a938d24bf4c88fe3ca4424ec9d934175fee800278769c7d4257dcf11a/scp-0.14.4-py2.py3-none-any.whl [~/Documents]$
It’s been awhile since I’ve used stash so I don’t know if this is a result of the new version.
@ihf there is another GitHub PR about fixing wget and others. I believe another fork has those fixes, it should be possible now to use selfupdate.
@JonB I will say, it's going to take a while to find and fix all of the problems with stash and 3.4
ihf last edited by ihf
@jonb selfupdate says I am at the up-to-date version already; however, on another iPad I tried:
import requests as r; exec(r.get('https://bit.ly/get-stash').content)
The version it then installs does not appear to be patched to run on 3.4.
@ihf there is a way to tell selfupdate which fork to install from.
You could try
@JonB Did you have any luck getting a script to work? I've tried to manually edit and can't seem to get stash working properly on 3.4..