Martin
Martin

Reputation: 1628

How to use an installed pip3 package from the command line?

I made a test package and uploaded it to pypi here: https://pypi.org/project/martin-test-package-11122/0.0.1/

The code of my package's __init__.py file is this:

import os
import sys

print("inside martin's test pip package")

print("the script has the arg %s" % (sys.argv[1]))

When I run the file locally with python3 __init__.py testArgument it just prints the argument output as expected.

I installed my package with pip3 install martin-test-package-11122==0.0.1 and verified it's installed by running pip3 freeze.

How can I run my installed package from the command line? I'm trying to call my installed package with a command like python3 -m pip3 martin-test-package-11122 commandLineArg to get the output from my __init__.py file like when ran it locally. But this -m command just causes the error /usr/bin/python3: No module named pip3

I've been googling to try and find this and the closest I can find is this stackoverflow question, which says to run python3 and import pip3 but even trying that didn't work.

Upvotes: 2

Views: 7235

Answers (1)

ForceBru
ForceBru

Reputation: 44830

The -m option does exactly what you need. pip3 by itself only installs modules, it doesn't run them (Python does). So, there's no such thing as a "pip3 package" because pip3 is just an installer, and you could as well copy the files to the appropriate folders manually, but pip3 automates this.

Since the name of the folder with the package is example_pkg, you should just execute:

python3 -m example_pkg commandLineArg

Upvotes: 8

Related Questions