Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Batch File to add to PATH Environment Variable (Windows 10)

Tags:

batch-file

I am trying to create a batch file to automatically add my python folder to the Environment Path. Below is my environment variables before the file was run.enter image description here

And this is the file I ran (Note the bat file is in the same directory as the python folder):

@echo OFF
setx path "%path%;%cd%\Python36"

This file added python to path (see the red underline) but also added a bunch of other folders to the path (blue circle). I am confused as to why this occurred. Any help would be greatly appreciated! enter image description here

like image 265
J.C Avatar asked Dec 12 '25 17:12

J.C


1 Answers

There is a couple different ways.

First - Search for python, then set the $PATH.

FOR /f %%p in ('where python') do SET PYTHONPATH=%%p
ECHO %PYTHONPATH%

Second - If you know where Python is installed, you can use setx to permanently set PATH or PYTHONPATH.

setx path "%path%;C:\Users\Admin\AppData\Local\Programs\Python\PythonVersion;"

I found an extremely intensive PowerShell script for installing Python. Just needs the links updated.

like image 100
Noah M. Avatar answered Dec 16 '25 14:12

Noah M.