Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Installing Python

Wesley Trayer
Wesley Trayer
13,812 Points

How do I "set Python to PATH" without reinstalling Python?

I am currently at Timezones in the learn python track, and I wanted to install pytz on my computer. I read that all you needed to type was "pip install pytz" in the command prompt, but it didn't work. Followed a link to this video and I realized that I hadn't "Set Python to PATH" when I installed python, so I can't access python from the command prompt simply by typing "python".

So, my question is: Is there a way to set python to PATH without reinstalling it?

If not, I'll just make sure my python scripts are saved somewhere safe and reinstall python.

Michael Hulet
Michael Hulet
47,912 Points

Are you on macOS, Windows, or a Linux-based OS?

Wesley Trayer
Wesley Trayer
13,812 Points

Sorry I took so long to reply. I'm using Windows 10.

1 Answer

Hi Wesley Trayer

  • To do this you will need administrator access.
  • The way I am going to show you, is the system-wide way.
  • My installation directory probably will differ from yours, so you will have to figure out where Python is installed on your hard drive. Usually it defaults to C:\ drive.

WARNING: In step 4: DO NOT modify or edit existing entries, if you aren't sure what they are. You are better off leaving them alone. Especially those that have to do with C:\Windows. You will cause yourself a bigger headache if you mess with these and it may cause you to have to reset/reinstall your OS to fix it.

  1. Find your Python Installation Directory
  2. Get to your Advanced System Settings
  3. Here are where your Environment Variables are stored for specific User or entire System.
  4. If you have installed Python without the set PATH selected, then you shouldnt have entries for Python or Python\Scripts. You can manually add them in but you will need to know what the exact INSTALLATION path is in my case it is. Once you know the path you can Set the environmental variables for it.

NOTE: You will have to add the both Python PATHs to the environment variables. One is the ROOT folder (or the folder that has the python.exe file in it. The other is ROOT folder including the Scripts folder. You will see mine in step 4.

Wesley Trayer
Wesley Trayer
13,812 Points

Thanks for the reply Chris.

Just one question, the environment variables, what are their Exact names (I tried "Python" and "Python\Scripts"). I set the file paths, restarted my computer and it still doesn't seem to be working. I'll keep working with it, to see if I missed something. :-)

you have to put the FULL INSTALLATION path for your Python install.

So in my example, the place I installed Python was on a different drive than default.

  • E:\Python\Python36 (this is ROOT directory of Python)
  • E:\Python\Python36\Scripts (this is my scripts folder inside that folder)

Both of those paths should be in Environmental variable as entries. But there is a good chance if you only have 1 drive, Python installs to your C:\ drive so maybe your FULL path would be

C:\Python\Python36

or something like

C:\Program Files\Python

Its entirely dependent on where you installed it to, you can use File Explorer to navigate your drive to find it. :)

Wesley Trayer
Wesley Trayer
13,812 Points

I'm sorry if I misworded my question. I meant, what is the "Variable" name?

System Properties> Environment Variables> System variables> Variable: Python, Value: C:\Users\MyUser\AppData\Local\Programs\Python\Python35-32\

System Properties> Environment Variables> System variables> Variable: Python\Scripts, Value: C:\Users\MyUser\AppData\Local\Programs\Python\Python35-32\Scripts\

Thanks!

Path is a system variable name. If you directly setting your path to Python inside that system variable listing. Then you dont have to worry about a system variable name.

If you are clicking New instead of Edit on the Path variable name. Then yes, you have to name the variable. But since it is a variable, you can name it something you want, if I were to do this, I would probably name it something like PYTHON_PATH then inside the value portion you would put the absolute path to the install folder of Python.

But then you still have to tell the Path variable to include that SYSTEM variable in its values of paths. Path variable is used heavily by your CMD/Terminal to run .exe commands like when you say ping or cd or mkdir. Windows knows how to get to these .exe commands because inside path they point to different folders to look inside for them. If that makes sense.

In summary you can do two ways

  1. directly set the absolute path, by clicking EDIT on the Path system variable
  2. define a new system variable, then EDIT Path and reference your new variable by its name.
  • Example: if you use PYTHON_PATH as the new variable name. Inside of Path variable you would add a new entry and use %PYTHON_PATH% to reference it.
Wesley Trayer
Wesley Trayer
13,812 Points

Thanks! I was mixing up the User Variables and the System Variables. Got it now!