For Mac/Linux;

PYTHONPATH=/foo/bar/baz python somescript.py somecommand

For Windows, setup a wrapper pythonpath.bat;

@ECHO OFF
setlocal
set PYTHONPATH=%1
python %2 %3
endlocal

and call pythonpath.bat script file like;

pythonpath.bat /foo/bar/baz somescript.py somecommand
Answer from ismail on Stack Overflow
🌐
Real Python
realpython.com › add-python-to-path
How to Add Python to PATH – Real Python
July 23, 2026 - >>> PATH = "/home/realpython/apps:/bin" >>> PATH = f"/home/realpython/python:{PATH}" >>> PATH '/home/realpython/python:/home/realpython/apps:/bin' Since PATH is just a string separated by colons, prepending a value involves creating a string with the new path, a colon, then the old path. With this string, you set the new value of PATH. To refresh your current command-line session, you can run the following command, replacing .profile with whichever login script you’ve chosen:
🌐
Net Informations
net-informations.com › python › intro › path.htm
How to set python path
csh shell: type setenv PATH "$PATH:/usr/local/bin/python" and press Enter. bash shell (Linux): type export ATH="$PATH:/usr/local/bin/python" and press Enter. sh or ksh shell: type PATH="$PATH:/usr/local/bin/python" and press Enter. /usr/local/bin/python is the default path of the Python directory.
🌐
GitHub
bic-berkeley.github.io › psych-214-fall-2016 › using_pythonpath.html
Using PYTHONPATH — Functional MRI methods
$ # Set PYTHONPATH to path to the working directory + /code $ # This is for the "bash" shell on Unix / git bash on Windows $ export PYTHONPATH="$PWD/code" $ # Now the script can find "a_module" $ python3 scripts/a_script.py Running useful function · You probably don’t want to have to set PYTHONPATH every time you start up a terminal and run a Python script.
🌐
YouTube
youtube.com › dylan codes
Python PATH Variable | How to run Python from command line EASY - YouTube
In this video, I will show you how to setup a Python PATH environment variable on Windows 10. After this, you will be able to run scripts from the command li...
Published: June 16, 2020
Views: 1K
🌐
Redreamality
redreamality.com › blog › pythonpathvs-code
How to Set PYTHONPATH on Windows, Linux, macOS and VS Code
August 21, 2025 - Use python3 instead of python if that is the command for your intended interpreter. PYTHONPATH is an environment variable that allows users to add extra directories to the list of paths that the Python interpreter searches for modules and packages. This is particularly useful during development when you need to import custom modules that are not located in the standard library path or in the installed package directories. This article will detail various methods for setting PYTHONPATH on Windows, macOS, and Linux systems.
🌐
Python
docs.python.org › 3 › using › cmdline.html
1. Command line and environment — Python 3.15.1 documentation
To specify different values for these, set PYTHONHOME to prefix:exec_prefix. ... Augment the default search path for module files. The format is the same as the shell’s PATH: one or more directory pathnames separated by os.pathsep (e.g. colons on Unix or semicolons on Windows). Non-existent directories are silently ignored. In addition to normal directories, individual PYTHONPATH entries may refer to zipfiles containing pure Python modules (in either source or compiled form).
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › How-to-set-python-environment-variable-PYTHONPATH-on-Windows
How to set Python environment variable PYTHONPATH on Linux?
May 2, 2023 - The PYTHONPATH environment variable tells Python where to look for modules and packages beyond the standard library. Setting it correctly on Linux ensures your custom modules can be imported from any location. Open a terminal and use the export command to set PYTHONPATH ?
🌐
Delft Stack
delftstack.com › home › howto › python › change pythonpath
How to Change Python Path | Delft Stack
March 4, 2025 - This method is particularly useful when you want to include additional directories without modifying your Python scripts. Here’s how you can do it. First, you need to set the PYTHONPATH variable in your terminal or command prompt.
🌐
Uchicago
geosci.uchicago.edu › ~rtp1 › PrinciplesPlanetaryClimate › Python › ShellsNStuff.html
About Shells, Paths and Environment Variables
Hint to the instructor: Since it is recommended that most users install the Enthought Canopy distribution, you should simply make sure all Mac OSX users are using the bash shell, which is currently the default for Macs The setup.py utility in Courseware handles the job of editing the .bash_profile file to set PYTHONPATH . If you are setting up the courseware on a server, then you can just have the sysadmin set the shell for each student account, and copy an appropriate shell configuration file into each student home directory. Then the student won't need to know any of this stuff. In many Linux Python distributions you would also set the PATH environment variable so that the python command executes the version of Python you want to be using, since there may be many versions on the server.
🌐
sqlpey
sqlpey.com › python › solved-how-to-set-pythonpath-for-command-line-python-scripts
Solved: How to Set PYTHONPATH for Command Line Python Scripts
November 23, 2024 - A: Yes, you can append multiple directories by separating them with a colon (on Mac/Linux) or a semicolon (on Windows). For example, PYTHONPATH=/path1:/path2 python somescript.py (Mac/Linux) or set PYTHONPATH=path1;path2 (Windows).
🌐
Javatpoint
javatpoint.com › how-to-set-python-path
Setting Path in Python - Javatpoint
Setting Path in Python - Setting paths in Python programs is essential for gaining access to files, modules, and directories. Paths can be relative, referring to destinations relative to the current working directory, or absolute, describing the entire directory from the root.
🌐
Codemia
codemia.io › home › knowledge hub › in python script, how do i set pythonpath?
In Python script, how do I set PYTHONPATH? | Codemia
September 24, 2025 - 1import os 2import subprocess 3from ... If the goal is to run a script from the command line with one additional import directory, set PYTHONPATH in the shell before starting Python....
🌐
Great Learning
mygreatlearning.com › blog › it/software development › how to add python to path?
How To Add Python To Path?
November 15, 2024 - Every Operating System has a list of directories containing the executable files for the commands and one executable file for each command. The name of the command itself saves each executable file. This list of directories is stored in a variable called Path. Here's a step-by-step guide on how to add Python to the system path:
Top answer
1 of 1
1

py.exe is the Python Launcher for Windows and is a separate program from any given python.exe. However, its intended purpose is to allow multiple versions of Python to be ran with minimal fuss. So, for instance, if you hypothetically needed to run Python 2.7 or Python 3.6, you could just use something like e.g. py -2.7 or py -3.6 (assuming both were versions which were installed and recognized on your system).

But for some of my programs I need to use python in order to be able to run my code.

If you really wish to use a single version of Python from the command line, simply add the folder where your prefered python.exe resides to your PATH/Path variable(s).

On Windows 7:

  • Go to Control Panel\System and Security\System.

  • Click the Advanced system settings link.

  • Select the Advanced tab from the System Properties dialog box and click the Environment Variables... button.

  • Edit your PATH (User) and/or Path (System) variables to include e.g. C:\path\to\your\preferred\python.exe (remember to put a ; at the end of the last listed path before putting the path to your python.exe).

  • Click OK when finished.

In Windows 10, you can:

  • Search for the Control Panel from the Start Menu.

    Or you can:

  • Search for env from the Start Menu and click the link to edit your environment variables.

  • You will still need to click the Environment Variables... button in either case under the Advanced tab from the System Properties dialog box.

  • Click Edit and add your C:\path\to\your\preferred\python.exe path to the appropriate PATH (User) and/or Path (System) variable list.

  • Click OK when finished.

python should now be available from the command line. If you are still having trouble running it, you may need to log out and then log back in (rebooting is typically unnecessary).


"Python" As A Batch File

While a bit of a hack, you can also "alias" py.exe as python with a batch file.

Create a new .txt file and and put e.g.:

C:\path\to\your\py.exe %*

Save it and rename it to python.bat.

Then place this batch file in your PATH\Path variable(s), as above (ex. as C:\path\to\your\python.bat).

In this case, you're still using py.exe in the background but using python (a.k.a. python.bat) to call it. The %* notation allows any variables (e.g. script names, options, etc.) to be passed along automatically to py.exe.

To be clear, you can simply use python from the command line with this method. You do not need to use python.bat.


As a final, final note, while not recommended, you could also probably simply change the name of py.exe to python.exe if you really wanted to.


🌐
Python
docs.python.org › 3 › using › windows.html
4. Using Python on Windows — Python 3.15.1 documentation
In general, configuration files have the ability to configure everything, including the location of other configuration files, while registry settings are administrator-only and will override configuration files. Command-line options override all other settings, but not every option is available.