1

I'm on MacOSX (12.0.1) and with Python 3.9. I want to create a simple python package for personal use. Upon creating the package using python setup.py install, almost everything works: I can import the package when using python, etc. However, I've tried to follow every tutorial online to create an associated executable script. I.e., a command that I can execute from the shell that contains some functionality from the package I made. However, nothing has worked.

My setup.py code:

from setuptools import setup

setup(name='my_package',
      version='1.0.0',
      description='heeheehoohoo',
      author='Me',
      author_email='me@me',
      url='me.com',
      packages=['my_package'],
      entry_points={
          'console_scripts': ['mypkg=my_package:run']},
      install_requires=['cairosvg',
                        'selenium',
                        'PyPDF2',
      ],
      include_package_data=True,
      zip_safe=False
     )

And under my_package/__init__.py I have:

from . mine import main

def run():
    import argparse

    parser = argparse.ArgumentParser(prog = 'eeeeeee', description = 'eeeeee')

    parser.add_argument('eeeeee', help = 'eeeeeee')

    args = parser.parse_args()

    print(f'eeeee ...')
    main(args.eeeeeee)
    print(f'Success!')

Everything gets installed, yet for some reason when I try to execute $ mypkg, I get zsh: command not found: mypkg. From python, I can import the function and directly try to execute run(). And strangest of all, each tutorial I have seen that has done anything like this can execute the commands without a problem once they'd executed python setup.py install.

Thank you!


Setting pip to the respective version of python and using pip install . instead of python setup.py install did the trick. However, it's still strange that python setup.py install does not work...

Max L
  • 49
  • 9
  • This seems all correct to me. Maybe it is an issue with the `PATH` environment variable. Have you checked that it contains the directory where `mypkg` has been installed? Do you know where `mypkg` has been installed? – sinoroc Jan 12 '23 at 09:20
  • 1
    Does this answer your question? [Pip suddenly using wrong version of Python](https://stackoverflow.com/questions/36311336/pip-suddenly-using-wrong-version-of-python) – David Buck Jan 13 '23 at 05:03
  • Yes and no. I thought about @sinoroc 's comment and I tried to identify the respective paths. At that point, I decided to look into why my pip was also displaced. After searching for a bit, the answer in that page resolved the issue for me. However, it seems to only work with `pip install .`, and not 'python setup.py install'. So as far as I am concerned, I'm happy it works. Nevertheless, I'm still confused why 'python setup.py install' does not work. – Max L Jan 13 '23 at 05:11
  • @MaxL Could you please not add [the answer](https://stackoverflow.com/revisions/75090598/4) in the question? Please add those details in the answer instead that you have written below. – medium-dimensional Jan 13 '23 at 05:22

0 Answers0