Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pipx fails to run script with dependencies. #1227

Closed
planetmarshall opened this issue Jan 22, 2024 · 4 comments · Fixed by #1240
Closed

pipx fails to run script with dependencies. #1227

planetmarshall opened this issue Jan 22, 2024 · 4 comments · Fixed by #1240
Labels
docs good first issue Good for newcomers help wanted Extra attention is needed

Comments

@planetmarshall
Copy link

planetmarshall commented Jan 22, 2024

Describe the bug

According to the docs, the following script should run:

# test.py

# Requirements:
# requests
#
# The list of requirements is terminated by a blank line or an empty comment line.

import sys
import requests
project = sys.argv[1]
pipx_data = requests.get(f"https://pypi.org/pypi/{project}/json").json()
print(pipx_data["info"]["version"])

How to reproduce

brew install pipx
pipx ensurepath
pipx run test.py

Expected behavior

ths script should install the requirements and output the pipx version (eg. 1.4.3)

Actual Behaviour

output is

File "/Users/andrew/projects/pipx-test/test.py", line 9, in <module>
    import requests
ModuleNotFoundError: No module named 'requests'

Notes

  • pipx version 1.4.3
  • Macos Ventura 13.6.2 (arm64)
  • Python 3.12 (homebrew)
@chrysle
Copy link
Contributor

chrysle commented Jan 22, 2024

This runs normally in my Debian installation. Could you post the output of pipx run with --verbose?

@chrysle chrysle added the macOS label Jan 22, 2024
@planetmarshall
Copy link
Author

planetmarshall commented Jan 22, 2024

This runs normally in my Debian installation. Could you post the output of pipx run with --verbose?

$ pipx run --verbose test.py 
pipx >(setup:860): pipx version is 1.4.3
pipx >(setup:861): Default python interpreter is '/opt/homebrew/opt/python@3.12/libexec/bin/python'
pipx >(exec_app:370): exec_app: /opt/homebrew/opt/python@3.12/libexec/bin/python test.py
Traceback (most recent call last):
  File "/Users/andrew/projects/pipx-test/test.py", line 9, in <module>
    import requests
ModuleNotFoundError: No module named 'requests'

@planetmarshall
Copy link
Author

planetmarshall commented Jan 22, 2024

In the tests the syntax for this feature is different - it's

# test.py

# /// script
# dependencies = ["requests"]
# ///

import sys
import requests
project = sys.argv[1]
pipx_data = requests.get(f"https://pypi.org/pypi/{project}/json").json()
print(pipx_data["info"]["version"])

Which works - maybe it's the docs that need updating?

@chrysle
Copy link
Contributor

chrysle commented Jan 22, 2024

Which works - maybe it's the docs that need updating?

Right, I forgot – When implementing support for inline script metadata, we also removed support for the old requirement specification. A pull request to update the section would be welcome.

@chrysle chrysle added help wanted Extra attention is needed good first issue Good for newcomers docs labels Jan 22, 2024
@dukecat0 dukecat0 removed the macOS label Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants