Python Forum
Python "Automate the Boring Stuff" wants me to change Windows environment variables?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python "Automate the Boring Stuff" wants me to change Windows environment variables?
#1
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.
Reply
#2
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)
Reply
#3
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!
Reply
#4
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 it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#5
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.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#6
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
Reply
#7
(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
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#8
(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.
Reply
#9
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Installing python packages in a virtual environment Led_Zeppelin 1 712 Aug-15-2023, 08:18 PM
Last Post: deanhystad
  Understanding venv; How do I ensure my python script uses the environment every time? Calab 1 2,158 May-10-2023, 02:13 PM
Last Post: Calab
  Python development environment standenman 3 1,523 May-04-2023, 07:24 PM
Last Post: snippsat
  Python Scripting Environment jpotter0 1 1,619 Nov-19-2022, 03:07 PM
Last Post: snippsat
  How do I link the virtual environment of that project to the 3.9.2 version of python? Bryant11 1 1,332 Feb-26-2022, 11:15 AM
Last Post: Larz60+
  Setting permanent user variables in Windows coder420 2 1,381 Jan-04-2022, 10:42 AM
Last Post: Larz60+
  VS Code debugger using wrong Python environment topfox 0 2,428 Jun-09-2021, 10:01 AM
Last Post: topfox
  Run the code for some stuff it does not return me why Anldra12 3 2,797 Apr-19-2021, 02:01 PM
Last Post: Anldra12
  Virtual environment and upgrading python 3.5 to 3.9 NeilUK 4 11,972 Jan-24-2021, 01:02 PM
Last Post: snippsat
  "Automate the Boring Stuff with Python" creating a path works but only for CMD promt Milos 2 2,821 Nov-28-2020, 01:08 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020