Python Forum

Full Version: Python "Automate the Boring Stuff" wants me to change Windows environment variables?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So, I'm working through "Automate the Boring Stuff" for Python, and I to continue, it wants me to go to my Windows "Edit environment variables for your account" so that I can apparently run finished programs. However, I am in an office environment, and apparently they don't want me changing Windows system variable files. I completely think this is reasonable on my employer's part - and frankly I'm stumped as to why the book assumes that everyone will be able (and have permissions) to do this.

Basically, I need a work-around for continuing with Python that does not require me changing files inside Windows. Any help with this? I don't care if I have to put long strings into the command line. Can I get around this very odd "necessity" within this book? Or am I just out of luck and need to forget about Python?
Thanks for any help.
Modifying the environment variables is not necessary, it's only done for convenience.
I'm assuming the book wants you to modify the path variable. If so, simply use the full path whenever you need to run a program (such as python or pip)
You are exactly right - the path variable.
I'm so glad to hear that I can continue without changing this.
Thanks so much for the fast reply!
There are two types of Environmental Variables- User and System.  Will they allow you to change the "User" level?

Basically, it is just a "hint" to the Windows OS on where to find "python.exe", and a few more Python related modules. Thus the suggestion that you add "C:\main_python_location \" and "C:\main_python_location \ Scripts" to the variables. Without it, you will manually have to include the path when invoking a file. Not a game changer, but does require a little extra typing.  Say your Python installation is located in "C\Python35\", with the variables, you simply type "python" into the command terminal, no matter where your are in the directory tree, and you will start the interactive shell. Without the variables. you would have to type "c:\python35\python" or change directory to "C:\Python35" then type "python". The environmental variables are Windows equivalent of the *nix PATH.
If you change the PATH variable in the command prompt I think it's changed until system reboot. Let one who use Windows tell if I am wrong. Even if it's permanent you just add something to the PATH, so all the rest will work as usual.
You can edit your environment only for the time being inside a command prompt, so that all edits will be undone when you close the box. This should work on your non-personal computer as well.

For example, create a new text file called "python_path.bat" and put these contents inside:

set "path=%path%;C:\main_python_location\;C:\main_python_location\scripts" 
cd "c:\my_python_files\"
cmd
You can now start the file and work with the command prompt and enlarged path variable
(Dec-13-2016, 09:43 AM)Kebap Wrote: [ -> ]You can edit your environment only for the time being inside a command prompt, so that all edits will be undone when you close the box. This should work on your non-personal computer as well.

For example, create a new text file called "python_path.bat" and put these contents inside:

set "path=%path%;C:\main_python_location\;C:\main_python_location\scripts" 
cd "c:\my_python_files\"
cmd
You can now start the file and work with the command prompt and enlarged path variable

You should be able to run this with Windows Task Scheduler for every time you login
(Dec-13-2016, 02:01 PM)sparkz_alot Wrote: [ -> ]You should be able to run this with Windows Task Scheduler for every time you login

You see the third line will open a command box. In there, you can now type stuff like python my_script.py and have it work instantly. No need to schedule the command box to open after every login. Just put the .bat file on your taskbar or desktop for easy access and be done with it.
This is good stuff.
Thank you all for this information. This will save me lots of time (and headaches with my IT dept.)  Big Grin