Skip to content

Cannot run CLI aestream after installing aestream via pip to user home #112

@holesond

Description

@holesond

OS and Python version: Ubuntu 22.04, Python 3.10.12

Reproduce the issue by running the following without root privileges:

pip install aestream

or

pip install --user aestream

Then running aestream fails with:

user@computer:~$ aestream
Traceback (most recent call last):
  File "/home/user/.local/bin/aestream", line 8, in <module>
    os.execv(
FileNotFoundError: [Errno 2] No such file or directory

Currently, the code of aestream (in /home/user/.local/bin/aestream) is:

#!/usr/bin/python3
import os
import sys
import sysconfig


if __name__ == "__main__":
    os.execv(
        os.path.join(sysconfig.get_path("platlib"), 'aestream.scripts/aestream'),
        sys.argv,
    )

sysconfig.get_path("platlib") returns '/usr/local/lib/python3.10/dist-packages'. However, pip installed the aestream package to '/home/user/.local/lib/python3.10/site-packages'.

I have fixed the issue in my AEStream installation by trying all the possible dist-packages and site-packages paths in the aestream code as follows:

#!/usr/bin/python3
import os
import sys
import site
import sysconfig


if __name__ == "__main__":
    packages_paths = [site.getusersitepackages()]
    packages_paths.append(sysconfig.get_path("platlib"))
    packages_paths.extend(site.getsitepackages())
    aestream_paths = [
        os.path.join(packages, 'aestream.scripts/aestream')
        for packages in packages_paths]
    succeeded = False
    for path in aestream_paths:
        try:
            os.execv(path, sys.argv)
            succeeded = True
            break
        except FileNotFoundError:
            pass
    if not succeeded:
        raise RuntimeError(
            f"I have not found the aestream executable among the paths: "
            f"{aestream_paths}")

These are all the possible paths on my system:

>>> import sysconfig
>>> sysconfig.get_path("platlib")
'/usr/local/lib/python3.10/dist-packages'
>>> import site; site.getsitepackages()
['/usr/local/lib/python3.10/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.10/dist-packages']
>>> site.getusersitepackages()
'/home/user/.local/lib/python3.10/site-packages'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions