You can use always:

'C:/mydir'

This works both in Linux and Windows.

Another possibility is:

'C:\\mydir'

If you have problems with some names you can also try raw string literals:

r'C:\mydir'

However, the best practice is to use the os.path module functions that always joins with the correct path separator (os.path.sep) for your OS:

os.path.join(mydir, myfile)

From python 3.4 you can also use the pathlib module. This is equivalent to the above:

pathlib.Path(mydir, myfile)

or:

pathlib.Path(mydir) / myfile
Answer from joaquin on Stack Overflow
🌐
Python
docs.python.org › 3 › using › windows.html
4. Using Python on Windows — Python 3.14.3 documentation
The /usr/bin/env form of shebang line will also search the PATH environment variable for unrecognized commands. This corresponds to the behaviour of the Unix env program, which performs the same search, but prefers launching known Python commands. A warning may be displayed when searching for arbitrary executables, and this search may be disabled by the shebang_can_run_anything configuration option. Shebang lines that do not match any of patterns are treated as Windows executable paths that are absolute or relative to the directory containing the script file.
Discussions

Python and the PATH variable in Windows 10
If you type python and the store opens, Turn off the python alias in the Alias List in settings ( https://www.tenforums.com/tutorials/102096-manage-app-execution-aliases-windows-10-a.html ) More on reddit.com
🌐 r/Python
16
33
August 20, 2021
python - How to add to the PYTHONPATH in Windows, so it finds my modules/packages? - Stack Overflow
I have a directory which hosts all of my Django apps (C:\My_Projects). I want to add this directory to my PYTHONPATH so I can call the apps directly. I tried adding C:\My_Projects\; to my Windows Path variable from the Windows GUI (My Computer > Properties > Advanced System Settings > Environment ... More on stackoverflow.com
🌐 stackoverflow.com
Windows path to Python path
I wonder is there a better solution on the issue to convert windows path to python path? Yes; simply use pathlib. from pathlib import Path win_path = r"" path_universal = Path(win_path) print("Your Python Path: ", path_universal) The more you use it, the more you regret not knowing about it earlier. It's an awesome piece of kit in the standard library, probably my favourite. More on reddit.com
🌐 r/learnpython
4
2
February 2, 2022
Python Installation
Hello, I recently got python downloaded in my system. able to open all terminals, Idle windows able to access Pycharm. but really not sure where is the exact location of Python installed when i try to check from Command prompt. I wanted to add Environmental Variables. Please help. More on discuss.python.org
🌐 discuss.python.org
0
0
December 7, 2023
🌐
Real Python
realpython.com › add-python-to-path
How to Add Python to PATH – Real Python
January 30, 2023 - Once you’ve located your Python executable, open the Start menu and search for the Edit the system environment variables entry, which opens up a System Properties window. In the Advanced tab, click on the button Environment Variables. There you’ll see User and System variables, which you’ll be able to edit: In the section entitled User Variables, double-click on the entry that says Path.
🌐
Reddit
reddit.com › r/python › python and the path variable in windows 10
r/Python on Reddit: Python and the PATH variable in Windows 10
August 20, 2021 -

Do you remember checking the box in the image shown below to add your Python installation to PATH in Windows 10?

Adding Python to PATH

Well, I was curious! What if someone accidentally forgot to check that little radio button? What would be the possible recovery steps?

So I spent my evening yesterday uninstalling Python and re-installing to figure out a way to add Python to the PATH post-installation.

If you forget to add Python to the PATH variable, you won't be able to run Python in your command line.

You will get a message saying,

‘python' is not recognized as an internal or external command.

Here are the steps I used to add Python to the PATH variable in Windows 10.

  1. Copy the directory to which Python is being installed.

  2. Search for System Properties in the Search Bar.

  3. Click on the "Environment Variables" button in System Properties.

  4. Click on the "Path" variable and then click on "Edit".

  5. Now here's the deal. Paste the directory path from Step 1 at the top of the list. You can use the "Move up" button to get it to the top. Now click on "Ok".

I found out that if you paste the path at the end, it still doesn't work. Can someone tell me why?

Anyways, if the steps are not clear to anyone, here is a visual guide containing images of every step, on my blog for achieving the above objective. If you are interested, do take a look.

Find elsewhere
🌐
Python
docs.python.org › 3 › library › os.html
os — Miscellaneous operating system interfaces
February 23, 2026 - As of Python 3.3, this is equivalent to os.chdir(fd). Raises an auditing event os.chdir with argument path. Availability: Unix. ... Return a string representing the current working directory. ... Return a bytestring representing the current working directory. Changed in version 3.8: The function now uses the UTF-8 encoding on Windows, rather than the ANSI code page: see PEP 529 for the rationale.
🌐
NBShare
nbshare.io › notebook › 462254290 › How-To-Add-Python-To-Windows-10-PATH
How To Add Python To Windows 10 PATH
February 21, 2021 - You should see in the same directory a "Scripts" folder as shown in the snapshot below. For me the path is "C:\Users\aphull\AppData\Local\Programs\Python\Python39\Scripts" 2. Now add your "Scripts" folder path to the System environment Variables. 3. Open new "cmd" prompt window and type "pip --version".
🌐
Reddit
reddit.com › r/learnpython › windows path to python path
r/learnpython on Reddit: Windows path to Python path
February 2, 2022 -

I have been searching the web for a solution without a result.
I made this small script that can be used. Feel free to use it.
I wonder is there a better solution on the issue to convert windows path to python path?

"""
A path, in Windows "C:\Folder" . in Python it is "C:/Folder".
In Python the "\" character can get interpreted as the ESCAPE character.
When an 'r' or 'R' prefix is present, a character following a backslash is
included in the string without change, and all backslashes are left in the string.
"""
def main():
# - YOUR INPUT - IMPORTANT: keep the r in front of path string here.
win_path = r"<TYPE YOUR PATH HERE>"
# Call function to convert from windows to Python path.
path_py = py_path(win_path)
print("Your Python Path: ", path_py)

def py_path(win_path):
python_path = "" # The result of this script.
# Convert to ASCII list
ascii_values_list = []
for character in win_path:
ascii_values_list.append(ord(character))
# Replace all ASCII values for "\" (=92) with value for "/" (=47).
for i in range(0, len(ascii_values_list)):
if ascii_values_list[i] == 92:
ascii_values_list[i] = 47
path_py = "" # Convert ASCII list to string
for val in ascii_values_list:
path_py = path_py + chr(val)

if path_py[-1] != "/": # Add "/" at end of path if needed.
path_py = path_py + "/"
return path_py

if __name__ == "__main__":
main() # Script goes there.

# EOF

🌐
YouTube
youtu.be › NPML38E6flQ
How to Add Python Installation to Path Environment ...
January 25, 2022 - We cannot provide a description for this page right now
🌐
Python.org
discuss.python.org › python help
Python Installation - Python Help - Discussions on Python.org
December 7, 2023 - Hello, I recently got python downloaded in my system. able to open all terminals, Idle windows able to access Pycharm. but really not sure where is the exact location of Python installed when i try to check from Command…
🌐
Python
docs.python.org › 3 › library › os.path.html
os.path — Common pathname manipulations
On Windows, USERPROFILE will be used if set, otherwise a combination of HOMEPATH and HOMEDRIVE will be used. An initial ~user is handled by checking that the last directory component of the current user’s home directory matches USERNAME, and replacing it if so. If the expansion fails or if the path does not begin with a tilde, the path is returned unchanged.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-add-python-to-windows-path
How to add Python to Windows PATH? - GeeksforGeeks
July 12, 2025 - If no results appear then Python is not installed on your machine, download it before proceeding further. Click on open file location and you will be in a location where Python is installed, Copy the location path from the top by clicking over it.
🌐
UltaHost
ultahost.com › home › docs › other › general guides
How to add Python Path to Windows 10 PATH | Ultahost Knowledge Base
May 16, 2024 - A new window will open. Now we will enter the following data in the open fields. ... C:\Users\*username*\AppData\Local\Programs\Python\Python38 (change the variable value to match your actual installation path).
🌐
Geek University
geek-university.com › home › python › add python to the windows path
Add Python to the Windows Path | Python#
June 25, 2022 - In the System variable window, find the Path variable and click Edit: Position your cursor at the end of the Variable value line and add the path to the python.exe file, preceeded with the semicolon character (;).
🌐
Python
docs.python.org › 3 › library › pathlib.html
pathlib — Object-oriented filesystem paths
February 23, 2026 - Under Windows, the unicode form is the canonical representation of filesystem paths. To access the individual “parts” (components) of a path, use the following property: ... >>> p = PurePath('/usr/bin/python3') >>> p.parts ('/', 'usr', 'bin', ...
🌐
Sentry
sentry.io › sentry answers › python › handle windows paths in python
Handle Windows paths in Python | Sentry
September 15, 2024 - For example, the path sam/Documents/data/1.5/data.csv could be resolved to /home/sam/Documents/data/1.5/data.csv on a Linux system or C:\Users\sam\Documents\data\1.5\data.csv on a Windows system, as long as the script is executed in /home/ or C:\Users. In a standard Python string, the escape sequence \\ translates to \. Therefore, a third way we can resolve this problem is by replacing all \s with \\s in the path.
🌐
Linux Hint
linuxhint.com › add-python-windows-path
How to Add Python to Windows Path? – Linux Hint
Step 2: Copy Path After finding ... the “Environment Variables” button: Step 4: Add Python to Windows Choose the “Path” variable and hit the “Edit” button to add Python to the Windows path:...
🌐
b.telligent
btelligent.com › en › blog › best-practice-working-with-paths-in-python-part-1-2
Best Practice: Working With Paths In Python (Part 1)
Recently while working on a project, ... in Python. Of course, you can. Moreover, since this isn’t at all complicated, I’d like to take this case to illustrate key best practices recommended for working with paths on drives. Assuming that you wish to get a listing of a particular path accurately, we start by selecting a user directory on a Windows 10 system, ...