Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
197 views
in Technique[技术] by (71.8m points)

windows - Python and the PATH

I have two questions about Python as it relates to PATH. First, I wanted to show you how my computer is set up. Right now I have python stored directly on my C drive like so: enter image description here

The folder "Python" is Python 3.8.3. Now, here are the folders in my PATH environment variable: enter image description here

My first question is why is that when I type "python" on my terminal (at any path), it launches the python.exe? As of right now, pip install commands and the python command works no matter what path I navigate. I thought that in order for this to happen, you would have to add the folder to where the python.exe was stored to your PATH variable (and the same goes for pip script). To my understanding, python is no where to be found in my environment variable set-up.

My second question is how would I make it to where Python 3.9.1 launches when I type "python" in the command prompt instead of the older version? Likewise, I would like to be able to use this newer version of pip when I type "pip install blabla."


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

My first question is why is that when I type "python" on my terminal (at any path), it launches the python.exe? As of right now, pip install commands and the python command works no matter what path I navigate. I thought that in order for this to happen, you would have to add the folder to where the python.exe was stored to your PATH variable (and the same goes for pip script). To my understanding, python is no where to be found in my environment variable set-up.

To answer why it works currently, it appears your screenshot is showing your system variables, but it is possible that your Path set in your user variables on your system point to your C:Python directory. Check your User variables to make sure it isn't set there.

My second question is how would I make it to where Python 3.9.1 launches when I type "python" in the command prompt instead of the older version? Likewise, I would like to be able to use this newer version of pip when I type "pip install blabla."

I would direct you to the python configuration docs. It talks about how to setup your environment to point to the new installation of python. In short, you'd modify your path variable to point to the directory where the new version of python.exe is saved. You also want to add the Scripts directory that can be found in that directory to your path. That will allow you to use the expected version of pip from the command prompt.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...