Hey! I have trouble packaging an executable. Well,...
# general
e
Hey! I have trouble packaging an executable. Well, actually packaging is successful, but when I try to run it I get:
env: python3.8: No such file or directory
. Probably I’m using the wrong Python distribution or?
e
This probably means the machine you built the PEX file on has python3.8 but the machine you tried to run it on does not. Does that sound about right?
Assuming I've got this right, there is no easy recommendation here. If the code is compatible with all Python 3's you expect will be installed and available on the machine you deploy to, you might specify a custom shebang as
/usr/bin/env python3
here: https://www.pantsbuild.org/docs/python-target-types#pex_binary
But, that might not be appropriate for your setup either. Would need to know more details of the apps python compatibility and the interpreters installed on your various target machines.
e
I have now installed python3.8 from homebrew and relinked to this version. Now I get a little further. I can:
./pants run apps/app_a
. But when I try to
./pants package apps/a
I get this error:
Copy code
Exception: String("Can only merge Directories with no duplicates, but found 3 duplicate entries in :\n\n`__init__.py`: 1.) file digest=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 size=0:\n\n\n\n`__init__.py`: 2.) file digest=c4f92a69e828f5701ffebac2959f704f9fe06ef3d559e146663cb14d44866416 size=1674:\n\n\"\"\"Helper classes for configuration management.\"\"\"\nimport os\n\n\nclass ModelConfig:\n    \"\"\"Model configuration class.\"\"\"\n\n    def __init__(\n        self, name: str, link: str, checksum: str, language_code=\"en\"\n    ):\n        self.fullname = name\n        self.link = link\n        self.language_code = language_code\n        self.checksum = checksum\n\n    def get_fullname(self):\n        \"\"\"\n\n        Returns\n        -------\n        Model fullname, i.e. \'<name_of_model>-<version>\'\n        \"\"\"\n        return self.fullname\n\n    def get_name(self):\n        \"\"\"\n\n        Returns\n        -------\n        model name without version\n\n        \"\"\"\n        return self.fullname.split(\"-\")[0]\n\n    def get_link(self):\n        \"\"\"\n\n        Returns\n        -------\n        model link\n        \"\"\"\n        return self.link\n\n    def get_language_code(self):\n        \"\"\"\n\n        Returns\n        -------\n        model language code\n        \"\"\"\n        return self.language_code\n\n    def get_version(self):\n        \"\"\"\n\n        Returns\n        --\n... TRUNCATED contents from 1674B to 1024B (Pass -ldebug to see full contents).\n\n`__init__.py`: 3.) file digest=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 size=0:\n\n")
I’ve not been able to understand what I’m doing wrong.
e
Ok, before addressing the error here, let me back up to our prior exchange. In that exchange I assumed you were building the PEX on one machine and running it on another. That was apparently not the case. You were building and running on the same machine. Is that correct?
... but plowing ahead to the error you just presented - it just means you have a python package under multiple source roots and the package has different
__init__.py
contents in different source roots. That is not good from a Python perspective - nothing to do with Pants. I can explain why its not good if that's not clear - just speak up. To be more concrete though, an example: Say you have these source roots:
Copy code
a/root1
a/root2
a/root3
Under the first two you have the same Python package `bob`:
Copy code
a/root1/bob/
  __init__.py
  jake.py
a/root2/bob/
  __init__py
  jane.py
I'm claiming
a/root1/bob/__init__.py
and
a/root2/bob/__init__.py
have different contents and Pants is complaining (rightly) about that.
Can you confirm this is true and you have a package housed in multiple source roots but with different
__init__.py
contents?
e
You’re right. I accidentally tried to unzip a .pex file and ended up in the root of my repo. I thought I’d cleaned all up. Thanks 😄