After updating to access pip
, I installed Numpy, tabulate, and
prettytable. The install confirmation for Numpy and tabulate was
accompanied by a warning stating the package location and that the
location was not on PATH
. I did not receive this warning for
prettytable though.
Are there any issues, or foreseeable future issues, if a script is installed not on PATH
? I’ve been learning Python for a few months through university (ie I’m a noob). I’m totally ignorant about where these modules should be stored to be considered on PATH
, or what problems, if any, may arise if they remain in their current location.
exact warning in cmd.exe:
WARNING: The script tabulate.exe is installed in
'C:\Users\atomi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\
LocalCache\local-packages\Python310\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning,
use --no-warn-script-location.
Do I need to update the module’s location or add the directory to PATH? (another topic I’ll need to research)
No, you don’t need to do anything. unless you want to use the script as
a command.
Thanks in advance. While waiting, I should probably research the
differences between modules and packages, and how they relate to the
term ‘scripts’.
A module is a single .py
file. A package is a directory/folder with a
collection of files within it; it is common to break a module into a
package when it gets cumbersome.
WRT PyPI, everything there is called a package, even if it is a single
.py file. In that context, “packaging” is a the process of preparing a
module or (ahem) package for publication and distribution.
“scripts”: When you package something up, part of the metadata can say
that certain functions within the package can be presented as command
line tools. These are scripts.
For example, my cs.app.ydl
package contains:
ydl = cs.app.ydl:main
in its metadata, saying that the package installation should create an
executable script named “ydl” (or in your case on Windows “ydl.exe”)
which calls the main()
function in the package cs.app.ydl
as a
command.
The error message you have is saying that the tabulate
package
provides a tabulate.exe
command, and that the place in which is was
installed is not in your PATH
environment setting, which governs where
to look for “commands”.
Typically, there is some kind of “activate” process people use enable
use of a particular Python environment, and one of its side effects is
to place the environment’s scripts directory in PATH
so that the
scripts which got installed in that environment are available as
commands.
You can just add that directory to your PATH to achieve the same effect
because the installed script should invoke Python in a way which
utilises the environment’s Python install.
As a specific example, I’m on UNIX (a MacBook).
My usual Python environment is a virtualenv in ~/var/venv/3
- a
virtual env is an environment derived from some specific Python install,
but separate enough that package installs live in the environment.
Now, my own $PATH
(the UNIX parallel to Windows %PATH
) includes
~/var/venv/3/bin
, which is where packages install their scripts on my
system. So I have a tabulate
command:
[~]fleet2*> py3 -m pip install tabulate
Requirement already satisfied: tabulate in ./var/venv/3.10.6_1-homebrew/lib/python3.10/site-packages (0.8.10)
[~]fleet2*> which tabulate
/Users/cameron/var/venv/3/bin/tabulate
[~]fleet2*> ls -ld ~/var/venv/3/bin/tabulate
-rwxrwxr-x 1 cameron cameron 246 4 Oct 10:55 /Users/cameron/var/venv/3/bin/tabulate
Here’s the bit about your warning message:
You do not need that directory in your PATH
unless you want it.
Here is the tabulate
script on my machine; it was created by pip
when it installed the package:
[~]fleet2*> cat /Users/cameron/var/venv/3/bin/tabulate
#!/Users/cameron/var/venv/3.10.6_1-homebrew/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from tabulate import _main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(_main())
An important feature is the shebang (#!
) line at the top, which
specifies the python3
executable which will be used to run this
script.
Because of that, I could (a) not have the venv bin
folder in my
$PATH
and (b) just invoke the tabulate
script explicitly instead:
[~]fleet2*> /Users/cameron/var/venv/3/bin/tabulate --help
Usage: tabulate [options] [FILE ...]
.......
and it would still work correctly courtesy of that shebang line. So you
do not need that folder in your PATH
inless you want the convenience
of invoking tabulate
as plain command:
[~]fleet2*> tabulate --help
Usage: tabulate [options] [FILE ...]
.........
I do. You may or may not.
On Windows, the Python launcher also understands shebang lines and the
tabulate.exe
file on your Windows machine will probably be quite
similar to the one on mine but with a different shebang path.
Cheers,
Cameron Simpson cs@cskk.id.au