Kappa-Dev / KappaTools

Tool suite for kappa models. Documentation and binaries can be found in the release section. Try it online at
http://kappalanguage.org/
GNU Lesser General Public License v3.0
113 stars 41 forks source link

Kappy installation issue #634

Closed bgyori closed 3 years ago

bgyori commented 3 years ago

Trying to migrate to the latest Kappy release (4.1.2), I am running into an issue with the installation. In a clean virtual environment on Mac with Python 3.9, I am doing pip install kappy and once installed, I get

>>> import kappy
>>> kappy.KappaStd()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ben/.virtualenvs/kappytest2/lib/python3.9/site-packages/kappy/kappa_std.py", line 62, in __init__
    self.switch_agent = subprocess.Popen(switch_args,
  File "/usr/local/Cellar/python@3.9/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 947, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/local/Cellar/python@3.9/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 1819, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/ben/.virtualenvs/kappytest2/lib/python3.9/site-packages/bin/KappaSwitchman'

It looks like it is looking for an executable in site-packages/bin/KappaSwitchman instead of site-packages/kappy/bin/KappaSwitchman which is what would make sense in this case. In fact, it looks like the installation itself is problematic since there is no bin folder in site-packages/kappy. I haven't yet tried this on other platforms or other Python versions so not sure if it's specific to this one or a more general issue.

hmedina commented 3 years ago

Huh, it is working for me. There must be some additional configuration that causing the mismatch.

user@machine:~$ pip uninstall kappy
Found existing installation: kappy 4.1.2
Uninstalling kappy-4.1.2:
  Would remove:
    /home/user/.local/lib/python3.9/site-packages/kappy-4.1.2.dist-info/*
    /home/user/.local/lib/python3.9/site-packages/kappy/*
Proceed (y/n)? y
  Successfully uninstalled kappy-4.1.2
user@machine:~$ pip install kappy
Defaulting to user installation because normal site-packages is not writeable
Collecting kappy
  Using cached kappy-4.1.2-cp39-cp39-manylinux2010_x86_64.whl (12.3 MB)
Requirement already satisfied: nose in ./.local/lib/python3.9/site-packages (from kappy) (1.3.7)
Requirement already satisfied: future in ./.local/lib/python3.9/site-packages (from kappy) (0.18.2)
Requirement already satisfied: requests in ./.local/lib/python3.9/site-packages (from kappy) (2.25.1)
Requirement already satisfied: idna<3,>=2.5 in ./.local/lib/python3.9/site-packages (from requests->kappy) (2.10)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in ./.local/lib/python3.9/site-packages (from requests->kappy) (1.26.2)
Requirement already satisfied: certifi>=2017.4.17 in ./.local/lib/python3.9/site-packages (from requests->kappy) (2020.12.5)
Requirement already satisfied: chardet<5,>=3.0.2 in ./.local/lib/python3.9/site-packages (from requests->kappy) (4.0.0)
Installing collected packages: kappy
Successfully installed kappy-4.1.2
user@machine:~$ python3
Python 3.9.0 (default, Dec  3 2020, 20:15:33)
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import kappy
>>> kappy.KappaStd()
<kappy.kappa_std.KappaStd object at 0x7f07d745e730>
>>>
bgyori commented 3 years ago

I checked and it works on Linux (which I think you're using above) for me as well. So the issue seems to be specific to Mac and I think it has something to do with the custom function to copy the binaries into the installation folder in setup.py, but I haven't yet figured out what it is.

bgyori commented 3 years ago

Okay, I think the issue is just that a specific wheel isn't available for Python 3.9/MacOS X on PyPI for version 4.1.2 (see https://pypi.org/project/kappy/#files): there are versions for Python 2.7, 3.6, 3.7, and 3.8. So pip install builds the package from source and fails to include the binaries. One solution would be just to package and upload a Python 3.9 release to PyPI by someone who has the permissions to do so.

bgyori commented 3 years ago

As far as I can tell just downloading https://files.pythonhosted.org/packages/d6/9b/94da0b91341c94cd5288e243e356aff3b27e697829e4b930babf3e5a6128/kappy-4.1.2-cp38-cp38-macosx_10_9_x86_64.whl, renaming the file to kappy-4.1.2-cp39-cp39-macosx_10_9_x86_64.whl and then uploading it to PyPI would be sufficient to resolve this. Could one of the maintainers help with that? Thanks!

hmedina commented 3 years ago

I'm using WSL2, so yeah, the Linux version within the virtual machine.

From PEP 427, I take it that the cp38 tag means that build was for the CPython 3.8 version. I'm hesitant to just upload the same file as 3.9 compatible, if it was built for an earlier version.

If the problem is Kappy failing to compile under Mac, shouldn't we tackle that directly? @pirbo

Is there output that can hint at what's broken? I don't have a Mac environment available, so I can't reproduce...

bgyori commented 3 years ago

Actually, the kappy package consists of two parts: compiled binaries (KaSim, KaSa, etc.) that are platfrom-dependent but not Python-dependent, and python code which is platform independent. However, if the uploaded wheel files are explicit about a given Python version, as in kappy-4.1.2-cp38-cp38-macosx_10_9_x86_64.whl for Python 3.8, pip simply doesn't find it as a potential installable when doing pip install kappy on Python 3.9. Since nothing in the wheel is otherwise dependent on the Python version, it is sufficient to create a copy of the file with cp39 in the file name to make it work with Python 3.9.

bgyori commented 3 years ago

I wasn't explicit earlier but I'm not just guessing that this would work but have actually tried it before suggesting it. See this log:

(py39) ~/tmp $ wget https://files.pythonhosted.org/packages/d6/9b/94da0b91341c94cd5288e243e356aff3b27e697829e4b930babf3e5a6128/kappy-4.1.2-cp38-cp38-macosx_10_9_x86_64.whl
...
(py39) ~/tmp $ pip install kappy-4.1.2-cp38-cp38-macosx_10_9_x86_64.whl
ERROR: kappy-4.1.2-cp38-cp38-macosx_10_9_x86_64.whl is not a supported wheel on this platform.
(py39) ~/tmp $ mv kappy-4.1.2-cp38-cp38-macosx_10_9_x86_64.whl kappy-4.1.2-cp39-cp39-macosx_10_9_x86_64.whl
(py39) ~/tmp $ pip install kappy-4.1.2-cp39-cp39-macosx_10_9_x86_64.whl
Processing ./kappy-4.1.2-cp39-cp39-macosx_10_9_x86_64.whl
...
Installing collected packages: kappy
Successfully installed kappy-4.1.2
(py39) ~/tmp $ ipython
Python 3.9.0 (default, Oct 27 2020, 14:13:35) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import kappy

In [2]: kappy.KappaStd()
Out[2]: <kappy.kappa_std.KappaStd at 0x1039b1820>
pirbo commented 3 years ago

First, Sorry I'm reacting this late!

Sadly, your trick does not work:

$ twine upload kappy-4.1.2-cp39-cp39-macosx_10_9_x86_64.whl
Enter your username: pirbo
Enter your password: 
Uploading distributions to https://upload.pypi.org/legacy/
Uploading kappy-4.1.2-cp39-cp39-macosx_10_9_x86_64.whl
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 7.64M/7.64M [00:05<00:00, 1.53MB/s]
NOTE: Try --verbose to see response content.
HTTPError: 400 Client Error: File already exists. See https://pypi.org/help/#file-name-reuse for more information. for url: https://upload.pypi.org/legacy/

and if you follow the link, you see that A file with the exact same content exists is indeed a forbidden case... I really to find a Mac to regenerate the package for 3.9 apparently. Sorry about that!

pirbo commented 3 years ago

I found a mac to steal :-) It should work now (reopen of course if I messed up)

bgyori commented 3 years ago

Thanks for looking into that!