Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Help on keeping a Python package compatible with Pythonista
-
Some time ago, I started a small project of a command line application to count and search files by extension. It’s both the creation of a tool I wanted to have for my personal usage and a way to learn and exercise new programming skills. It’s also the first project in a long time that I have been able to collaborate with someone else, wich is great.
Now, the thing is: I wanted this to run both on my Mac and on my iOS devices (and elsewhere), in Pythonista. I have been trying to keep it pure-Python in order to ensure future compatibility, but I am having a hard time trying to understand how can I install it and make it run on StaSh, or through the wrench menu. In Mac or PC, we can easily pip install it from the cloned git repository, but on Pythonista it does not work. Can someone please help?
https://github.com/victordomingos/Count-files
Thanks in advance!
-
have you tried
pip install owner/repo
? If your repo is setup for pip, that should, in theory, work in stash. i.epip install victordomingos/Count-files
Alternatively,
git clone https://github.com/victordomingos/Count-files.git Count-Files
should also work, and will place the git folder into Documents/Count-files -
Nice! I didn’t know pip would work directly with github repositories. It seems to install and remove as expected, but I am not able to run it after installation. Probably I won’t be able to run it from StaSh, because it’s Python 3... but I also didn’t find a way to run it from any other place. I tried to run the
countfiles.py
fromstash_extensions/bin
, but I get an error:Traceback (most recent call last): File "/private/var/mobile/Containers/Shared/AppGroup/F3C0E711-6D38-4FDF-81F2-DC3B97E4E9F1/Pythonista3/Documents/stash_extensions/bin/countfiles.py", line 2, in <module> from countfiles.__main__ import main_flow File "/private/var/mobile/Containers/Shared/AppGroup/F3C0E711-6D38-4FDF-81F2-DC3B97E4E9F1/Pythonista3/Documents/stash_extensions/bin/countfiles.py", line 2, in <module> from countfiles.__main__ import main_flow ModuleNotFoundError: No module named 'countfiles.__main__'; 'countfiles' is not a package
-
I think you need to name your script something different from your package... if you have countfiles.py on the path, i dont think you can import from the countfiles package... maybe have your stash bin be named something else, then use alias to name it countfiles, if you want.
-
I did a quick test by renaming
countfiles.py
(which was generated automatically during install) to something else and, besides an unrelated and easy to solve import issue, it seems to work now. I just need to change the entrypoint onsetup.py
, then.Thanks!
-
Unfortunately, we have run into problems again. The method of
pip install
ing directly from GitHub was working OK, but some of the recent changes insetup.py
seem to have broken compatibility with Pythonista. Now I get this error:[Count-files_4]$ cd ~/Documents/ [~/Documents]$ pip install victordomingos/Count-files Working on GitHub repository ... Opening: https://github.com/victordomingos/Count-files/archive/master.zip Save as: /private/var/mobile/Containers/Data/Application/42E7AC0F-227A-43B8-BA4C-BEE6B30E9330/tmp//master.zip (156922 bytes) 156922 [100.00%] Extracting archive file ... Running setup file ... SyntaxError('invalid syntax', ('/private/var/mobile/Containers/Data/Application/42E7AC0F-227A-43B8-BA4C-BEE6B30E9330/tmp/518fc4bef99942178e4acfbf283d866b/Count-files-master/setup.py', 15, 103, ' sys.stderr.write(f"Unsupported Python version: {sys.version_info.major}.{sys.version_info.minor}. "\n')) Failed to run setup.py Fall back to directory guessing ... Error: Cannot locate packages. Manual installation required.
Maybe it has something to do with the lack of support for Python 3 in StaSh. We will try to remove that f-string and see if it solves the problem.
Meanwhile, is there any other way to manually install a package like this, which does automatically the creation of an endpoint (which usually goes into
stash_extensions/bin
)? -
pip download generally works, followed by manual tar commands to extract, and then mv to move to where you want it
-
In this case,
setup.py
should create an endpoint script in StaSh’s path. That endpoint script was the runnable script. Is there any other way to make it create that file? -
We removed the f-string from
setup.py
, but now the default check for Python version again gets stuck because of StaSh not supporting Python 3.6. 😕[~/Documents]$ pip install victordomingos/Count-files Working on GitHub repository ... Opening: https://github.com/victordomingos/Count-files/archive/master.zip Save as: /private/var/mobile/Containers/Data/Application/42E7AC0F-227A-43B8-BA4C-BEE6B30E9330/tmp//master.zip 156933 Extracting archive file ... Running setup file ... Unsupported Python version: 2.7. Python 3.6 or later is required.
-
There is a
py3
branch on https://github.com/ywangd/stash -
Last time I tried to install StaSh for Python 3 it didn’t go very well. I seemed to be in an early development stage. And apparently it still doesn’t work, at least to me. I just downloaded and installed that version:
Traceback (most recent call last): File "/private/var/mobile/Containers/Shared/AppGroup/F3C0E711-6D38-4FDF-81F2-DC3B97E4E9F1/Pythonista3/Documents/launch_stash.py", line 31, in <module> from stash import stash File "/private/var/mobile/Containers/Shared/AppGroup/F3C0E711-6D38-4FDF-81F2-DC3B97E4E9F1/Pythonista3/Documents/site-packages/stash/stash.py", line 25, in <module> from .system.shcommon import IN_PYTHONISTA, ON_IPAD File "/private/var/mobile/Containers/Shared/AppGroup/F3C0E711-6D38-4FDF-81F2-DC3B97E4E9F1/Pythonista3/Documents/site-packages/stash/system/shcommon.py", line 50, in <module> import _outputcapture ModuleNotFoundError: No module named '_outputcapture'
-
did you forcequit pythonista after installng?
-
Hi,
StaSh supports py3 since version '0.7.0'. Try running 'selfupdate -f' to upgrade to the latest stable version (important: Version '0.7.0' requires a force update, please specify the '-f' parameter when running 'selfupdate').
There are also some unmerged changes with more bugfixes ('selfupdate -f bennr01:command_testing').
Please force-quit pythonista after updating StaSh.
If you have done this and are still experiencing problems, please paste the output of 'version' in StaSh.
Please also note that the newest version of StaSh supports botz py2 and py3 and thus uses the python version it is started with (With other words: you have to start StaSh using the py3 interpreter).@ccc said:
There is a
py3
branch on https://github.com/ywangd/stashThe 'py3' branch is outdated and unsupported. The py3 changes are already in 'master' (i think).
-
This worked. Thanks!