pypa / pipx

Install and Run Python Applications in Isolated Environments
https://pipx.pypa.io
MIT License
10.66k stars 418 forks source link

module not callable if package is installed from source control #1526

Open 111100001 opened 3 months ago

111100001 commented 3 months ago

Describe the bug when i install a fork i made using this command: pipx install git+https://github.com/111100001/tubeup.git

it installs it fine, but when i try to use it, is says this:

tubeup

Traceback (most recent call last):
  File "/home/lucky/.local/bin/tubeup", line 8, in <module>
    sys.exit(__main__())
TypeError: 'module' object is not callable

then i found out the file in .local/bin/tubeup is different than the one that is made when the main tubeup is installed normally.

the .local/bin file that pipx made using pipx install git+https://github.com/111100001/tubeup.git :

#!/home/lucky/.local/pipx/venvs/tubeup/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from tubeup import __main__
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(__main__())

the .local/bin file that is made when i install the main tubeup branch using pipx install tubeup :

#!/home/lucky/.local/pipx/venvs/tubeup/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from tubeup.__main__ import main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

i copied the main tubeup bin file and pasted it in the fork version that i installed and it worked.

How to reproduce

  1. install my fork using pipx install git+https://github.com/111100001/tubeup.git
  2. type tubeup in the terminal
  3. the error will show up
  4. to fix: change the .local/bin/tubeup file to this file (this is the file that is made with pipx install tubeup :
    #!/home/lucky/.local/pipx/venvs/tubeup/bin/python
    # -*- coding: utf-8 -*-
    import re
    import sys
    from tubeup.__main__ import main
    if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

Expected behavior tuebup wokrs normally when installed from source control

Gitznik commented 2 months ago

Can you please link your fork and the original repo, so I can have a quick look if I can see any issues there?

111100001 commented 2 months ago

Can you please link your fork and the original repo, so I can have a quick look if I can see any issues there?

both repos are in the commands above, but here they are:

my fork: https://github.com/111100001/tubeup

the original repo: https://github.com/bibanon/tubeup

Gitznik commented 2 months ago

It seems the scripts definition in the pyproject.toml is the culprit here. This error happens as well, wenn you install tubeup from the main repo.

I fixed it by changing the scripts from:

[project.scripts]
tubeup = "tubeup:__main__"

to

[project.scripts]
tubeup = "tubeup.__main__:main"

For reference, see my fork and try installing from there.

Looks like setup.py somehow makes the scripts path work when building the package, but installing directly from source, the first version does not work. Mind that this is not pipx functionality (we have nothing to do with the creation of the .../bin/python files). This is handled by pip itself.