Description of problem: I have a setup.py that includes a shell script # Register as a shell script entry_points={ 'console_scripts': ['my_command = my_module.my_command:main'] }, Using Python 2 we get the correct behavior: After installing this with setup.py or via pip (as root), the script is added to /usr/bin Using Python 3 this doesn't happen. And typing `my_command` results in the error bash: /usr/bin/my_command: No such file or directory
Could you please give me an exact reproducer witch all the commands? Note that sudo pip installing is dangerous and you should not do it.
Created attachment 1459958 [details] Minimal example to reproduce Setup.py # SetupTools for example script from setuptools import setup, find_packages setup( name='example', packages=find_packages(include=('example')), entry_points={ 'console_scripts': ['example = example.__main__:main'] }, ) example/__init__.py # Example module example/__main__.py def main(): print('Hello world') if __name__ == '__main__': main()
What exact command do I need to run?
Created attachment 1459968 [details] Minimal example to reproduce. With bugfix Minimal example to reproduce Setup.py # SetupTools for example script from setuptools import setup, find_packages setup( version='1.0.0', name='example', packages=find_packages(include=('example')), entry_points={ 'console_scripts': ['example = example.__main__:main'] }, ) example/__init__.py # Example module example/__main__.py def main(): print('Hello world') if __name__ == '__main__': main() To test: Python 2 (works): $ sudo pip install $ example Hello world Python 3 $ sudo pip3 install $ example -bash: /usr/bin/example: No such file or directory
Ends up in /usr/local/bin/example which is in sync with https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard https://unix.stackexchange.com/a/4187/196399
Don't see it there on my system!
Ok, here is a complete reproducer on Fedora 28: <mock-chroot> sh-4.4# rpm -q python3 python3-3.6.5-1.fc28.x86_64 <mock-chroot> sh-4.4# rpm -q python3-setuptools python3-setuptools-39.2.0-1.fc28.noarch <mock-chroot> sh-4.4# mkdir reproducer <mock-chroot> sh-4.4# cd reproducer/ <mock-chroot> sh-4.4# cat > setup.py # SetupTools for example script from setuptools import setup, find_packages setup( version='1.0.0', name='example', packages=find_packages(include=('example')), entry_points={ 'console_scripts': ['example = example.__main__:main'] }, ) <mock-chroot> sh-4.4# mkdir example <mock-chroot> sh-4.4# touch example/__init__.py <mock-chroot> sh-4.4# cat > example/__main__.py def main(): print('Hello world') if __name__ == '__main__': main() <mock-chroot> sh-4.4# whoami root <mock-chroot> sh-4.4# pip3 install . WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead. The directory '/builddir/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. The directory '/builddir/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. Processing /reproducer Installing collected packages: example Running setup.py install for example ... done Successfully installed example-1.0.0 <mock-chroot> sh-4.4# cat /usr/local/bin/example #!/usr/bin/python3 # EASY-INSTALL-ENTRY-SCRIPT: 'example==1.0.0','console_scripts','example' __requires__ = 'example==1.0.0' import re import sys from pkg_resources import load_entry_point if __name__ == '__main__': sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) sys.exit( load_entry_point('example==1.0.0', 'console_scripts', 'example')() )
python2 -m pip installs the program in /usr/bin, whereas python3 -m pip installs the program into /usr/local/bin. But I upgraded Python 3 pip manually using "python3 -m pip install -U pip" which installed pip in /usr/local/lib/python3.6/site-packages/pip(...). Maybe it explains why python3 -m pip uses /usr/local (at least, on my case).
python3 -m pip installs the program into /usr/local/bin because of https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe
Hmmm. It works using `python3 -m pip install .` but not using `pip3 -m install .`
I'm assuming you mean `pip3 install .` without m. What is the output of: $ pip3 --version $ python3 -m pip --veriosn
[root@laptop example-script]# pip3 --version pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6) [root@laptop example-script]# python3 -m pip --version pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6) Now seeing expected behavior with pip3 as well... Repeated install/uninstall works about half the time
> works about half the time and what happens the other half? Don't tell that "it doesn't work", tall me what's wrong. I cannot reproduce your problem.
I get this message: [root@laptop example-script]# example -bash: /usr/bin/example: No such file or directory Ok, as far as I can tell the issue is this: 1. Install with Python 2.7 --> Creates /usr/bin/example 2. Uninstall Python 2.7 3. Install with Python 3.6 --> Creates /usr/local/bin/example 4. Type "example" --> Bash remembers to look in /usr/bin/ but can't find it there. So just a side effect, really?
what's your PATH?
So this is a bash behaviour and nothing we can fix: [~]$ sudo ln -s /usr/bin/echo /usr/bin/bz1602745 [~]$ bz1602745 ha ha [~]$ sudo unlink /usr/bin/bz1602745 [~]$ sudo ln -s /usr/bin/echo /usr/local/bin/bz1602745 [~]$ bz1602745 ha bash: /usr/bin/bz1602745: No such file or directory [~]$ bash [~]$ bz1602745 ha ha